class Hoboken::AddOns::Sprockets

Rack-based asset packaging system.

Public Instance Methods

add_gems() click to toggle source
# File lib/hoboken/add_ons/sprockets.rb, line 14
def add_gems
  gem 'sassc', version: '2.4', group: :assets
  gem 'sprockets', version: '4.0', group: :assets
  gem 'uglifier', version: '4.2', group: :assets
  gem 'yui-compressor', version: '0.12', group: :assets
end
copy_sprockets_helpers() click to toggle source
# File lib/hoboken/add_ons/sprockets.rb, line 21
def copy_sprockets_helpers
  copy_file('hoboken/templates/sprockets.rake', 'tasks/sprockets.rake')
  copy_file('hoboken/templates/sprockets_chain.rb', 'middleware/sprockets_chain.rb')
  copy_file('hoboken/templates/sprockets_helper.rb', 'helpers/sprockets.rb')
end
create_assets_folder() click to toggle source
# File lib/hoboken/add_ons/sprockets.rb, line 8
def create_assets_folder
  empty_directory('assets')
  FileUtils.cp('public/css/styles.css', 'assets/styles.scss')
  FileUtils.cp('public/js/app.js', 'assets/app.js')
end
directions() click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/hoboken/add_ons/sprockets.rb, line 71
      def directions
        text = <<~TEXT
          #{'          '}
                    Run `bundle install` to get the sprockets gem and its
                    dependencies.
          #{'          '}
                    Running the server in development mode will serve css
                    and js files from /assets. In order to serve assets in
                    production, you must run `rake assets:precompile`. Read
                    the important note below before running this rake task.
        TEXT

        important = <<~TEXT
          #{'          '}
                    Important Note:
                    Any css or js files from the /public folder have been copied
                    to /assets, the original files remain intact in /public, but
                    will be replaced the first time you run `rake assets:precompile`.
                    You may want to backup those files if they are not under source
                    control before running the Rake command.
        TEXT

        say text
        say important, :red
      end
update_app() click to toggle source
# File lib/hoboken/add_ons/sprockets.rb, line 27
      def update_app
        snippet = <<~CODE
          require File.expand_path('middleware/sprockets_chain', settings.root)
          use Middleware::SprocketsChain, %r{/assets} do |env|
            %w[assets vendor].each do |f|
              env.append_path File.expand_path("../\#{f}", __FILE__)
            end
          end
        CODE

        indentation = classic? ? 2 : 6
        insert_into_file('app.rb', after: /configure :development do\n/) do
          "#{indent(snippet, indentation)}\n"
        end

        insert_into_file('app.rb', after: /configure do\n/) do
          "#{indent("helpers Helpers::Sprockets\n", indentation)}\n"
        end
      end