lib/roda/plugins/assets.rb in roda-3.18.0 vs lib/roda/plugins/assets.rb in roda-3.19.0

- old
+ new

@@ -296,11 +296,13 @@ # 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. + # which can fix issues when using a caching proxy in non-compiled mode. This can also + # be specified as a string to use that string to separate the timestamp from the asset. + # By default, <tt>/</tt> is used as the separator if timestamp paths are enabled. module Assets DEFAULTS = { :compiled_name => 'app'.freeze, :js_dir => 'js'.freeze, :css_dir => 'css'.freeze, @@ -373,10 +375,14 @@ if opts[:early_hints] app.plugin :early_hints end + if opts[:timestamp_paths] && !opts[:timestamp_paths].is_a?(String) + opts[:timestamp_paths] = '/' + end + DEFAULTS.each do |k, v| opts[k] = v unless opts.has_key?(k) end [ @@ -627,13 +633,13 @@ if dirs && !dirs.empty? dirs.each{|f| asset_dir = asset_dir[f]} prefix = "#{dirs.join('/')}/" if o[:group_subdirs] end Array(asset_dir).map do |f| - if o[:timestamp_paths] + if ts = o[:timestamp_paths] mtime = asset_last_modified(File.join(o[:"#{stype}_path"], *[prefix, f].compact)) - mtime = "#{sprintf("%i%06i", mtime.to_i, mtime.usec)}/" + mtime = "#{sprintf("%i%06i", mtime.to_i, mtime.usec)}#{ts}" end "#{url_prefix}/#{o[:"#{stype}_prefix"]}#{mtime}#{prefix}#{f}#{o[:"#{stype}_suffix"]}" end end end @@ -782,10 +788,11 @@ "#{k.sub(/\A#{type}/, '')}.#{md}.#{type}" end /#{o[:"compiled_#{type}_prefix"]}(#{Regexp.union(assets)})/ else assets = unnest_assets_hash(o[type]) - /#{o[:"#{type}_prefix"]}#{"\\d+\/" if o[:timestamp_paths]}(#{Regexp.union(assets.uniq)})#{o[:"#{type}_suffix"]}/ + ts = o[:timestamp_paths] + /#{o[:"#{type}_prefix"]}#{"\\d+#{ts}" if ts}(#{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.