module RailsConnector module Generators class InstallGenerator < Rails::Generators::Base desc "Copy Infopark Rails Connector files to your application." # Normally, you'd just call 'source_root' as a class method from here, # but we need to glob the dir ourselves. Hence our own method. def self.source_root @source_root ||= File.expand_path("templates", __dir__) end def install_configuration copy_file "initializers/rails_connector.rb", "config/initializers/rails_connector.rb" template "app/models/obj.rb.erb", "app/models/obj.rb" copy_file "local/configuration.rb", "config/local/configuration.rb" end def append_asset_manifests append_file("app/assets/javascripts/application.js", "//= require infopark_rails_connector") gsub_file("app/assets/stylesheets/application.css", "*= require_tree .", "*= require_tree .\n *= require infopark_rails_connector") end def remove_public_index_html remove_file "public/index.html" remove_file "app/assets/images/rails.png" end def patch_default_application_layout gsub_file("app/views/layouts/application.html.erb", %r{}, "<%= rails_connector_header_tags %>\n") gsub_file("app/views/layouts/application.html.erb", %r{}, "<%= rails_connector_after_content_tags %>\n") end end end end