lib/roda/plugins/assets.rb in roda-3.0.0 vs lib/roda/plugins/assets.rb in roda-3.1.0
- old
+ new
@@ -292,19 +292,24 @@
# paths will be considered relative to the application's :root option.
# :sri :: Enables subresource integrity when setting up references to compiled assets. The value should be
# :sha256, :sha384, or :sha512 depending on which hash algorithm you want to use. This changes the
# hash algorithm that Roda will use when naming compiled asset files. The default is :sha256, you
# can use nil to disable subresource integrity.
+ # :timestamp_paths :: Include the timestamp of assets in asset paths in non-compiled mode. Doing this can
+ # slow down development requests due to additional requests to get last modified times,
+ # put it will make sure the paths change in development when there are modifications,
+ # which can fix issues when using a caching proxy in non-compiled mode.
module Assets
DEFAULTS = {
:compiled_name => 'app'.freeze,
:js_dir => 'js'.freeze,
:css_dir => 'css'.freeze,
:prefix => 'assets'.freeze,
:concat_only => false,
:compiled => false,
:add_suffix => false,
+ :timestamp_paths => false,
:group_subdirs => true,
:compiled_css_dir => nil,
:compiled_js_dir => nil,
:sri => :sha256
}.freeze
@@ -554,11 +559,16 @@
Minjs::Compressor::Compressor.new(:debug => false).compress(content).to_js
end
# Compress the JS using Uglifier, requires javascript runtime
def compress_js_uglifier(content)
- require 'uglifier'
+ begin
+ require 'uglifier'
+ rescue => e
+ raise CompressorNotFound, "#{e.class}: #{e.message}", e.backtrace
+ end
+
Uglifier.compile(content)
end
# Compress the CSS using YUI Compressor, requires java runtime
def compress_js_yui(content)
@@ -608,11 +618,11 @@
asset_dir = o[ltype]
if dirs && !dirs.empty?
dirs.each{|f| asset_dir = asset_dir[f]}
prefix = "#{dirs.join('/')}/" if o[:group_subdirs]
end
- Array(asset_dir).map{|f| "#{url_prefix}/#{o[:"#{stype}_prefix"]}#{prefix}#{f}#{o[:"#{stype}_suffix"]}"}
+ Array(asset_dir).map{|f| "#{url_prefix}/#{o[:"#{stype}_prefix"]}#{"#{asset_last_modified(File.join(o[:"#{stype}_path"], *[prefix, f].compact)).to_i}/" if o[:timestamp_paths]}#{prefix}#{f}#{o[:"#{stype}_suffix"]}"}
end
end
# Return a string containing html tags for the given asset type.
# This will use a script tag for the :js type and a link tag for
@@ -753,10 +763,10 @@
"#{k.sub(/\A#{type}/, '')}.#{md}.#{type}"
end
/#{o[:"compiled_#{type}_prefix"]}(#{Regexp.union(assets)})/
else
assets = unnest_assets_hash(o[type])
- /#{o[:"#{type}_prefix"]}(#{Regexp.union(assets.uniq)})#{o[:"#{type}_suffix"]}/
+ /#{o[:"#{type}_prefix"]}#{"\\d+\/" if o[:timestamp_paths]}(#{Regexp.union(assets.uniq)})#{o[:"#{type}_suffix"]}/
end
end
# Recursively unnested the given assets hash, returning a single array of asset
# files for the given.