Class: Boring::FontAwesome::Yarn::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_font_awesome_packageObject



10
11
12
13
# File 'lib/generators/boring/font_awesome/yarn/install/install_generator.rb', line 10

def add_font_awesome_package
  say "Adding fontawesome packages", :green
  run "yarn add @fortawesome/fontawesome-free"
end

#import_font_awesome_javascriptObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/generators/boring/font_awesome/yarn/install/install_generator.rb', line 30

def import_font_awesome_javascript
  if File.exist?("app/javascript/packs/application.js")
    javascript_font_awesome_imports = <<~RUBY
      \n
      import "@fortawesome/fontawesome-free/js/all"
    RUBY

    append_to_file "app/javascript/packs/application.js", javascript_font_awesome_imports
  else
    say <<~WARNING, :red
      ERROR: Looks like the webpacker installation is incomplete. Could not find application.js in app/javascript/packs.
    WARNING
  end
end

#import_font_awesome_stylesheetObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/generators/boring/font_awesome/yarn/install/install_generator.rb', line 15

def import_font_awesome_stylesheet
  say "Adding font awesome stylesheets", :green
  if File.exist?("app/javascript/stylesheets/application.scss")
    stylesheet_font_awesome_imports = <<~RUBY
      \n
      @import '@fortawesome/fontawesome-free';
    RUBY

    append_to_file "app/javascript/stylesheets/application.scss", stylesheet_font_awesome_imports
  else
    say "Copying application.scss with FontAwesome imports", :green
    template("application.scss", "app/javascript/stylesheets/application.scss")
  end
end

#insert_stylesheet_packs_tagObject



45
46
47
48
49
# File 'lib/generators/boring/font_awesome/yarn/install/install_generator.rb', line 45

def insert_stylesheet_packs_tag
  insert_into_file "app/views/layouts/application.html.erb", <<~RUBY, after: /stylesheet_link_tag.*\n/
    \t\t<%= stylesheet_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
  RUBY
end