Class: Jekyll::Assets::Plugins::Searcher
- Inherits:
-
Object
- Object
- Jekyll::Assets::Plugins::Searcher
- Defined in:
- lib/jekyll/assets/plugins/searcher.rb
Overview
– Searches for ‘<img>` that have `<img asset>` or `<img asset=“args”>` and runs them through the asset system. This allows you to use real assets inside of your Markdown pre-convert. –
Instance Method Summary collapse
-
#initialize(doc) ⇒ Searcher
constructor
A new instance of Searcher.
-
#run ⇒ Object
–.
Constructor Details
#initialize(doc) ⇒ Searcher
Returns a new instance of Searcher.
20 21 22 |
# File 'lib/jekyll/assets/plugins/searcher.rb', line 20 def initialize(doc) @doc = doc end |
Instance Method Details
#run ⇒ Object
–
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jekyll/assets/plugins/searcher.rb', line 25 def run html.search("img[@asset]").each do |v| raise ArgumentError, "src is empty" unless v[:src] args = "#{v.delete('src')&.value} #{v.delete('asset')&.value}" pctx = ::Liquid::ParseContext.new attrs = v.attributes.keys args, = Tag.new("asset", args, pctx).render_raw(ctx) args.to_h(html: true).each do |k, vv| unless attrs.include?(k.to_s) v.set_attribute(k, vv) end end end out = html.to_html @doc.output = out end |