Class: Jekyll::Imgwh::Tag

Inherits:
Liquid::Tag
  • Object
show all
Includes:
Helpers
Defined in:
lib/jekyll/imgwh/tag.rb

Instance Method Summary collapse

Methods included from Helpers

#debug, #image_size, #name, #resolve_path

Constructor Details

#initialize(tag_name, content, tokens) ⇒ Tag

Returns a new instance of Tag.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jekyll/imgwh/tag.rb', line 10

def initialize(tag_name, content, tokens)
  content.strip!
  super

  if (m = @markup.match(%r/^(["'])((?:\1\1|(?!\1).)+)\1(?:\s+(.+))?$/))
    @quote, @src, @rest = m.captures
    @src = @src.gsub("#{@quote}#{@quote}", @quote)

  elsif (m = @markup.match(%r/^(?!["'])((?:(?!\{\{)\S|\{\{.+?\}\})+)(?:\s+(.+))?$/))
    @quote = ""
    @src, @rest = m.captures

  else
    raise SyntaxError, "#{@tag_name}: invalid tag markup: #{@markup.inspect}"
  end
end

Instance Method Details

#render(context) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jekyll/imgwh/tag.rb', line 27

def render(context)
  debug "---", "markup: #{@markup.inspect}", "src: #{@src.inspect}", "rest: #{@rest.inspect}"

  context.stack do
    context["#{@tag_name}_quote"] = @quote

    src = Liquid::Template.parse(@src).render(context)
    debug "src rendered: #{src.inspect}"

    size = image_size(src, context)
    debug "image size: #{size}"

    rest = render_rest(context)

    "<img src=#{quoted src} width=#{quoted size[0]} height=#{quoted size[1]}#{rest}>"
  end
end