1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
# frozen_string_literal: true
module Responders
module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path("..", __FILE__)
desc "Creates an initializer with default responder configuration and copy locale file"
def create_responder_file
create_file "lib/application_responder.rb", <<-RUBY
class ApplicationResponder < ActionController::Responder
include Responders::FlashResponder
include Responders::HttpCacheResponder
# Redirects resources to the collection path (index action) instead
# of the resource path (show action) for POST/PUT/DELETE requests.
# include Responders::CollectionResponder
end
RUBY
end
def update_application
inject_into_class "config/application.rb", "Application", <<-RUBY
# Use the responders controller from the responders gem
config.app_generators.scaffold_controller :responders_controller
RUBY
end
def update_application_controller
prepend_file "app/controllers/application_controller.rb", %{require "application_responder"\n\n}
inject_into_class "app/controllers/application_controller.rb", "ApplicationController", <<-RUBY
self.responder = ApplicationResponder
respond_to :html
RUBY
end
def copy_locale
copy_file "../../responders/locales/en.yml", "config/locales/responders.en.yml"
end
end
end
end
|