Class: Octopress::Tags::ImageCaptionTag::Tag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Octopress::Tags::ImageCaptionTag::Tag
- 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
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ Tag
Returns a new instance of Tag.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/octopress-image-caption-tag.rb', line 19 def initialize(tag_name, markup, tokens) if markup =~ /(\S.*\s+)?(https?:\/\/|\/)(\S+)(\s+\d+%?\s+\d+%?)?(\s+.+)?/i @class = $1 || '' @img = $2 + $3 if $5 @title = $5.strip end if $4 =~ /\s*(\d+%?)\s+(\d+%?)/ @width = $1 @height = $2 elsif @class.rstrip == "right" or @class.rstrip == "left" @width = "33%" else @width = "100%" end if /(?:"|')(?<title>[^"']+)?(?:"|')\s+(?:"|')(?<alt>[^"']+)?(?:"|')/ =~ @title @title = title @alt = alt else @alt = @title.gsub!(/"/, '"') if @title end end super end |
Instance Method Details
#render(context) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/octopress-image-caption-tag.rb', line 44 def render(context) super if @img && @width[-1] == "%" # Relative width, so width goes on outer span "<figure class='#{('caption-wrapper ' + @class).rstrip}' style='width:#{@width};'>" + "<a class='image-popup' href='#{@img}'>" + "<img class='caption' src='#{@img}' width='100%' height='100%' title='#{@title}' alt='#{@alt}'>" + "</a>" + "<figurecaption class='caption-text'>#{@title}</figurecaption>" + "</figure>" elsif @img # Absolute width, so width goes on the img tag and text span gets sytle-width:@width-15; "<figure class='#{('caption-wrapper ' + @class).rstrip}'>" + "<a class='image-popup' href='#{@img}'>" + "<img class='caption' src='#{@img}' width='#{@width}px' height='#{@height}px' title='#{@title}' alt='#{@alt}'>" + "</a>" + "<figurecaption class='caption-text' style='width:#{@width.to_i - 10}px;'>#{@title}</figurecaption>" + "</figure>" else "Error processing input, expected syntax: {% imgcap [class name(s)] /url/to/image [width height] [title [alt]] %}" end end |