Module: Roda::RodaPlugins::Sprockets
- Defined in:
- lib/roda/plugins/sprockets.rb,
lib/roda/plugins/sprockets_task.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods, RequestMethods Classes: Task
Constant Summary collapse
- DEFAULTS =
{ sprockets: nil, precompile: %w(app.js app.css *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2), prefix: %w(assets vendor/assets), root: false, public_path: "public/assets/", path_prefix: "/assets", protocol: :http, css_compressor: nil, js_compressor: nil, host: nil, digest: true, opal: false, debug: nil, cache: nil, }.freeze
Class Method Summary collapse
Class Method Details
.configure(app, plugin_options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/roda/plugins/sprockets.rb', line 25 def self.configure(app, = {}) if app.opts[:sprockets] app.opts[:sprockets].merge!() else app.opts[:sprockets] = .dup end = app.opts[:sprockets] DEFAULTS.each { |k, v| [k] = v unless .key?(k) } if ![:root] [:root] = app.opts[:root] || Dir.pwd end if [:debug].nil? if %w[development test].include? ENV['RACK_ENV'] [:debug] = true else [:debug] = false end 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 [:opal] [:sprockets] ||= ::Sprockets::Environment.new [: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([:root], prefix)] end else paths = if Pathname.new(prefix).absolute? Dir[File.join(prefix, '*')] else Dir[File.join([:root], prefix, '*')] end end paths.each do |path| [:sprockets].append_path path end end if [:opal] Opal.paths.each do |path| [:sprockets].append_path path end end if [:cache] [:sprockets].cache = [:cache] end [:sprockets_helpers] = ::Sprockets::Helpers::Settings.new [:sprockets_helpers].environment = [:sprockets] [:sprockets_helpers].digest = [:digest] [:sprockets_helpers].prefix = [:path_prefix] [:sprockets_helpers].debug = [:debug] unless [:debug] [:sprockets].css_compressor = [:css_compressor] unless [:css_compressor].nil? [:sprockets].js_compressor = [:js_compressor] unless [:js_compressor].nil? [:sprockets_helpers].manifest = ::Sprockets::Manifest.new([:sprockets], [:public_path]) [:sprockets_helpers].protocol = [:protocol] [:sprockets_helpers].asset_host = [:host] unless [:host].nil? end end |