From 9bd572ffdc907301691e5ff5a62d68ecfa883229 Mon Sep 17 00:00:00 2001 From: Frederic Hemberger Date: Mon, 26 Sep 2011 11:51:44 +0200 Subject: Adds jsFiddle plugin --- plugins/jsfiddle.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 plugins/jsfiddle.rb (limited to 'plugins/jsfiddle.rb') 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: +# +# Input: {% jsfiddle ccWP7 js,html,result %} +# Output: +# + +module Jekyll + class JsFiddle < Liquid::Tag + def initialize(tag_name, markup, tokens) + if /(?\w+)(?:\s+(?[\w,]+))?(?:\s+(?\w+))?(?:\s+(?\w+))?(?:\s+(?\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 + "" + 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 -- cgit v1.2.1