lib/jekyll/assets/proxy.rb in jekyll-assets-3.0.8 vs lib/jekyll/assets/proxy.rb in jekyll-assets-3.0.9

- old
+ new

@@ -26,20 +26,16 @@ # @param [Env] env the environment. # Run all your proxies on assets. # @return [Sprockets::Asset] # -- def self.proxy(asset, args:, ctx:) - proxies = Proxy.inherited.select do |o| - o.for?(type: asset.content_type, args: args) - end - - return asset if proxies.empty? env = ctx.registers[:site].sprockets - file = copy(asset, args: args, ctx: ctx) - cache = file.basename.sub_ext("").to_s + return asset if (proxies = proxies_for(asset: asset, args: args)).empty? + key = digest(args) - env.cache.fetch(cache) do + out = env.cache.fetch(key) do + file = copy(asset, args: args, ctx: ctx) proxies.each do |o| obj = o.new(file, { args: args, asset: asset, ctx: ctx, @@ -48,17 +44,27 @@ o = obj.process file = o if o.is_a?(Pathutil) && file != o raise Deleted, o unless file.exist? end - true + file end - env.find_asset!(file) + env.find_asset!(out) end # -- + def self.proxies_for(asset:, args:) + Proxy.inherited.select do |o| + o.for?({ + type: asset.content_type, + args: args, + }) + end + end + + # -- # Copy the asset to the proxied directory. # @note this is done so we do not directly alter. # @param [Sprockets::Asset] asset the current asset. # @param [Env] env the environment. # @param [Hash] args the args. @@ -90,15 +96,19 @@ # Allows you to tell the proxier which args are yours. # @note we will not run your proxy if the argkey doen't match. # @param [Symbol] key the key. # -- def self.args_key(key = nil) - unless key.nil? - @key = - key - end + key.nil? ? @key : @key = key + end - @key + # -- + # Return a list of proxy keys. + # This allows you to select their values from args. + # @return [Array<Symbol>] + # -- + def self.keys + inherited.map(&:arg_keys).flatten end # -- def initialize(file, **kwd) super(**kwd)