Class: Octopress::Tags::ImageCaptionTag::Block
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Octopress::Tags::ImageCaptionTag::Block
- Includes:
- ImageCaptionFunctions
- Defined in:
- lib/octopress-image-caption-tag.rb
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ Block
constructor
A new instance of Block.
- #render(context) ⇒ Object
Methods included from ImageCaptionFunctions
#absolute_sized_figure, #em_sized_figure, #parse_sizes, #parse_title, #relative_sized_figure
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ Block
Returns a new instance of Block.
118 119 120 121 122 123 124 125 126 127 |
# 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 |
Instance Method Details
#render(context) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# 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 |