Sha256: 510759978d582eec3220231a741e1c1eb81af5131fac81d7c36499647a2d4117

Contents?: true

Size: 1.61 KB

Versions: 12

Compression:

Stored size: 1.61 KB

Contents

module BootswatchRails
  module Generators
    class InstallGenerator < Rails::Generators::Base
      desc "Setup application to use bootswatch.com"
      class_option :turbolinks, type: :boolean, default: false,
               desc: 'Activate turbolinks (off by default)'
      source_root File.expand_path("../templates", __FILE__)
      
      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
        template "head.html.erb", "app/views/layouts/_head.html.erb"
      end
      
      def remove_turbolinks
        return if options.turbolinks?
        comment_lines "Gemfile", /gem 'turbolinks/
        file = "app/assets/javascripts/application.js"
        gsub_file file, /^\/\/= require turbolinks\s/, ""
        file = "app/views/layouts/_head.html.erb"
        gsub_file file, /, 'data-turbolinks-track' => true/, ""
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
bootswatch_rails-3.2.0.26 lib/generators/bootswatch_rails/install/install_generator.rb
bootswatch_rails-3.2.0.25 lib/generators/bootswatch_rails/install/install_generator.rb
bootswatch_rails-3.2.0.24 lib/generators/bootswatch_rails/install/install_generator.rb
bootswatch_rails-3.2.0.22 lib/generators/bootswatch_rails/install/install_generator.rb
bootswatch_rails-3.2.0.21 lib/generators/bootswatch_rails/install/install_generator.rb
bootswatch_rails-3.2.0.20 lib/generators/bootswatch_rails/install/install_generator.rb
bootswatch_rails-3.2.0.19 lib/generators/bootswatch_rails/install/install_generator.rb
bootswatch_rails-3.2.0.18 lib/generators/bootswatch_rails/install/install_generator.rb
bootswatch_rails-3.2.0.17 lib/generators/bootswatch_rails/install/install_generator.rb
bootswatch_rails-3.2.0.16 lib/generators/bootswatch_rails/install/install_generator.rb
bootswatch_rails-3.2.0.15 lib/generators/bootswatch_rails/install/install_generator.rb
bootswatch_rails-3.2.0.14 lib/generators/bootswatch_rails/install/install_generator.rb