Class: PufferPages::Liquid::Tags::Image

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/puffer_pages/liquid/tags/image.rb

Constant Summary collapse

Syntax =
/^(#{::Liquid::QuotedFragment})/

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ Image

Returns a new instance of Image.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/puffer_pages/liquid/tags/image.rb', line 8

def initialize(tag_name, markup, tokens)
  if markup =~ Syntax
    @path = $1
  else
    raise SyntaxError.new("Syntax Error in 'image' - Valid syntax: image '/path/to/image'")
  end

  @attributes = {}
  markup.scan(::Liquid::TagAttributes) do |key, value|
    @attributes[key] = value
  end

  super
end

Instance Method Details

#render(context) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/puffer_pages/liquid/tags/image.rb', line 23

def render(context)
  attributes = {}
  @attributes.each do |key, value|
    attributes[key] = context[value]
  end

  context.registers[:tracker].register("<%= image_tag #{@path}, #{attributes} %>")
end