Class: Sunrise::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Sunrise::Generators::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/sunrise/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#add_routes ⇒ Object
Add devise routes.
- #autoload_paths ⇒ Object
- #copy_configurations ⇒ Object
- #copy_helpers ⇒ Object
-
#copy_images ⇒ Object
copy images.
-
#copy_javascripts ⇒ Object
copy javascripts.
-
#copy_models ⇒ Object
copy models.
- #copy_specs ⇒ Object
-
#copy_stylesheets ⇒ Object
copy stylesheets.
-
#copy_uploaders ⇒ Object
copy uploaders.
-
#copy_views ⇒ Object
copy views.
-
#create_migrations ⇒ Object
copy migration files.
- #dependent_generators ⇒ Object
- #download_rails_js ⇒ Object
- #test_framework ⇒ Object
Class Method Details
.current_time ⇒ Object
127 128 129 130 |
# File 'lib/generators/sunrise/install_generator.rb', line 127 def self.current_time @current_time ||= Time.now @current_time += 1.minute end |
.next_migration_number(dirname) ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/generators/sunrise/install_generator.rb', line 119 def self.next_migration_number(dirname) if ActiveRecord::Base. current_time.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end |
Instance Method Details
#add_routes ⇒ Object
Add devise routes
86 87 88 89 90 |
# File 'lib/generators/sunrise/install_generator.rb', line 86 def add_routes route "devise_for :users" route "resources :pages, :only => [:show]" route 'root :to => "welcome#index"' end |
#autoload_paths ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/generators/sunrise/install_generator.rb', line 92 def autoload_paths log :autoload_paths, "models/defaults" sentinel = /\.autoload_paths\s+\+=\s+\%W\(\#\{config\.root\}\/extras\)\s*$/ code = 'config.autoload_paths += %W(#{config.root}/app/models/defaults)' in_root do inject_into_file 'config/application.rb', " #{code}\n", { :after => sentinel, :verbose => false } end end |
#copy_configurations ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/sunrise/install_generator.rb', line 41 def copy_configurations copy_file('config/seeds.rb', 'db/seeds.rb') copy_file('config/sunrise.rb', 'config/initializers/sunrise.rb') template('config/application.yml', 'config/application.yml.sample') template('config/database.yml', 'config/database.yml.sample') template('config/logrotate-config', 'config/logrotate-config.sample') template('config/nginx-config-passenger', 'config/nginx-config-passenger.sample') end |
#copy_helpers ⇒ Object
51 52 53 |
# File 'lib/generators/sunrise/install_generator.rb', line 51 def copy_helpers directory('helpers', 'app/helpers') end |
#copy_images ⇒ Object
copy images
15 16 17 18 19 |
# File 'lib/generators/sunrise/install_generator.rb', line 15 def copy_images directory "images/manage", "public/images/manage" copy_file('images/alert.png', 'public/images/alert.png') copy_file('images/cross_ico.png', 'public/images/cross_ico.png') end |
#copy_javascripts ⇒ Object
copy javascripts
22 23 24 |
# File 'lib/generators/sunrise/install_generator.rb', line 22 def copy_javascripts directory "javascripts", "public/javascripts" end |
#copy_models ⇒ Object
copy models
56 57 58 |
# File 'lib/generators/sunrise/install_generator.rb', line 56 def copy_models directory "models", "app/models" end |
#copy_specs ⇒ Object
114 115 116 117 |
# File 'lib/generators/sunrise/install_generator.rb', line 114 def copy_specs directory "spec", "spec" copy_file('rspec', '.rspec') end |
#copy_stylesheets ⇒ Object
copy stylesheets
27 28 29 |
# File 'lib/generators/sunrise/install_generator.rb', line 27 def copy_stylesheets directory "stylesheets", "public/stylesheets" end |
#copy_uploaders ⇒ Object
copy uploaders
37 38 39 |
# File 'lib/generators/sunrise/install_generator.rb', line 37 def copy_uploaders directory "uploaders", "app/uploaders" end |
#copy_views ⇒ Object
copy views
32 33 34 |
# File 'lib/generators/sunrise/install_generator.rb', line 32 def copy_views directory "views", "app/views" end |
#create_migrations ⇒ Object
copy migration files
66 67 68 69 70 71 72 |
# File 'lib/generators/sunrise/install_generator.rb', line 66 def create_migrations if .migrations [:users, :roles, :structures, :pages, :assets, :headers].each do |item| migration_template "migrate/create_#{item}.rb", File.join('db/migrate', "sunrise_create_#{item}.rb") end end end |
#dependent_generators ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/generators/sunrise/install_generator.rb', line 74 def dependent_generators unless Rails.env.test? say_status("invoke dependent generators", "", :green) generate("simple_form:install") generate("sunrise:file_upload:install") generate("ckeditor:install") generate("devise:install") end end |
#download_rails_js ⇒ Object
60 61 62 63 |
# File 'lib/generators/sunrise/install_generator.rb', line 60 def download_rails_js say_status("fetching rails.js", "", :green) get "https://github.com/rails/jquery-ujs/raw/master/src/rails.js", "public/javascripts/rails.js" end |
#test_framework ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/generators/sunrise/install_generator.rb', line 103 def test_framework log :test_framework, "rspec" sentinel = /\.filter_parameters\s+\+\=\s+\[(.+)\]\s*$/ code = "config.generators do |g|\n g.test_framework :rspec\n end" in_root do inject_into_file 'config/application.rb', "\n\n #{code}", { :after => sentinel, :verbose => false } end end |