class Jekyll::Assets::HTML::IMG
Public Class Methods
for?(type:, args:)
click to toggle source
– @example {% asset src srcset=“” %} @example {% asset src %} –
Calls superclass method
Jekyll::Assets::Extensible::for?
# 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
Public Instance Methods
complex(doc)
click to toggle source
–
# 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)
click to toggle source
–
# 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()
click to toggle source
–
# 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?()
click to toggle source
–
# File lib/jekyll/assets/plugins/html/img.rb, line 50 def srcset? args.key?(:srcset) && args[:srcset] .key?(:width) end