module Speedo module Generators class InstallGenerator < Rails::Generators::Base source_root File.expand_path("../../../../", __FILE__) desc "Installs Speedo files to get you going fast." # app/views/layouts/application.html.haml def layout if yes? "Do you want to replace the application layout? [yN]" template 'app/views/layouts/speedo/application.html.haml', 'app/views/layouts/application.html.haml' remove_file 'app/views/layouts/application.html.erb' end end # app/assets/stylesheets/speedo.css.scss def copy_stylesheet template 'app/assets/stylesheets/speedo.css.scss', 'app/assets/stylesheets/speedo.css.scss' end def alter_application_css if_file 'app/assets/stylesheets/application.css' do |path| unless File.read(path).match /require speedo/ inject_into_file path, after: '*= require_self' do "\n *= require speedo" end end end end # app/assets/javascripts/swim.js.coffee def javascript template 'app/assets/javascripts/swim.js.coffee', 'app/assets/javascripts/swim.js.coffee' end def alter_application_js if_file 'app/assets/javascripts/application.js' do |path| unless File.read(path).match /require speedo/ inject_into_file path, before: '//= require_tree .' do "//= require speedo\n" end end end end # config/locales/speedo.en.yml def locales template 'config/locales/speedo.en.yml', 'config/locales/speedo.en.yml' end def routes route 'mount Speedo::Engine => "/speedo"' end private def if_file path if File.exist? path yield path else say "#{path} not found. Please manually require speedo." end end end end end