Class: Squareone::Generator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/squareone/generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject

Declare source files directory



21
22
23
# File 'lib/squareone/generator.rb', line 21

def self.source_root
  File.expand_path("../templates", File.dirname(__FILE__))
end

Instance Method Details

#copy_filesObject

Copy files in the root directory



48
49
50
51
52
# File 'lib/squareone/generator.rb', line 48

def copy_files
  %w{_config.dev.yml about.md feed.xml gulpfile.js index.html}.each do |file|
    copy_file file
  end
end

#copy_foldersObject

Copy files in folders



26
27
28
29
30
# File 'lib/squareone/generator.rb', line 26

def copy_folders
  %w{_includes _layouts _posts _sass assets}.each do |dir|
    directory dir
  end
end

#create_git_filesObject

Create git files



33
34
35
36
37
38
# File 'lib/squareone/generator.rb', line 33

def create_git_files
  %w{assets/images/.gitkeep assets/stylesheets/.gitkeep}.each do |file|
    create_file file
  end
  copy_file ".gitignore"
end

#generate_from_templatesObject

Generate files with template variables



41
42
43
44
45
# File 'lib/squareone/generator.rb', line 41

def generate_from_templates
  %w{package.json _config.yml}.each do |file|
    template file
  end
end

#setupObject

Setup generator

Raises:

  • (Thor::Error)


11
12
13
14
15
16
17
18
# File 'lib/squareone/generator.rb', line 11

def setup
  @project_name = name.downcase

  raise Thor::Error, set_color("ERROR: #{@project_name} already exist.", :red) if File.exist?(@project_name)

  @project_title = name.split(/[- _]/).map(&:capitalize).join(' ')
  self.destination_root = File.expand_path(@project_name)
end

#success_messageObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/squareone/generator.rb', line 54

def success_message
  message = <<-MSG
  =============================================
  Project #{@project_name} created successfully.

  1. Move into the project directory.
    $ cd #{@project_name}
  
  2. Install project dependencies.
    $ npm install

  3. Start local server with gulp watching for changes.
    $ npm start
  ===========================================
  MSG

  say message
end