Class: Jekyll::Assets::HTML::IMG
- Inherits:
-
Jekyll::Assets::HTML
- Object
- Extensible
- Jekyll::Assets::HTML
- Jekyll::Assets::HTML::IMG
- Defined in:
- lib/jekyll/assets/plugins/html/img.rb
Instance Attribute Summary
Attributes inherited from Jekyll::Assets::HTML
Attributes inherited from Extensible
#args, #asset, #ctx, #env, #jekyll
Class Method Summary collapse
Instance Method Summary collapse
-
#complex(doc) ⇒ Object
–.
-
#path(dimensions:, type: nil) ⇒ Object
–.
-
#run ⇒ Object
–.
-
#srcset? ⇒ Boolean
–.
Methods inherited from Jekyll::Assets::HTML
build, #initialize, make_doc, skips, wants_xml?
Methods inherited from Extensible
for_args?, for_type?, inherited, #initialize, internal!, internal?, requirements
Constructor Details
This class inherits a constructor from Jekyll::Assets::HTML
Class Method Details
.for?(type:, args:) ⇒ Boolean
– –
59 60 61 62 63 64 65 66 |
# File 'lib/jekyll/assets/plugins/html/img.rb', line 59 def self.for?(type:, args:) return false unless super return false if args.key?(:pic) return false if args.key?(:inline) && type == "image/svg+xml" true end |
Instance Method Details
#complex(doc) ⇒ Object
–
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jekyll/assets/plugins/html/img.rb', line 24 def complex(doc) img = doc.img @args.to_h(html: true, skip: HTML.skips) Array(args[:srcset][:width]).each do |w| dimensions, density, type = w.to_s.split(%r!\s+!, 3) img["srcset"] ||= "" img["srcset"] += ", #{path(dimensions: dimensions, type: type)} " img["srcset"] += density || "#{dimensions}w" img["srcset"] = img["srcset"] .gsub(%r!^,\s*!, "") end end |
#path(dimensions:, type: nil) ⇒ Object
–
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jekyll/assets/plugins/html/img.rb', line 38 def path(dimensions:, type: nil) args_ = "#{args[:argv1]} @path" args_ += " magick:resize=#{dimensions}" args_ += " magick:format=#{type}" if type args_ += " @optim" if args.key?(:optim) pctx = Liquid::ParseContext.new tag = Tag.new("asset", args_, pctx) tag.render(ctx) end |
#run ⇒ Object
–
15 16 17 18 19 20 21 |
# File 'lib/jekyll/assets/plugins/html/img.rb', line 15 def run Nokogiri::HTML::Builder.with(doc) do |d| srcset? ? complex(d) : d.img(args.to_h({ html: true, skip: HTML.skips })) end end |
#srcset? ⇒ Boolean
–
50 51 52 53 |
# File 'lib/jekyll/assets/plugins/html/img.rb', line 50 def srcset? args.key?(:srcset) && args[:srcset] .key?(:width) end |