summaryrefslogtreecommitdiff
path: root/_plugins/image.rb
blob: 93b70e944a52dcd73a3fb8d9c7ae146f27e2da38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Jekyll
  class ImageTag < Liquid::Tag

    def initialize(tag_name, parameters, tokens)
      super
      @params = {}
      parameters.scan(/(\w+)\s*=\s*"([^"]+)"/) do |key, value|
        @params[key] = value
      end
    end

    def render(context)
      url = @params['url']
      alt = @params['alt']
      if alt
        "<img src='#{url}' alt='#{alt}' />"
      else
        "<img src='#{url}' />"
      end
    end
    Liquid::Template.register_tag('image', self)
  end
end