aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorBrandon Mathis <brandon@imathis.com>2011-09-28 14:51:24 -0500
committerBrandon Mathis <brandon@imathis.com>2011-09-28 14:51:24 -0500
commit3bd4ed026eab04b5c560ca85317c982ab0679369 (patch)
tree652b5d0663331f1561b4d98f98ab5654366a78ed /plugins
parent3ad7715901414e9bdb7fb150cb4074f1bfa8c74c (diff)
parent9cf956cc96d0a337562a46bb1e695c4da31c88c4 (diff)
downloadmy_new_personal_website-3bd4ed026eab04b5c560ca85317c982ab0679369.tar.xz
my_new_personal_website-3bd4ed026eab04b5c560ca85317c982ab0679369.zip
Merge branch 'master' of github.com:imathis/octopress into compass
Diffstat (limited to '')
-rw-r--r--plugins/image_tag.rb45
-rw-r--r--plugins/jsfiddle.rb40
2 files changed, 63 insertions, 22 deletions
diff --git a/plugins/image_tag.rb b/plugins/image_tag.rb
index 25a38df5..45670007 100644
--- a/plugins/image_tag.rb
+++ b/plugins/image_tag.rb
@@ -1,46 +1,47 @@
# Title: Simple Image tag for Jekyll
-# Author: Brandon Mathis http://brandonmathis.com
-# Description: Easily output images with optional class names and title/alt attributes
+# Authors: Brandon Mathis http://brandonmathis.com
+# Felix Schäfer, Frederic Hemberger
+# Description: Easily output images with optional class names, width, height, title and alt attributes
#
-# Syntax {% image [class name(s)] url [title text] %}
+# Syntax {% img [class name(s)] [http[s]:/]/path/to/image [width [height]] [title text | "title text" ["alt text"]] %}
#
-# Example:
-# {% ima left half http://site.com/images/ninja.png Ninja Attack! %}
+# Examples:
+# {% img /images/ninja.png Ninja Attack! %}
+# {% img left half http://site.com/images/ninja.png Ninja Attack! %}
+# {% img left half http://site.com/images/ninja.png 150 150 "Ninja Attack!" "Ninja in attack posture" %}
#
# Output:
-# <image class='left' src="http://site.com/images/ninja.png" title="Ninja Attack!" alt="Ninja Attack!">
+# <img src="/images/ninja.png">
+# <img class="left half" src="http://site.com/images/ninja.png" title="Ninja Attack!" alt="Ninja Attack!">
+# <img class="left half" src="http://site.com/images/ninja.png" width="150" height="150" title="Ninja Attack!" alt="Ninja in attack posture">
#
module Jekyll
class ImageTag < Liquid::Tag
@img = nil
- @title = nil
- @class = ''
- @width = ''
- @height = ''
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
+ attributes = ['class', 'src', 'width', 'height', 'title']
+
+ if markup =~ /(?<class>\S.*\s+)?(?<src>(?:https?:\/\/|\/|\S+\/)\S+)(?:\s+(?<width>\d+))?(?:\s+(?<height>\d+))?(?<title>\s+.+)?/i
+ @img = attributes.reduce({}) { |img, attr| img[attr] = $~[attr].strip if $~[attr]; img }
+ if /(?:"|')(?<title>[^"']+)?(?:"|')\s+(?:"|')(?<alt>[^"']+)?(?:"|')/ =~ @img['title']
+ @img['title'] = title
+ @img['alt'] = alt
+ else
+ @img['alt'] = @img['title'].gsub!(/"/, '&#34;') if @img['title']
end
+ @img['class'].gsub!(/"/, '') if @img['class']
end
super
end
def render(context)
- output = super
if @img
- "<img class='#{@class}' src='#{@img}' width='#{@width}' height='#{@height}' alt='#{@title}' title='#{@title}'>"
+ "<img #{@img.collect {|k,v| "#{k}=\"#{v}\"" if v}.join(" ")}>"
else
- "Error processing input, expected syntax: {% img [class name(s)] /url/to/image [width height] [title text] %}"
+ "Error processing input, expected syntax: {% img [class name(s)] [http[s]:/]/path/to/image [width [height]] [title text | \"title text\" [\"alt text\"]] %}"
end
end
end
diff --git a/plugins/jsfiddle.rb b/plugins/jsfiddle.rb
new file mode 100644
index 00000000..3ae173eb
--- /dev/null
+++ b/plugins/jsfiddle.rb
@@ -0,0 +1,40 @@
+# Title: jsFiddle tag for Jekyll
+# Author: Brian Arnold (@brianarn)
+# Description:
+# Given a jsFiddle shortcode, outputs the jsFiddle iframe code.
+# Using 'default' will preserve defaults as specified by jsFiddle.
+#
+# Syntax: {% jsfiddle shorttag [tabs] [skin] [height] [width] %}
+#
+# Examples:
+#
+# Input: {% jsfiddle ccWP7 %}
+# Output: <iframe style="width: 100%; height: 300px" src="http://jsfiddle.net/ccWP7/embedded/js,resources,html,css,result/light/"></iframe>
+#
+# Input: {% jsfiddle ccWP7 js,html,result %}
+# Output: <iframe style="width: 100%; height: 300px" src="http://jsfiddle.net/ccWP7/embedded/js,html,result/light/"></iframe>
+#
+
+module Jekyll
+ class JsFiddle < Liquid::Tag
+ def initialize(tag_name, markup, tokens)
+ if /(?<fiddle>\w+)(?:\s+(?<sequence>[\w,]+))?(?:\s+(?<skin>\w+))?(?:\s+(?<height>\w+))?(?:\s+(?<width>\w+))?/ =~ markup
+ @fiddle = fiddle
+ @sequence = (sequence unless sequence == 'default') || 'js,resources,html,css,result'
+ @skin = (skin unless skin == 'default') || 'light'
+ @width = width || '100%'
+ @height = height || '300px'
+ end
+ end
+
+ def render(context)
+ if @fiddle
+ "<iframe style=\"width: #{@width}; height: #{@height}\" src=\"http://jsfiddle.net/#{@fiddle}/embedded/#{@sequence}/#{@skin}/\"></iframe>"
+ else
+ "Error processing input, expected syntax: {% jsfiddle shorttag [tabs] [skin] [height] [width] %}"
+ end
+ end
+ end
+end
+
+Liquid::Template.register_tag('jsfiddle', Jekyll::JsFiddle) \ No newline at end of file