From aed317d92b96102ab676fbf5147b35fb6b61845a Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Sun, 12 Feb 2012 17:00:36 -0600 Subject: [PATCH] added puts plugin for easily logging from liquid templates to the terminal --- plugins/puts.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 plugins/puts.rb diff --git a/plugins/puts.rb b/plugins/puts.rb new file mode 100644 index 0000000..a8013ac --- /dev/null +++ b/plugins/puts.rb @@ -0,0 +1,32 @@ +# Title: Puts Tag for Jekyll +# Author: Brandon Mathis http://brandonmathis.com +# Description: Puts is a liquid tag block which outputs its contents to the terminal +# +# Example Usage: +# Lets say you've assigned some variable you need to test. +# {% assign noun = "toaster" %} +# +# Drop it in a puts block along with a way to identify it in the output. +# {% puts %} +# Look out he's got a {{ noun }}. +# {% endputs %} +# +# Outputs: +# >>> {% puts %} <<< +# Look out he's got a toaster. +# + +module Jekyll + class Puts < Liquid::Block + def initialize(tag_name, markup, tokens) + super + end + + def render(context) + puts ">>> {% puts %} <<<" + puts super.map(&:strip).join + end + end +end + +Liquid::Template.register_tag('puts', Jekyll::Puts)