Class: SinatraGenerator::Generator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



16
17
18
# File 'lib/sinatra_generator/generator.rb', line 16

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#config_ruObject



33
34
35
# File 'lib/sinatra_generator/generator.rb', line 33

def config_ru
  template "#{Generator.source_root}/templates/config.ru", "#{folder_name}/config.ru"
end

#create_rootObject



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

def create_root
  empty_directory folder_name
  #FileUtils.cd destination_root
end

#gemfileObject



29
30
31
# File 'lib/sinatra_generator/generator.rb', line 29

def gemfile
  template "#{Generator.source_root}/templates/Gemfile", "#{folder_name}/Gemfile"
end

#main_rbObject



25
26
27
# File 'lib/sinatra_generator/generator.rb', line 25

def main_rb
  template "#{Generator.source_root}/templates/main.rb", "#{folder_name}/main.rb"
end

#procfileObject



37
38
39
# File 'lib/sinatra_generator/generator.rb', line 37

def procfile
  template "#{Generator.source_root}/templates/Procfile", "#{folder_name}/Procfile" if options[:procfile]
end

#publicObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/sinatra_generator/generator.rb', line 55

def public
  if options[:assets] 
    directory "#{Generator.source_root}/templates/public", "#{folder_name}/public"

    if options[:views]
      insert_into_file "#{folder_name}/views/layout.erb", "\n  <link rel='stylesheet' href='/stylesheets/main.css'>",
        :after => '<title>Hello World</title>'
    end
  end
end

#viewsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sinatra_generator/generator.rb', line 41

def views
  if options[:views]
    inside folder_name do

      empty_directory 'views'

      inside 'views' do
        copy_file "#{Generator.source_root}/templates/layout.erb", "layout.erb"
        copy_file "#{Generator.source_root}/templates/index.erb", "index.erb"     
      end
    end
  end
end