module Roda::RodaPlugins::Sprockets
Constants
- DEFAULTS
Public Class Methods
configure(app, plugin_options = {})
click to toggle source
# File lib/roda/plugins/sprockets.rb, line 25 def self.configure(app, plugin_options = {}) if app.opts[:sprockets] app.opts[:sprockets].merge!(plugin_options) else app.opts[:sprockets] = plugin_options.dup end options = app.opts[:sprockets].merge! plugin_options DEFAULTS.each { |k, v| options[k] = v unless options.key?(k) } if !options[:root] options[:root] = app.opts[:root] || Dir.pwd end # opal-sprockets registers engines when required, but if we create Sprockets::Environment before # requiring that, they don't get registered require 'opal/sprockets' if options[:opal] options[:sprockets] ||= ::Sprockets::Environment.new options[:prefix].each do |prefix| # Support absolute asset paths # https://github.com/kalasjocke/sinatra-asset-pipeline/pull/54 if prefix.end_with? '/' paths = if Pathname.new(prefix).absolute? Dir[File.join(prefix)] else Dir[File.join(options[:root], prefix)] end else paths = if Pathname.new(prefix).absolute? Dir[File.join(prefix, '*')] else Dir[File.join(options[:root], prefix, '*')] end end paths.each do |path| options[:sprockets].append_path path end end if options[:opal] Opal.paths.each do |path| options[:sprockets].append_path path end end if options[:cache] options[:sprockets].cache = options[:cache] end options[:sprockets_helpers] = ::Sprockets::Helpers::Settings.new options[:sprockets_helpers].environment = options[:sprockets] options[:sprockets_helpers].digest = options[:digest] options[:sprockets_helpers].prefix = options[:path_prefix] unless options[:path_prefix].nil? options[:sprockets_helpers].debug = options[:debug] unless options[:debug] options[:sprockets].css_compressor = options[:css_compressor] unless options[:css_compressor].nil? options[:sprockets].js_compressor = options[:js_compressor] unless options[:js_compressor].nil? options[:sprockets_helpers].manifest = ::Sprockets::Manifest.new(options[:sprockets], options[:public_path]) options[:sprockets_helpers].protocol = options[:protocol] options[:sprockets_helpers].asset_host = options[:host] unless options[:host].nil? end end