Class: Template::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/template/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



14
15
16
# File 'lib/generators/template/install_generator.rb', line 14

def self.source_root
  @source_root ||= File.join(File.dirname(__FILE__), 'templates')
end

Instance Method Details

#add_routesObject



29
30
31
# File 'lib/generators/template/install_generator.rb', line 29

def add_routes
    route 'root :to => "welcome#index"'
end

#copy_template_filesObject

Generator Code. Remember this is just suped-up Thor so methods are executed in order



20
21
22
23
24
25
26
# File 'lib/generators/template/install_generator.rb', line 20

def copy_template_files
    copy_file 'app/controllers/welcome_controller.rb','app/controllers/welcome_controller.rb'
    template 'app/views/layouts/application.html.erb'
    template 'app/views/welcome/index.html.erb'
    template 'config/database.yml'
    template 'public/stylesheets/screen.css'
end

#generate_navigationObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/generators/template/install_generator.rb', line 33

def generate_navigation
    generate('navigation_config',"--force")
    @navigation = ''
    while !(controller_name = ask("Enter controller name: [no more controllers]")).blank? do
      c_name = controller_name.scan(/\w+/)[0] #get only first arg.
      generate('controller', c_name+' show') #TODO: push all other args onto end.
      @navigation += 'primary.item :'+controller_name.downcase+' ,\''+controller_name.capitalize+'\', '+controller_name.downcase+'_show_url'+'
      '
    end
    template 'config/navigation.rb'
end

#run_post_install_scriptsObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/generators/template/install_generator.rb', line 50

def run_post_install_scripts
  begin
    sh 'rm public/index.html' #todo other OS.
    sh 'rake db:setup'
  rescue
    puts '----- Unable to run post install scripts. You need to: -------'
    puts '|     -  Remove index file in index.html                     |'
    puts '|     -  Run rake db:setup                                   |'
    puts '|     -  Start your server: rails server                     |'
    puts '---------------------------------------------------------------'
  end
end

#setup_dbObject



46
47
48
# File 'lib/generators/template/install_generator.rb', line 46

def setup_db
    plugin('easypg', :git=>'git://github.com/rahim/easypg.git')
end