Class: Sinatra::AppGenerator

Inherits:
NameCommand show all
Defined in:
lib/sinatra/commands/app_generator_command.rb

Instance Attribute Summary

Attributes inherited from NameCommand

#args, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NameCommand

#clean_string, inherited, #initialize, #underscored

Methods inherited from Command

#app_path, #cmd, commands, inherited, #rm, #rm_r, #template_path

Constructor Details

This class inherits a constructor from Sinatra::NameCommand

Class Method Details

.commandObject



4
5
6
# File 'lib/sinatra/commands/app_generator_command.rb', line 4

def self.command
  "generate:app"
end

.helpObject



8
9
10
# File 'lib/sinatra/commands/app_generator_command.rb', line 8

def self.help
  "app_name"
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sinatra/commands/app_generator_command.rb', line 16

def call
  # mkdir self.underscored, verbose: true
  %w{apps spec/apps}.each do |dir|
    Dir[template_path("**", "*")].each do |f|
      if File.directory?(f)
        FileUtils.mkdir_p clean_string(f), verbose: true
      else
        FileUtils.mkdir_p clean_string(File.dirname(f)), verbose: true
        File.open(clean_string(f), 'w') do |file|
          file.puts clean_string(File.read(f))
        end
      end
    end
  end
  File.open(app_path("assets", "javascripts", "#{self.underscored}.js.coffee"), 'w') do |file|
    file.puts ""
  end
  File.open(app_path("assets", "stylesheets", "#{self.underscored}.css.scss"), 'w') do |file|
    file.puts ""
  end
  File.open(app_path("config.ru"), "a") do |file|
    file.puts <<-EOF
  map "/#{self.underscored}" do
run #{self.classified}
  end
    EOF
  end

end

#classifiedObject



12
13
14
# File 'lib/sinatra/commands/app_generator_command.rb', line 12

def classified
  "#{self.name.classify}App"
end