From 790521a44b12c6a287d0d52c80aafe6c93fc341f Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Sun, 17 Jul 2011 20:23:08 -0400 Subject: [PATCH] Added a plugin for easily generating
and
with images --- .themes/classic/plugins/figure_tag.rb | 69 +++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .themes/classic/plugins/figure_tag.rb diff --git a/.themes/classic/plugins/figure_tag.rb b/.themes/classic/plugins/figure_tag.rb new file mode 100644 index 0000000..550e677 --- /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
with an optional
and class names. +# +# Syntax {% figure [class name(s)] url [caption text] %} +# +# Example: +# {% figure left half http://site.com/images/ninja.png Ninja Attack! %} +# +# Output: +#
Ninja Attack!
+# +# Example 2 (image with caption) +# {% figure /images/ninja.png Ninja Attack! %} +# +# Output: +#
Ninja Attack!
+# +# Example 3 (just an image with classes) +# {% figure right /images/ninja.png %} +# +# Output: +#
+# + +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 += "" + figure += "
#{@caption}
" if @caption + 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)