Class: Jekyll::ImgLink

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

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ ImgLink

Returns a new instance of ImgLink.



111
112
113
114
115
116
117
118
119
120
# File 'lib/ext.rb', line 111

def initialize(tag_name, text, tokens)
  arr = text.strip.split(' ',2)
  if arr.count == 2 
    @img_name =  arr[1]
    @title =  arr[0]
  else
    @img_name =  arr[0]
    @title =  "img_link"
  end
end

Instance Method Details

#render(context) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/ext.rb', line 122

def render(context)
  path = context['page']['path']
  

  dirPath0 = path[0...(path.length - 3)]
  pathComponent = dirPath0.split("/")
  dirPath = pathComponent[-1]
  
  base = $g_config['baseurl']
  link = "/pics/#{dirPath}/#{@img_name}"
  if base && base.length
    link = "#{base}/pics/#{dirPath}/#{@img_name}"
  end 
  return "[#{@title}](#{link})" 
end