Class: Jekyll::Assets::Proxy
- Inherits:
-
Extensible
- Object
- Extensible
- Jekyll::Assets::Proxy
- Defined in:
- lib/jekyll/assets/proxy.rb
Direct Known Subclasses
Jekyll::Assets::Plugins::ImageOptim, Jekyll::Assets::Plugins::MiniMagick
Defined Under Namespace
Classes: Deleted
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Attributes inherited from Extensible
#args, #asset, #ctx, #env, #jekyll
Class Method Summary collapse
-
.args_key(key = nil) ⇒ Symbol
– Allows you to tell the proxier which args are yours.
-
.copy(asset, ctx:, args:) ⇒ Pathutil
– Copy the asset to the proxied directory.
- .digest(args) ⇒ Object
-
.keys ⇒ Array<Symbol>
– Return a list of proxy keys.
-
.proxies_for(asset:, args:) ⇒ Object
–.
-
.proxy(asset, args:, ctx:) ⇒ Sprockets::Asset
– Run all your proxies on assets.
Instance Method Summary collapse
-
#initialize(file, **kwd) ⇒ Proxy
constructor
–.
Methods inherited from Extensible
for?, for_args?, for_type?, inherited, internal!, internal?, requirements
Constructor Details
#initialize(file, **kwd) ⇒ Proxy
–
114 115 116 117 |
# File 'lib/jekyll/assets/proxy.rb', line 114 def initialize(file, **kwd) super(**kwd) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
13 14 15 |
# File 'lib/jekyll/assets/proxy.rb', line 13 def file @file end |
Class Method Details
.args_key(key = nil) ⇒ Symbol
we will not run your proxy if the argkey doen’t match.
– Allows you to tell the proxier which args are yours. –
100 101 102 |
# File 'lib/jekyll/assets/proxy.rb', line 100 def self.args_key(key = nil) key.nil? ? @key : @key = key end |
.copy(asset, ctx:, args:) ⇒ Pathutil
this is done so we do not directly alter.
– Copy the asset to the proxied directory. –
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/jekyll/assets/proxy.rb', line 73 def self.copy(asset, ctx:, args:) env = ctx.registers[:site].sprockets path = env.in_cache_dir("proxied") extname = File.extname(args[:argv1]) 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 |
.digest(args) ⇒ Object
90 91 92 |
# File 'lib/jekyll/assets/proxy.rb', line 90 def self.digest(args) Digest::SHA256.hexdigest(args.to_h.inspect)[0, 6] end |
.keys ⇒ Array<Symbol>
– Return a list of proxy keys. This allows you to select their values from args. –
109 110 111 |
# File 'lib/jekyll/assets/proxy.rb', line 109 def self.keys inherited.map(&:arg_keys).flatten end |
.proxies_for(asset:, args:) ⇒ Object
–
56 57 58 59 60 61 62 63 |
# File 'lib/jekyll/assets/proxy.rb', line 56 def self.proxies_for(asset:, args:) Proxy.inherited.select do |o| o.for?({ type: asset.content_type, args: args, }) end end |
.proxy(asset, args:, ctx:) ⇒ Sprockets::Asset
– Run all your proxies on assets. –
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jekyll/assets/proxy.rb', line 30 def self.proxy(asset, args:, ctx:) env = ctx.registers[:site].sprockets return asset if (proxies = proxies_for(asset: asset, args: args)).empty? key = digest(args) 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, }) o = obj.process file = o if o.is_a?(Pathutil) && file != o raise Deleted, o unless file.exist? end file end env.find_asset!(out) end |