aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Mathis <brandon@imathis.com>2011-07-17 20:23:08 -0400
committerBrandon Mathis <brandon@imathis.com>2011-07-17 20:23:08 -0400
commit790521a44b12c6a287d0d52c80aafe6c93fc341f (patch)
treed95c32ece3eb054c6bbcb65f1f7199cd6d763529
parente17bb6ebd52e83cd00a1469ab9142c1c3ecfe656 (diff)
downloadmy_new_personal_website-790521a44b12c6a287d0d52c80aafe6c93fc341f.tar.xz
my_new_personal_website-790521a44b12c6a287d0d52c80aafe6c93fc341f.zip
Added a plugin for easily generating <figure> and <figcaption> with images
Diffstat (limited to '')
-rw-r--r--.themes/classic/plugins/figure_tag.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/.themes/classic/plugins/figure_tag.rb b/.themes/classic/plugins/figure_tag.rb
new file mode 100644
index 00000000..550e677f
--- /dev/null
+++ b/.themes/classic/plugins/figure_tag.rb
@@ -0,0 +1,69 @@
+# Title: Simple Image Figure tag for Jekyll
+# Author: Brandon Mathis http://brandonmathis.com
+# Description: Easily output images in <figure> with an optional <figcaption> and class names.
+#
+# Syntax {% figure [class name(s)] url [caption text] %}
+#
+# Example:
+# {% figure left half http://site.com/images/ninja.png Ninja Attack! %}
+#
+# Output:
+# <figure class='left half'><img src="http://site.com/images/ninja.png"><figcaption>Ninja Attack!</figcaption></figure>
+#
+# Example 2 (image with caption)
+# {% figure /images/ninja.png Ninja Attack! %}
+#
+# Output:
+# <figure><img src="/images/ninja.png"><figcaption>Ninja Attack!</figcaption></figure>
+#
+# Example 3 (just an image with classes)
+# {% figure right /images/ninja.png %}
+#
+# Output:
+# <figure><img class="right" src="/images/ninja.png"></figure>
+#
+
+module Jekyll
+
+ class FigureImageTag < Liquid::Tag
+ ClassImgCaption = /(\S[\S\s]*)\s+(https?:\/\/|\/)(\S+)\s+(.+)/i
+ ClassImg = /(\S[\S\s]*)\s+(https?:\/\/|\/)(\S+)/i
+ ImgCaption = /^\s*(https?:\/\/|\/)(\S+)\s+(.+)/i
+ Img = /^\s*(https?:\/\/|\/)(\S+\s)/i
+
+ @img = nil
+ @caption = nil
+ @class = ''
+
+ def initialize(tag_name, markup, tokens)
+ if markup =~ ClassImgCaption
+ @class = $1
+ @img = $2 + $3
+ @caption = $4
+ elsif markup =~ ClassImg
+ @class = $1
+ @img = $2 + $3
+ elsif markup =~ ImgCaption
+ @img = $1 + $2
+ @caption = $3
+ elsif markup =~ Img
+ @img = $1 + $2
+ end
+ super
+ end
+
+ def render(context)
+ output = super
+ if @img
+ figure = "<figure class='#{@class}'>"
+ figure += "<img src='#{@img}'>"
+ figure += "<figcaption>#{@caption}</figcaption>" if @caption
+ figure += "</figure>"
+ else
+ "Error processing input, expected syntax: {% figure [class name(s)] /url/to/image [caption] %}"
+ end
+ end
+ end
+end
+
+Liquid::Template.register_tag('figure', Jekyll::FigureImageTag)