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 File.exist? 'app/views/layouts/application.html.haml' if yes? 'application.html.haml already exists. Do you want the template as speedo.html.haml (for manual integration)? [yN]' template 'app/views/layouts/speedo/application.html.haml', 'app/views/layouts/speedo.html.haml' end else template 'app/views/layouts/speedo/application.html.haml', 'app/views/layouts/application.html.haml' end if File.exist? 'app/views/layouts/application.html.erb' if yes? 'Do you want to remove the application.html.erb layout (otherwise delete it manually)? [yN]' remove_file 'app/views/layouts/application.html.erb' end end end # app/assets/stylesheets/speedo.css.scss def copy_stylesheet copy_file 'app/assets/stylesheets/speedo.css.scss', 'app/assets/stylesheets/speedo.css.scss' end # app/assets/stylesheets/application.css.scss def copy_application_css if File.exist? 'app/assets/stylesheets/application.css.scss' if yes? 'application.css.scss already exists. Do you want to replace it? [yN]' copy_file 'app/assets/stylesheets/application.css.scss', 'app/assets/stylesheets/application.css.scss' else say 'Make sure to @import "speedo"; in your application.css.scss, and @import other files - do NOT use *=require.' end end if File.exist? 'app/assets/stylesheets/application.css' if yes? 'Do you want to remove application.css (otherwise delete it manually)? [yN]' remove_file 'app/assets/stylesheets/application.css' end end end # app/assets/javascripts/swim.js.coffee def javascript copy_file '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 if File.exist? 'config/locales/en.yml' unless File.read('config/locales/en.yml').match /app_name/ inject_into_file 'config/locales/en.yml', after: 'en:' do "\n app_name: 'See config/locales to name this app'" end end else copy_file 'config/locales/speedo.en.yml', 'config/locales/speedo.en.yml' end 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. Add '//= require_tree .' to application.js." end end end end end