Class: Bootstrap::Generators::InstallGenerator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



8
9
10
# File 'lib/generators/bootstrap/install/install_generator.rb', line 8

def app_name
  @app_name
end

Instance Method Details

#setupObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/generators/bootstrap/install/install_generator.rb', line 10

def setup
  # Adding Assets
  js_manifest = 'app/assets/javascripts/application.js'

  if File.exist?(js_manifest)
    insert_into_file js_manifest, "//= require jquery3\n//= require popper\n//= require bootstrap-sprockets\n", :after => "turbolinks\n"
  else
    copy_file "application.js", js_manifest
  end

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

  if File.exist?(css_manifest)
    File.delete(css_manifest)
    if File.exist?(scss_manifest)
      File.delete(scss_manifest)
      copy_file "application.scss", "app/assets/stylesheets/application.scss"
      copy_file "bootstrap_forms.scss", "app/assets/stylesheets/bootstrap_forms.scss"
    else
      copy_file "application.scss", "app/assets/stylesheets/application.scss"
      copy_file "bootstrap_forms.scss", "app/assets/stylesheets/bootstrap_forms.scss"
    end
  else
    copy_file "application.scss", "app/assets/stylesheets/application.scss"
    copy_file "bootstrap_forms.scss", "app/assets/stylesheets/bootstrap_forms.scss"
  end

  # Adding Templates
  app = ::Rails.application
  @app_name = app.class.to_s.split("::").first
  ext = app.config.generators.options[:rails][:template_engine] || :erb
  template "layout.html.#{ext}", "app/views/layouts/application.html.#{ext}"
  template "_head.html.#{ext}", "app/views/shared/_head.html.#{ext}"
  template "_navbar.html.#{ext}", "app/views/shared/_navbar.html.#{ext}"
  template "_footer.html.#{ext}", "app/views/shared/_footer.html.#{ext}"
  template "_notices.html.#{ext}", "app/views/shared/_notices.html.#{ext}"
  template "_devise.html.#{ext}", "app/views/shared/_devise.html.#{ext}"
  copy_file "application_helper.rb", "app/helpers/application_helper.rb"

  # Adding Templates Folder for future Generators
  copy_file "_form.html.erb", "lib/templates/erb/scaffold/_form.html.erb"
  copy_file "edit.html.erb", "lib/templates/erb/scaffold/edit.html.erb"
  copy_file "index.html.erb", "lib/templates/erb/scaffold/index.html.erb"
  copy_file "new.html.erb", "lib/templates/erb/scaffold/new.html.erb"
  copy_file "show.html.erb", "lib/templates/erb/scaffold/show.html.erb"

  append_to_file "Gemfile", "# Adding gems required by BootstrapMan\ngem 'jquery-rails'\ngem 'bootstrap'\ngem 'font-awesome-rails'\ngem 'bootstrap_form'\n"
end