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 = "      \\n\n      import \"@fortawesome/fontawesome-free/js/all\"\n    RUBY\n\n    append_to_file \"app/javascript/packs/application.js\", javascript_font_awesome_imports\n  else\n    say <<~WARNING, :red\n      ERROR: Looks like the webpacker installation is incomplete. Could not find application.js in app/javascript/packs.\n    WARNING\n  end\nend\n"

#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 = "      \\n\n      @import '@fortawesome/fontawesome-free';\n    RUBY\n\n    append_to_file \"app/javascript/stylesheets/application.scss\", stylesheet_font_awesome_imports\n  else\n    say \"Copying application.scss with FontAwesome imports\", :green\n    template(\"application.scss\", \"app/javascript/stylesheets/application.scss\")\n  end\nend\n"

#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", "    \\t\\t<%= stylesheet_pack_tag 'application', 'data-turbolinks-track': 'reload' %>\n  RUBY\nend\n", after: /stylesheet_link_tag.*\n/