Class: Lab::Generators::SetupGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/lab/setup/setup_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_static_assetsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/generators/lab/setup/setup_generator.rb', line 25

def copy_static_assets
  copy_file "css/blueprint.css", "public/stylesheets/blueprint.css"
  copy_file "css/ie.css", "public/stylesheets/ie.css"
  copy_file "css/print.css", "public/stylesheets/print.css"
  copy_file "images/logo_learninglab.gif", "public/images/logo_learninglab.gif"
  copy_file "images/navbar_bkg.gif", "public/images/navbar_bkg.gif"
  copy_file "images/help_triangle.gif", "public/images/help_triangle.gif"
  copy_file "images/bullet_black.gif", "public/images/icons/bullet_black.gif"
  copy_file "images/notice.gif", "public/images/icons/notice.gif"
  copy_file "images/alert.gif", "public/images/icons/alert.gif"
  copy_file "images/error.gif", "public/images/icons/error.gif"
  copy_file "images/edit.gif", "public/images/icons/edit.gif"
  copy_file "images/new.gif", "public/images/icons/new.gif"
end

#create_configObject



48
49
50
51
52
53
# File 'lib/generators/lab/setup/setup_generator.rb', line 48

def create_config
  copy_file "sass_config.rb", "config/initializers/sass_config.rb"
  template "root_index.erb", "app/views/info/index.html.haml"
  copy_file "info_controller.rb", "app/controllers/info_controller.rb"
  route "root :to => \"info#index\""
end

#create_layoutObject



40
41
42
43
44
45
46
# File 'lib/generators/lab/setup/setup_generator.rb', line 40

def create_layout
  template "layout.erb", "app/views/layouts/application.html.haml"
  copy_file "css/_constants.sass", "app/stylesheets/_constants.sass"
  copy_file "css/_mixins.sass", "app/stylesheets/_mixins.sass"
  copy_file "css/screen.sass", "app/stylesheets/screen.sass"
  copy_file "layout_helper.rb", "app/helpers/layout_helper.rb"
end

#initial_cleaningObject



10
11
12
13
14
15
# File 'lib/generators/lab/setup/setup_generator.rb', line 10

def initial_cleaning
  remove_file "public/index.html"
  remove_file "README"
  remove_file "public/images/rails.png"
  remove_file "app/views/layouts/application.html.erb"
end

#setup_deviseObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/generators/lab/setup/setup_generator.rb', line 59

def setup_devise
  run "rails generate devise:install"
  inject_into_file "config/environments/development.rb", "config.action_mailer.default_url_options = { :host => 'localhost:3000' }", :before => "end\n"
  template "devise/devise_user.rb", "app/models/user.rb"
  migration_template "devise/devise_migration.rb", "db/migrate/devise_create_users.rb"
  route "resources :users"
  route "devise_for :users"
  template "devise/authorization_rules.rb", "config/authorization_rules.rb"
  template "devise/users_controller.rb", "app/controllers/users_controller.rb"
  copy_file "devise/views/login.haml", "app/views/devise/sessions/new.html.haml"
  copy_file "devise/views/forgot_password.haml", "app/views/devise/passwords/new.html.haml"
  copy_file "devise/views/change_password.haml", "app/views/devise/passwords/edit.html.haml"
  copy_file "devise/views/_form.html.haml", "app/views/users/_form.html.haml"
  copy_file "devise/views/edit.html.haml", "app/views/users/edit.html.haml"
  copy_file "devise/views/index.html.haml", "app/views/users/index.html.haml"
  copy_file "devise/views/new.html.haml", "app/views/users/new.html.haml"
  copy_file "devise/views/show.html.haml", "app/views/users/show.html.haml"
  inject_into_class "app/controllers/application_controller.rb", ApplicationController do
    "  def permission_denied\n" +
    "    redirect_to(root_url, :alert => \"You are not allowed to do this action.\")\n" +
    "  end\n"
  end
end

#setup_gemsObject



17
18
19
20
21
22
23
# File 'lib/generators/lab/setup/setup_generator.rb', line 17

def setup_gems
  append_file "Gemfile", "gem 'haml'\n"
  append_file "Gemfile", "gem 'devise'\n"
  append_file "Gemfile", "gem 'jquery-rails'\n"
  append_file "Gemfile", "gem 'declarative_authorization'\n"
  run "bundle install"
end

#setup_jquery_railsObject



55
56
57
# File 'lib/generators/lab/setup/setup_generator.rb', line 55

def setup_jquery_rails
  run "rails generate jquery:install --ui"
end