<commit_before>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)'
      class_option :gmaps, type: :boolean, default: false,
               desc: 'Include Google Maps (requires gmaps4rails and underscore-rails)'
      class_option :leaflet, type: :boolean, default: false,
               desc: 'Include Leaflet JS (requires leaflet-rails and related gems)'
      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
      end

      def setup_head
        template "head.html.erb", "app/views/layouts/_head.html.erb"
      end

      def add_gmaps
        return unless options.gmaps?
        file = "app/assets/javascripts/application.js"
        inject_into_file file, after: /require jquery_ujs.*$/ do
          "\n//= require underscore" +
          "\n//= require gmaps/google"
        end
      end

      def add_leaflet
        return unless options.leaflet?
        file = "app/assets/javascripts/application.js"
        inject_into_file file, after: /require jquery_ujs.*$/ do
          "\n//= require leaflet" +
          "\n//= require leaflet.makimarkers"
        end
        file = "app/assets/stylesheets/application.css"
        prepend_to_file file do
          [
            "//= depend_on_asset \"layers.png\"",
            "//= depend_on_asset \"layers-2x.png\"",
            "",
            ""
          ].join("\n")
        end
        inject_into_file file, after: /require_tree \..*$/ do
          "\n *= require leaflet"
        end
      end

      def remove_turbolinks
        return if options.turbolinks?<commit_msg>added leaflet.geodesic.js when using Leaflet<commit_after>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)'
      class_option :gmaps, type: :boolean, default: false,
               desc: 'Include Google Maps (requires gmaps4rails and underscore-rails)'
      class_option :leaflet, type: :boolean, default: false,
               desc: 'Include Leaflet JS (requires leaflet-rails and related gems)'
      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
      end

      def setup_head
        template "head.html.erb", "app/views/layouts/_head.html.erb"
      end

      def add_gmaps
        return unless options.gmaps?
        file = "app/assets/javascripts/application.js"
        inject_into_file file, after: /require jquery_ujs.*$/ do
          "\n//= require underscore" +
          "\n//= require gmaps/google"
        end
      end

      def add_leaflet
        return unless options.leaflet?
        file = "app/assets/javascripts/application.js"
        inject_into_file file, after: /require jquery_ujs.*$/ do
          [
            "",
            "//= require leaflet",
            "//= require leaflet.makimarkers",
            "//= require leaflet.geodesic",
            ""
          ].join("\n")
        end
        file = "app/assets/stylesheets/application.css"
        prepend_to_file file do
          [
            "//= depend_on_asset \"layers.png\"",
            "//= depend_on_asset \"layers-2x.png\"",
            "",
            ""
          ].join("\n")
        end
        inject_into_file file, after: /require_tree \..*$/ do
          "\n *= require leaflet"
        end
      end

      def remove_turbolinks
        return if options.turbolinks?
{'fraction_non_alphanumeric': 0.11036664805509026, 'fraction_numerical': 0.000744463056020845, 'mean_word_length': 1.9238302502720348, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4151940', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1535, 'n_words': 358}