Class: Chester::Command::Generate
- Inherits:
-
Base
- Object
- Base
- Chester::Command::Generate
show all
- Defined in:
- lib/chester/commands/generate.rb
Instance Attribute Summary
Attributes inherited from Base
#args
Instance Method Summary
collapse
Methods inherited from Base
#display, #initialize
Methods included from Helpers
#home_directory, #running_on_a_mac?, #running_on_windows?
Instance Method Details
#create_folder(folder_name) ⇒ Object
24
25
26
27
|
# File 'lib/chester/commands/generate.rb', line 24
def create_folder(folder_name)
display 'create folder ' + args.first + 's if does not exist'
FileUtils.mkdir_p args.first + 's'
end
|
#get_filename(file_type, filename, action = 'index') ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/chester/commands/generate.rb', line 29
def get_filename(file_type, filename, action = 'index')
result = "#{FileUtils.pwd}/#{file_type + 's'}/#{filename.downcase}"
if file_type == 'controller'
result += "_#{args.first}.coffee"
elsif file_type == 'view'
FileUtils.mkdir_p result
result += "/#{action}.coffee"
elsif file_type == 'helper'
result += "_#{args.first}.coffee"
else
result += ".coffee"
end
end
|
#index ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/chester/commands/generate.rb', line 5
def index
if args.length < 2
display 'Please enter [controller|model|view|helper] [name]'
elsif args.first =~ /^(controller|model|view|helper)$/
create_folder args.first + 's'
name = args[1].capitalize
action = args[2] || 'index'
input = File.read(File.dirname(__FILE__) + "/../templates/#{args.first}.coffee.erb")
File.open get_filename(args.first, name, action), 'w' do |f|
f.write Erubis::Eruby.new(input).result(:name => name, :action => action)
end
display 'modify app.coffee'
else
display "#{args.first} not valid command"
end
end
|