lib/playmo/recipes/home_controller_recipe.rb in playmo-0.0.18 vs lib/playmo/recipes/home_controller_recipe.rb in playmo-0.1.0

- old
+ new

@@ -1,86 +1,73 @@ -module Playmo - module Recipes - class HomeControllerRecipe < Playmo::Recipe - source_root File.expand_path('../templates/home_controller_recipe', __FILE__) +recipe :home_controller do + description 'This will add HomeController into your app that present home page' + after :layout - def setup - question "Would you want to create HomeController in this project?" => :install_home_controller - end + # Make changes in index view + def change_index_view + case retrieve(:markup) + when :erb then change_index_view_with_erb + when :haml then change_index_view_with_haml + when :slim then change_index_view_with_slim + end + end - def install_home_controller - # Generate home_controller - Event.events.listen(:after_install) do |event_data| - generate :controller, :home, :index + def change_index_view_with_erb + gsub_file 'app/views/home/index.html.erb', '<h1>Home#index</h1>' do + <<-CONTENT.gsub(/^ {8}/, '') + <%= heading_with_title("Home#index") %> - # Change generated routes - gsub_file 'config/routes.rb', 'get "home/index"' do - 'root :to => "home#index"' - end + <% content_for :sidebar do %> + <%= heading "Sidebar" %> + <p>Content for sidebar.</p> + <p>This content displayed only at home page.</p> + <% end %> + CONTENT + end + end - # Make changes in index view - change_index_view + def change_index_view_with_haml + gsub_file 'app/views/home/index.html.haml', '%h1 Home#index' do + <<-'CONTENT'.gsub(/^ {8}/, '') + = heading_with_title("Home#index") + - content_for :sidebar do + = heading "Sidebar" + %p Content for sidebar. + %p This content displayed only at home page. + CONTENT + end + end + + def change_index_view_with_slim + gsub_file 'app/views/home/index.html.slim', 'h1 Home#index' do + <<-'CONTENT'.gsub(/^ {8}/, '') + = heading_with_title("Home#index") + - content_for :sidebar do + = heading "Sidebar" + p Content for sidebar. + p This content displayed only at home page. + CONTENT + end + end - # Copy sidebar template - empty_directory "app/views/shared" - copy_file "_sidebar.html.erb", "app/views/shared/_sidebar.html.erb" + ask "Would you want to create HomeController in this project?" do + # Generate home_controller + generate :controller, :home, :index - # Remove default rails index file - remove_file 'public/index.html' - end + before_exit do + # Change generated routes + gsub_file 'config/routes.rb', 'get "home/index"' do + 'root :to => "home#index"' end - private - # Make changes in index view - def change_index_view - case retrieve(:markup) - when :erb then change_index_view_with_erb - when :haml then change_index_view_with_haml - when :slim then change_index_view_with_slim - end - end + change_index_view - def change_index_view_with_erb - gsub_file 'app/views/home/index.html.erb', '<h1>Home#index</h1>' do - <<-CONTENT.gsub(/^ {12}/, '') - <%= heading_with_title("Home#index") %> + # Copy sidebar template + empty_directory "app/views/shared" + copy_file "_sidebar.html.erb", "app/views/shared/_sidebar.html.erb" - <% content_for :sidebar do %> - <%= heading "Sidebar" %> - <p>Content for sidebar.</p> - <p>This content displayed only at home page.</p> - <% end %> - CONTENT - end - end - - def change_index_view_with_haml - gsub_file 'app/views/home/index.html.haml', '%h1 Home#index' do - <<-'CONTENT'.gsub(/^ {12}/, '') - = heading_with_title("Home#index") - - content_for :sidebar do - = heading "Sidebar" - %p Content for sidebar. - %p This content displayed only at home page. - CONTENT - end - end - - def change_index_view_with_slim - gsub_file 'app/views/home/index.html.slim', 'h1 Home#index' do - <<-'CONTENT'.gsub(/^ {12}/, '') - = heading_with_title("Home#index") - - content_for :sidebar do - = heading "Sidebar" - p Content for sidebar. - p This content displayed only at home page. - CONTENT - end - end + # Remove default rails index file + remove_file 'public/index.html' end end -end - -# Write down this recipe to our Cookbook if it's available -require File.dirname(__FILE__) + '/layout_recipe' -Playmo::Cookbook.instance.insert_after(Playmo::Recipes::LayoutRecipe, Playmo::Recipes::HomeControllerRecipe) if defined?(Playmo::Cookbook) +end \ No newline at end of file