class Bootstrap::Generators::InstallGenerator

Public Instance Methods

add_assets() click to toggle source
# File lib/generators/bootstrap/install/install_generator.rb, line 12
def add_assets

  js_manifest = 'app/assets/javascripts/application.js'

  if File.exist?(js_manifest)
    insert_into_file js_manifest, "//= require twitter/bootstrap\n", :after => "jquery_ujs\n"
  else
    copy_file "application.js", js_manifest
  end

  css_manifest = 'app/assets/stylesheets/application.css'

  if File.exist?(css_manifest)
    # Add our own require:
    content = File.read(css_manifest)
    if content.match(/require_tree\s+\.\s*$/)
      # Good enough - that'll include our bootstrap_and_overrides.css.less
    else
      style_require_block = " *= require bootstrap_and_overrides\n"
      insert_into_file css_manifest, style_require_block, :after => "require_self\n"
    end
  else
    copy_file "application.css", "app/assets/stylesheets/application.css"
  end

end
add_bootstrap() click to toggle source
# File lib/generators/bootstrap/install/install_generator.rb, line 39
def add_bootstrap
  if use_coffeescript?
    copy_file "bootstrap.coffee", "app/assets/javascripts/bootstrap.js.coffee"
  else
    copy_file "bootstrap.js", "app/assets/javascripts/bootstrap.js"
  end
  if use_less?
    copy_file "bootstrap_and_overrides.less", "app/assets/stylesheets/bootstrap_and_overrides.css.less"
  else
    copy_file "bootstrap_and_overrides.css", "app/assets/stylesheets/bootstrap_and_overrides.css"
  end
end
add_locale() click to toggle source
# File lib/generators/bootstrap/install/install_generator.rb, line 52
def add_locale
  if File.exist?("config/locales/en.bootstrap.yml")
    localez = File.read("config/locales/en.bootstrap.yml")
    insert_into_file "config/locales/en.bootstrap.yml", localez, :after => "en\n"
  else
    copy_file "en.bootstrap.yml", "config/locales/en.bootstrap.yml"
  end
end
cleanup_legacy() click to toggle source
# File lib/generators/bootstrap/install/install_generator.rb, line 61
      def cleanup_legacy
        # Remove old requires (if any) that included twitter/bootstrap directly:
        gsub_file("app/assets/stylesheets/application.css", %r|\s*\*=\s*twitter/bootstrap\s*\n|, "")
        gsub_file("app/assets/stylesheets/application.css", %r|\s*\*=\s*twitter/bootstrap_responsive\s*\n|, "")
        if File.exist?('app/assets/stylesheets/bootstrap_override.css.less')
          puts <<-EOM
          Warning:
            app/assets/stylesheets/bootstrap_override.css.less exists
            It should be removed, as it has been superceded by app/assets/stylesheets/bootstrap_and_overrides.css.less
          EOM
        end
      end

Private Instance Methods

use_coffeescript?() click to toggle source
# File lib/generators/bootstrap/install/install_generator.rb, line 79
def use_coffeescript?
  return false if options[:'no-coffeescript']
  ::Rails.configuration.app_generators.rails[:javascript_engine] == :coffee
end
use_less?() click to toggle source
# File lib/generators/bootstrap/install/install_generator.rb, line 75
def use_less?
  (defined?(Less) && (stylesheets_type!='static') ) || (stylesheets_type=='less')
end