Sha256: 725223ae11aefd4a2b3c65a2ce50991e0420d216e9975f90f083162af7585598

Contents?: true

Size: 1.88 KB

Versions: 14

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

module Boring
  module FontAwesome
    module Yarn
      class InstallGenerator < Rails::Generators::Base
        source_root File.expand_path("templates", __dir__)
        desc "Adds fontawesome via rubygems to the application"

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

        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

        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

        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
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
boring_generators-0.15.0 lib/generators/boring/font_awesome/yarn/install/install_generator.rb
boring_generators-0.14.0 lib/generators/boring/font_awesome/yarn/install/install_generator.rb
boring_generators-0.13.0 lib/generators/boring/font_awesome/yarn/install/install_generator.rb
boring_generators-0.12.0 lib/generators/boring/font_awesome/yarn/install/install_generator.rb
boring_generators-0.11.0 lib/generators/boring/font_awesome/yarn/install/install_generator.rb
boring_generators-0.10.0 lib/generators/boring/font_awesome/yarn/install/install_generator.rb
boring_generators-0.9.0 lib/generators/boring/font_awesome/yarn/install/install_generator.rb
boring_generators-0.8.0 lib/generators/boring/font_awesome/yarn/install/install_generator.rb
boring_generators-0.7.0 lib/generators/boring/font_awesome/yarn/install/install_generator.rb
boring_generators-0.6.0 lib/generators/boring/font_awesome/yarn/install/install_generator.rb
boring_generators-0.5.0 lib/generators/boring/font_awesome/yarn/install/install_generator.rb
boring_generators-0.4.0 lib/generators/boring/font_awesome/yarn/install/install_generator.rb
boring_generators-0.3.0 lib/generators/boring/font_awesome/yarn/install/install_generator.rb
boring_generators-0.2.0 lib/generators/boring/font_awesome/yarn/install/install_generator.rb