class Octopress::Tags::ImageCaptionTag::Block

Public Class Methods

new(tag_name, markup, tokens) click to toggle source
Calls superclass method
# File lib/octopress-image-caption-tag.rb, line 118
def initialize(tag_name, markup, tokens)
  if %r{(?<classname>\S.*\s+)?(?<protocol>https?://|/)(?<url>\S+)(?<sizes>\s+\d+(\.\d+)?%?(em)?\s+\d+(\.\d+)?%?(em)?)?(?<title>\s+.+)?} =~ markup
    @class = classname || 'center'
    @img = "#{protocol}#{url}"
    @title = title.strip if title
    parse_sizes(sizes)
    parse_title(@title)
  end
  super
end

Public Instance Methods

render(context) click to toggle source
Calls superclass method
# File lib/octopress-image-caption-tag.rb, line 129
def render(context)
  site = context.registers[:site]
  converter = site.find_converter_instance(Jekyll::Converters::Markdown)
  @caption = converter.convert(super).lstrip.rstrip
  if @img && @width[-1] == '%' # Relative width, so width goes on outer span
    relative_sized_figure
  elsif @img && @width[-2..-1] == 'em'
    em_sized_figure
  elsif @img # Absolute width, so width goes on the img tag and text span gets sytle-width:@width-15;
    absolute_sized_figure
  else
    'Error processing input, expected syntax: {% imgcaption [class name(s)] /url/to/image [width height] [title [alt]] %} Caption Text {% endimgcaption %}'
  end
end