class Jekyll::ImgSrcsetTag
Public Class Methods
new(tag_name, text, tokens)
click to toggle source
Calls superclass method
# File lib/jekyll-img-srcset.rb, line 202 def initialize(tag_name, text, tokens) super @text = text end
Public Instance Methods
cache()
click to toggle source
# File lib/jekyll-img-srcset.rb, line 198 def cache @@cache ||= Jekyll::Cache.new("Jekyll::ImgSrcset") end
render(context)
click to toggle source
# File lib/jekyll-img-srcset.rb, line 207 def render(context) config = context.registers[:site].config base_image_path = config["base_image_path"] || "assets/images" attrs = { classes: [], } [/(\S+)="([^"]+?)"/, /(\S+)=([^\s\}"][^\s\}]+)/].each do | attr_regex | @text.scan(attr_regex) do | key, value | if key == "class" context_content = check_in_context context, value if context_content.nil? attrs[:classes] << value else attrs[:classes] << context_content end else context_content = check_in_context context, value if context_content.nil? attrs[key.to_sym] = value else attrs[key.to_sym] = context_content end end end end if File.exists?(File.join base_image_path, attrs[:src]) widths, original_width = resize_image( attrs[:src], config["widths"], config["destination"], base_image_path, cache) context.registers[:site].keep_files.concat(widths.map do |w| File.join(base_image_path, "#{w}", attrs[:src]) end) format_image(attrs, widths, original_width, attrs[:src], attrs[:caption], attrs[:title], context.registers[:site].baseurl, base_image_path) else puts "image not found: #{File.join base_image_path, attrs[:src]} in page at url #{context["page"]["url"]}" "" end end