Class: BootswatchRails::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#copy_application_jsObject



37
38
39
40
41
# File 'lib/generators/bootswatch_rails/install/install_generator.rb', line 37

def copy_application_js
  file = "app/assets/javascripts/application.js"
  remove_file file
  template "application.js", file
end

#copy_directoriesObject



54
55
56
57
58
# File 'lib/generators/bootswatch_rails/install/install_generator.rb', line 54

def copy_directories
  directory "app", force: true
  directory "config"
  directory "lib", force: true
end

#setup_assets_precompileObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/generators/bootswatch_rails/install/install_generator.rb', line 43

def setup_assets_precompile
  return unless options.cdn?
  initializer "bootswatch_assets.rb" do
    assets  = "jquery.js"
    assets += " jquery-ui.js" if options.ui?
    assets += " jquery.dataTables.js dataTables.responsive.js" if options.dt?
    assets += " bootstrap.js"
    "Rails.application.config.assets.precompile += %w( #{assets} )"
  end
end

#setup_headObject



60
61
62
# File 'lib/generators/bootswatch_rails/install/install_generator.rb', line 60

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

#update_application_controllerObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/bootswatch_rails/install/install_generator.rb', line 16

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 logged_in?",
    "    @current_theme ||= default_theme",
    "  end",
    "  helper_method :current_theme",
    ""
  ]
  inject_into_file file, lines.join("\n"), before: /^end$/
end