Class: Jekyll::SrcTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll/image_optimizer.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ SrcTag

Returns a new instance of SrcTag.



62
63
64
65
66
67
68
# File 'lib/jekyll/image_optimizer.rb', line 62

def initialize(tag_name, markup, tokens)
  super
  if markup =~ /\s*(.+?)\s+([^\s]+)\s*/
    @dir = $1
    @index = $2
  end
end

Instance Method Details

#render(context) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/jekyll/image_optimizer.rb', line 70

def render(context)
  base_url=context['site']['baseurl']
  index=Liquid::Template.parse(@index).render(context).to_i
  src=context['page']['image'][index]['url']
  hash=ImageHash.new(use_hash(context['site']))
  for file in Dir[hash.dir_search_pattern(opt_dir(context['site'])+@dir, src)]
    if File.file? file and hash.hash? file
      return base_url+'/'+file
    end
  end
end