Class: Jekyll::ResponsiveImage::Tag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::ResponsiveImage::Tag
- 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
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ Tag
Returns a new instance of Tag.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/jekyll/responsive_image/tag.rb', line 4 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
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jekyll/responsive_image/tag.rb', line 15 def render(context) config = ResponsiveImage.defaults.dup config.merge!(context.registers[:site].config['responsive_image']) 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) template.render!(@attributes) end |