Class: PagesGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- PagesGenerator
- Defined in:
- lib/generators/pages/pages_generator.rb
Instance Method Summary collapse
- #add_routes ⇒ Object
- #blast_off ⇒ Object
- #copy_files ⇒ Object
- #create_models ⇒ Object
- #gems ⇒ Object
- #jquery_setup ⇒ Object
- #remove_files ⇒ Object
- #seed_data ⇒ Object
Instance Method Details
#add_routes ⇒ Object
34 35 36 37 38 39 |
# File 'lib/generators/pages/pages_generator.rb', line 34 def add_routes route "root :to => 'page#show#index', :page => 'index'" route "match ':page/' => 'page#show#:page', :as => :link" route "resources :pages, :module => 'admin'" route "resources :messages, :module => 'admin'" end |
#blast_off ⇒ Object
67 68 69 |
# File 'lib/generators/pages/pages_generator.rb', line 67 def blast_off run 'touch tmp/restart.txt' end |
#copy_files ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/generators/pages/pages_generator.rb', line 41 def copy_files copy_file 'admin_pages_controller.rb', 'app/controllers/admin/pages_controller.rb' copy_file 'application_controller.rb', 'app/controllers/application_controller.rb' copy_file 'dashboard_controller.rb', 'app/controllers/dashboard_controller.rb' copy_file 'page_controller.rb', 'app/controllers/page_controller.rb' copy_file 'page_helper.rb', 'app/helpers/page_helper.rb' copy_file 'index.html.haml', 'app/views/page/index.html.haml' copy_file 'page.html.haml', 'app/views/layouts/page.html.haml' copy_file 'application.html.haml', 'app/views/layouts/application.html.haml' copy_file 'style.sass', 'public/stylesheets/sass/style.sass' copy_file 'reset.sass', 'public/stylesheets/sass/reset.sass' copy_file 'admin.sass', 'public/stylesheets/sass/admin.sass' copy_file 'show.html.haml', 'app/views/page/show.html.haml' copy_file '_page.html.haml', 'app/views/page/_page.html.haml' copy_file '_header.html.haml', 'app/views/page/_header.html.haml' copy_file '_navigation.html.haml', 'app/views/page/_navigation.html.haml' copy_file '_sidebar.html.haml', 'app/views/page/_sidebar.html.haml' copy_file '_footer.html.haml', 'app/views/page/_footer.html.haml' copy_file 'edit.html.erb', 'app/views/admin/pages/edit.html.erb' copy_file 'pages_index.html.haml', 'app/views/admin/pages/index.html.haml' copy_file 'new.html.erb', 'app/views/admin/pages/new.html.erb' copy_file 'show.html.erb', 'app/views/admin/pages/show.html.erb' copy_file '_admin_nav.html.haml', 'app/views/layouts/_admin_nav.html.haml' copy_file '_form.html.erb', 'app/views/admin/pages/_form.html.erb' end |
#create_models ⇒ Object
4 5 6 7 8 9 |
# File 'lib/generators/pages/pages_generator.rb', line 4 def create_models generate :model, 'page name:string content:text page_title:string meta_keywords:text meta_description:text' rake 'db:migrate' remove_file 'app/models/page.rb' if File.exists?('app/models/page.rb') copy_file 'page.rb', 'app/models/page.rb' end |
#gems ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/generators/pages/pages_generator.rb', line 16 def gems gem 'haml', '2.2.24' gem 'jquery-rails' gsub_file "Gemfile", /#.*\n/, "\n" gsub_file "Gemfile", /\n+/, "\n" end |
#jquery_setup ⇒ Object
24 25 26 |
# File 'lib/generators/pages/pages_generator.rb', line 24 def jquery_setup generate 'jquery:install --ui' end |
#remove_files ⇒ Object
28 29 30 31 32 |
# File 'lib/generators/pages/pages_generator.rb', line 28 def remove_files remove_file 'public/index.html' if File.exists?('public/index.html') remove_file 'app/views/layouts/application.html.erb' if File.exists?('app/views/layouts/application.html.erb') remove_file 'public/images/rails.png' if File.exists?('public/images/rails.png') end |
#seed_data ⇒ Object
11 12 13 14 |
# File 'lib/generators/pages/pages_generator.rb', line 11 def seed_data append_file 'db/seeds.rb', "Page.create! :name => 'index', :content => 'i am index. i have no data.'" rake 'db:seed' end |