diff options
author | Brandon Mathis <brandon@imathis.com> | 2011-09-28 14:51:24 -0500 |
---|---|---|
committer | Brandon Mathis <brandon@imathis.com> | 2011-09-28 14:51:24 -0500 |
commit | 3bd4ed026eab04b5c560ca85317c982ab0679369 (patch) | |
tree | 652b5d0663331f1561b4d98f98ab5654366a78ed /plugins/jsfiddle.rb | |
parent | 3ad7715901414e9bdb7fb150cb4074f1bfa8c74c (diff) | |
parent | 9cf956cc96d0a337562a46bb1e695c4da31c88c4 (diff) | |
download | my_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 'plugins/jsfiddle.rb')
-rw-r--r-- | plugins/jsfiddle.rb | 40 |
1 files changed, 40 insertions, 0 deletions
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 |