Class: Octopress::Tags::ImageCaptionTag::Tag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Octopress::Tags::ImageCaptionTag::Tag
- Includes:
- ImageCaptionFunctions
- Defined in:
- lib/octopress-image-caption-tag.rb
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ Tag
constructor
A new instance of Tag.
- #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) ⇒ Tag
Returns a new instance of Tag.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/octopress-image-caption-tag.rb', line 84 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
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/octopress-image-caption-tag.rb', line 95 def render(context) super @caption = @title if @img && @width[-1] == '%' # Relative width, so width goes on outer span relative_sized_figure elsif @img && @width[-2..-1] == 'em' # Absolute size in ems 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: {% imgcap [class name(s)] /url/to/image [width height] [title [alt]] %}' end end |