module Roda::RodaPlugins::Assets::RequestClassMethods
def _asset_regexp(type, key, digest)
def _asset_regexp(type, key, digest) "#{key.sub(/\A#{type}/, '')}.#{digest}.#{type}" end
def assets_matchers
An array of asset type strings and regexps for that type, for all asset types
def assets_matchers @assets_matchers ||= [:css, :js].map do |t| if regexp = assets_regexp(t) [t, regexp].freeze end end.compact.freeze end
def assets_regexp(type)
The regexp matcher to use for the given type. This handles any asset groups
def assets_regexp(type) o = roda_class.assets_opts if compiled = o[:compiled] assets = compiled. select{|k,_| k =~ /\A#{type}/}. map{|k, md| _asset_regexp(type, k, md)} return if assets.empty? /#{o[:"compiled_#{type}_prefix"]}(#{Regexp.union(assets)})/ else return unless assets = o[type] assets = unnest_assets_hash(assets) ts = o[:timestamp_paths] /#{o[:"#{type}_prefix"]}#{"\\d+#{ts}" if ts}(#{Regexp.union(assets.uniq)})#{o[:"#{type}_suffix"]}/ end end
def unnest_assets_hash(h)
Recursively unnested the given assets hash, returning a single array of asset
def unnest_assets_hash(h) case h when Hash h.map do |k,v| assets = unnest_assets_hash(v) assets = assets.map{|x| "#{k}/#{x}"} if roda_class.assets_opts[:group_subdirs] assets end.flatten(1) else Array(h) end end