Class: Jekyll::ResponsiveImage::Tag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::ResponsiveImage::Tag
- Includes:
- Common
- Defined in:
- lib/jekyll/responsive_image/tag.rb
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ Tag
constructor
A new instance of Tag.
- #render(context) ⇒ Object
Methods included from Common
Methods included from Utils
#format_output_path, #image_hash, #relative_dirname, #symbolize_keys
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ Tag
Returns a new instance of Tag.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/jekyll/responsive_image/tag.rb', line 6 def initialize(tag_name, markup, tokens) super @attributes = {} markup.scan(::Liquid::TagAttributes) do |key, value| # Strip quotes from around attribute values @attributes[key] = value.gsub(/^['"]|['"]$/, '') end end |
Instance Method Details
#render(context) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jekyll/responsive_image/tag.rb', line 17 def render(context) cache_key = @attributes.to_s result = @attributes['cache'] ? RenderCache.get(cache_key) : nil if result.nil? site = context.registers[:site] config = make_config(site) image = ImageProcessor.process(@attributes['path'], config) @attributes['original'] = image[:original] @attributes['resized'] = image[:resized] image_template = @attributes['template'] || config['template'] partial = File.read(image_template) template = Liquid::Template.parse(partial) result = template.render!(@attributes.merge(site.site_payload)) RenderCache.set(cache_key, result) end result end |