From 392fb30cd07d65ed5b72dc6e01ed03a2b065a477 Mon Sep 17 00:00:00 2001 From: tobi Date: Thu, 12 Aug 2010 13:45:53 -0700 Subject: [PATCH] Migrated from liquid-for-programmers v3 --- Liquid-for-Programmers.textile | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Liquid-for-Programmers.textile b/Liquid-for-Programmers.textile index c810fec..55bc56d 100644 --- a/Liquid-for-Programmers.textile +++ b/Liquid-for-Programmers.textile @@ -20,16 +20,22 @@ h3. Create your own filters Creating filters is very easy. Basically they are just methods which take one parameter and return a modified string. You can use your own filters by passing an array of modules to the render call like this @template.render(assigns, [MyTextFilters, MyDateFilters]) +

 module TextFilter
   def textilize(input)
     RedCloth.new(input).to_html
   end
 end
+
+

 @template = Liquid::Template.parse(" {{ '*hi*' | textilize }} ")
-@template.render({}, [TextFilter])              # => "hi" 
+@template.render({}, :filters => [TextFilter])              # => "hi" 
+
+ Alternatively you can also register your filters globally +

 module TextFilter
   def textilize(input)
     RedCloth.new(input).to_html
@@ -37,14 +43,20 @@ module TextFilter
 end
 
 Liquid::Template.register_filter(TextFilter)
+
+Once the filter is globally registered you can simply use it: + +

 @template = Liquid::Template.parse(" {{ '*hi*' | textilize }} ")
 @template.render              # => "hi" 
+
h3. Create your own tag blocks All tag blocks are parsed by liquid. To create a new block you just have to inherit from Liquid::Block and register your block with Liquid::Template +

   class Random < Liquid::Block                                             
     def initialize(markup, tokens)
        super 
@@ -61,6 +73,9 @@ All tag blocks are parsed by liquid. To create a new block you just have to inhe
   end
 
 Liquid::Template.register_tag('random', Random)
+
+

 @template = Liquid::Template.parse(" {% random 5 %} wanna hear a joke? {% endrandom %} ")
 @template.render              # => in 20% of the cases this will output : wanna hear a joke?
+