Class: Bootstrap::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/bootstrap/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_assetsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/generators/bootstrap/install/install_generator.rb', line 11

def add_assets

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

  if File.exist?('app/assets/stylesheets/application.css')
    # Add our own require:
    content = File.read("app/assets/stylesheets/application.css")
    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 "app/assets/stylesheets/application.css", style_require_block, :after => "require_self\n"
    end
  else
    copy_file "application.css", "app/assets/stylesheets/application.css"
  end

end

#add_bootstrapObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/generators/bootstrap/install/install_generator.rb', line 34

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_localeObject



47
48
49
50
51
52
53
54
# File 'lib/generators/bootstrap/install/install_generator.rb', line 47

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_legacyObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/generators/bootstrap/install/install_generator.rb', line 56

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