lib/jekyll/assets/proxy.rb in jekyll-assets-3.0.2 vs lib/jekyll/assets/proxy.rb in jekyll-assets-3.0.3
- old
+ new
@@ -9,12 +9,10 @@
module Jekyll
module Assets
class Proxy < Extensible
attr_reader :file
- DIG = Digest::SHA256
- DIR = "proxied"
class Deleted < StandardError
def initialize(obj)
super "#{obj} violated a contract and " \
"deleted your proxy file"
@@ -66,22 +64,30 @@
# @param [Hash] args the args.
# @return [Pathutil]
# --
def self.copy(asset, ctx:, args:)
env = ctx.registers[:site].sprockets
- raw = args.instance_variable_get(:@raw)
- key = DIG.hexdigest(raw)[0, 6]
- path = env.in_cache_dir(DIR)
+ path = env.in_cache_dir("proxied")
extname = File.extname(args[:argv1])
- out = Pathutil.new(path).join(key).sub_ext(extname)
- out.dirname.mkdir_p unless out.dirname.exist?
- Pathutil.new(asset.filename).cp(out)
+ out = Pathutil.new(path).join(digest(args))
+ .sub_ext(extname)
+ unless out.file?
+ out.dirname.mkdir_p
+ Pathutil.new(asset.filename)
+ .cp(out)
+ end
+
out
end
+ def self.digest(args)
+ Digest::SHA256.hexdigest(args.instance_variable_get(
+ :@raw))[0, 6]
+ end
+
# --
# @return [Symbol] the argument key.
# 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.
@@ -103,7 +109,7 @@
end
end
end
Jekyll::Assets::Hook.register :env, :after_init do
- append_path(in_cache_dir(Jekyll::Assets::Proxy::DIR))
+ append_path(in_cache_dir("proxied"))
end