module Roda::RodaPlugins::Assets::RequestClassMethods
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| [t.to_s.freeze, assets_regexp(t)].freeze if roda_class.assets_opts[t] 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 do |k, md| "#{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"]}/ 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