Sha256: 7a8cc1d5f18d5cd9990b2b92c694f16d86fe083cfa8d9d7978c25cd7a6dcf360
Contents?: true
Size: 1.88 KB
Versions: 9
Compression:
Stored size: 1.88 KB
Contents
module BootswatchRails module Generators class InstallGenerator < Rails::Generators::Base desc "Setup application to use bootswatch.com" class_option :bootstrap, type: :boolean, default: true, desc: 'Add bootstrap to application.js' class_option :turbolinks, type: :boolean, default: false, desc: 'Activate turbolinks (off by default)' source_root File.expand_path("../templates", __FILE__) def update_javascripts return unless options.bootstrap? file = "app/assets/javascripts/application.js" inject_into_file file, "\n//= require bootstrap", after: /require jquery_ujs$/ unless options.turbolinks? gsub_file file, /^\/\/=( require turbolinks)/, "// \\1" comment_lines "Gemfile", /gem 'turbolinks/ end end def update_application_controller file = "app/controllers/application_controller.rb" inject_into_file file, "\n\n private", after: /protect_from_forgery.*$/ lines = [ "", " def default_theme", " BootswatchRails::THEMES[BootswatchRails::DEFAULT].to_s", " end", " helper_method :default_theme", "", " def current_theme", " @current_theme = current_user.theme if current_user.present?", " @current_theme ||= default_theme", " end", " helper_method :current_theme", "" ] inject_into_file file, lines.join("\n"), before: /^end$/ end def copy_directories directory "app", force: true directory "config" directory "lib", force: true end def remove_turbolinks return if options.turbolinks? file = "app/views/layouts/_head.html.erb" gsub_file file, /, 'data-turbolinks-track' => true/, "" end end end end
Version data entries
9 entries across 9 versions & 1 rubygems