From c61c2b725efb80ed2ce9760b668e8db400dcd254 Mon Sep 17 00:00:00 2001 From: RichMorin Date: Thu, 12 Aug 2010 13:45:54 -0700 Subject: [PATCH] Migrated from liquid-for-programmers v10 --- Liquid-for-Programmers.textile | 36 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Liquid-for-Programmers.textile b/Liquid-for-Programmers.textile index 493c5ac..38eae97 100644 --- a/Liquid-for-Programmers.textile +++ b/Liquid-for-Programmers.textile @@ -4,10 +4,10 @@ It's very simple to get started with Liquid. A Liquid template is rendered in two steps: Parse and Render. For an overview of the Liquid syntax, please read [[Liquid for Designers]]. -

+
   @template = Liquid::Template.parse("hi {{name}}")  # Parses and compiles the template
   @template.render( 'name' => 'tobi' )               # Renders the output => "hi tobi" 
-
+
The @parse@ step creates a fully compiled template which can be re-used as often as you like. You can store it in memory or in a cache for faster rendering later. @@ -28,22 +28,22 @@ Basically, they are just methods which take one parameter and return a modified 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({}, :filters => [TextFilter])              # => "hi" 
-
+
Alternatively, you can register your filters globally: -

+
 module TextFilter
   def textilize(input)
     RedCloth.new(input).to_html
@@ -51,20 +51,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 tags To create a new tag, simply inherit from @Liquid::Tag@ and register your block with @Liquid::Template@. -

+
   class Random < Liquid::Tag                                             
     def initialize(tag_name, max, tokens)
        super 
@@ -77,12 +77,12 @@ To create a new tag, simply inherit from @Liquid::Tag@ and register your block w
   end
 
 Liquid::Template.register_tag('random', Random)
-
+
-

+
 @template = Liquid::Template.parse(" {% random 5 %}")
 @template.render    # => "3"
-
+
h3. Create your own tag blocks @@ -90,7 +90,7 @@ 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(tag_name, markup, tokens)
        super 
@@ -107,10 +107,10 @@ you just have to inherit from @Liquid::Block@ and register your block with @Liqu
   end
 
 Liquid::Template.register_tag('random', Random)
-
+
-

+
 text = " {% random 5 %} wanna hear a joke? {% endrandom %} "
 @template = Liquid::Template.parse(text)
 @template.render  # => In 20% of the cases, this will output "wanna hear a joke?"
-
\ No newline at end of file +
\ No newline at end of file