Commits

Brian Mearns committed 2002f76

More work on readme, added function for processing example templates.

Comments (0)

Files changed (2)

templ/README.templ

     See the end of this file for additional copyright and license information.
 }{
 }{include html.itmpl}{
+}{v
+    {$ EXAMPLE-TEMPLATE {lambda
+        {' :SYNTAX :INTRO :OUTRO :TEMPLATE }
+        {implode <<<
+            {p {' {$ :INTRO}}}
+            {pre
+                {' :syntax templ}
+                {$ :TEMPLATE}
+            }
+
+            {p {' {$ :OUTRO}}}
+            {pre
+                {' :syntax {$ :SYNTAX}}
+                {buffer {eval {$ :TEMPLATE}}}
+            }
+        >>> }
+    }}
 }{html "templ - Template Processing Language"
 %Head content
 <<<
         >>> }
 
 
-        {section "Templ Basics" <<<
-
-{p <<<
-    The following template shows some of the basic elements of {code templ} templates:
-    >>>}
-{pre {' :syntax templ } "
-Hello, World!
+        {section "Templ Basics"
+            <<< {EXAMPLE-TEMPLATE
+                "text"
+                {implode <<<
+                    The following template shows some of the basic elements of {code templ} templates:
+                >>>}
+                "The output looks like this:"
+                "Hello, World!
 My Name is {set :NAME \"templ\"}. I am the TEMplate Processing Language.
 Sometimes, {$ :NAME} likes to speak in the third person.
 
 
 {$ :NAME} can loop (and do trig):
 {for :THETA {range 0 40 10} {
-    echo \"    sin(\" {$ :THETA} \") = \" {sin {rad {$ :THETA}}} {\n}}
+    echo \"    sin(\" {$ :THETA} \") = \" {sin {rad {$ :THETA}}} {\\n}}
 }
 
 {$ :NAME} can even do list comprehensions and user defined functions:
             {let :RADS}
             {$ :RADS {rad {$ :THETA}}}
 
-            {echo \"Processing theta=\" {$ :THETA} \"...\" {\n}}
+            {echo \"Processing theta=\" {$ :THETA} \"...\" {\\n}}
 
             %return value
             {+ {cos {$ :RADS}} {sin {$ :RADS}} }
         }
     }
-}}{wrap \"{\" \"}\" {implode {glue \",\" {\n} \"    \"} {gen
+}}{wrap \"{\" \"}\" {implode {glue \",\" {\\n} \"    \"} {gen
     :T
     {range 40 80 10}
     {join \":\" {$ :T} {:MY-FUNC {$ :T}}}
 }}}
-" }
+"
+        } >>> } % end section "Basics"
 
-{p <<<
-    The output looks like this:
-    >>>}
-{pre "
-Hello, World!
-My Name is templ. I am the TEMplate Processing Language.
-Sometimes, templ likes to speak in the third person.
-
-templ can do math:
-    1 + 1 = 2
-    1 + 2 = 3
-    2 + 3 = 5
-    3 + 5 = 8
-    etc...
-
-templ can operate on strings and lists:
-    bananas
-    [a, b, c, d, e, f]
-
-templ can do conditional processing:
-    Phew!
-
-templ can loop (and do trig):
-    sin(0) = 0.0
-    sin(10) = 0.173648177667
-    sin(20) = 0.342020143326
-    sin(30) = 0.5
-
-
-templ can even do list comprehensions and user defined functions:
-Processing theta=40...
-Processing theta=50...
-Processing theta=60...
-Processing theta=70...
-{40:1.40883205281,
-    50:1.40883205281,
-    60:1.36602540378,
-    70:1.28171276411}"
-}
-        >>> } % end section "Basics"
-
-        {section "Code Generation - A Sine Lookup Table" {::
-
-
-            {let :TEMPLATE}
-            {$ :TEMPLATE "
-{v
+        {section "Code Generation - A Sine Lookup Table"
+            <<< {EXAMPLE-TEMPLATE
+                c
+                {implode
+                    <<<The following template shows an example of how to use {code templ}
+                    to generate C-code, in this case a sine lookup table.>>>
+                }
+                "The output looks like this:"
+                "{v
     {set :SIZE 10}
 }const double sine_lut[{get :SIZE}] =
 \\{
     }}
 }}\\};
 "
-            }
-            
-        <<<
-            {p
-                <<<
-                The following template shows an example of using {code templ} to
-                generate a C-code sine look-up-table:
-                >>>
-            }
-            {pre {' :syntax templ } {$ :TEMPLATE}}
-
-            {p
-                <<<
-                Which produces this:
-                >>>
-            }
-            {pre {' :syntax c } {buffer {eval {$ :TEMPLATE}}}}
-
-        >>> }} % end section "Code Generation..."
+            } >>>
+        } % end section "Code Generation..."
 
     }} %end section Examples
 
             elements.append(ttypes.List(embedded, embeddedStart))            
 
         elif token == TOKEN_CEMBED:
-            raise Exception("Unexpected >>> in expression. This is a reserved token inside expressions, to use it as a string, it must be quoted.")
+            raise TemplateSyntaxError("Input >>> in expression. This is a reserved token inside expressions, to use it as a string, it must be quoted.", myfilepos)
 
         elif token == TOKEN_CCUR:
             #End of expression.