Maytag Metalark avatar Maytag Metalark committed 4446552

Working on tutorial, and fixed the title for the rest.itempl.

Comments (0)

Files changed (3)

         % subst to assign it (evaluated) to :htmlBodyContent.
         {$ :bodyContent {implode {ete {$ :contentList}}}}
 
+        {$ :tline {implode {gen i {range {strlen {ete {$ :pageTitle}}}} "="}}}
+
         % FIXME: Add TOC
         % FIXME: Add copyright notice? Add a new "comment" macro, and then add the copyright as a comment, in the bodyContent when
         % invoking the reST macro.
         {glue 
+            {\n} {$ :tline} {\n} {ete {$ :pageTitle}} {\n} {$ :tline} {\n} {\n}
             {$ :bodyContent }
         }
 

templ/tutorial.css

+pre {
+    border: 1px dashed;
+}

templ/tutorial.templ

+{#
+    Copyright 2012 Brian Mearns
+
+    This file is part of templ.
+
+    templ is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    templ is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with templ.  If not, see <http://www.gnu.org/licenses/>.
+}{
+}{include rest.itmpl}{
+}{v {:
+    {$ EXAMPLE-TEMPLATE {lambda
+        {' :SYNTAX :INTRO :OUTRO :TEMPLATE }
+        {implode <<<
+            {p {' {$ :INTRO}}}
+            {pre
+                {' :syntax templ}
+                {$ :TEMPLATE}
+            }
+
+            {p {' {$ :OUTRO}}}
+            {pre
+                {' :syntax {$ :SYNTAX}}
+                {buffer {eval {$ :TEMPLATE}}}
+            }
+        >>> }
+    }}
+
+    {$ templ {macro {' code "templ" }}}
+
+}}{reST "templ - Basic Tutorial and Overview"
+
+%Body content
+{'
+
+    {section "Introduction" {'
+
+        {section "Overview" {'
+            {p 
+<<<{b templ} (pronounced just like "temple") is the {b Tem}plate {b P}rocessing {b L}anguage: it's used for processing template files
+in order to produce an output file. Template files are simply user supplied files that define how the output
+should be generated. Templates are usually just plain text, but binary content is also supported.>>>
+            }
+
+            {p 
+<<<In its simplest (and least useful) form, a template file simply contains the data that is desired for
+the output. However, what makes a a template file interesting, and what makes {templ} itself useful,
+is the use of embedded {templ} statements, which are evaluated by the {templ} processor in order
+to produce the output.>>>
+            }
+
+        }} % section "Overview"
+
+        {section "Template Files" {'
+
+            {p
+<<<At the top level, a {templ} template file consists of two types of elements: {em text} and {em statements}.
+Text is simply raw (more-or-less) content that will be written to the output stream. Statements are
+{templ} code that the processor will evaluate in order to determine the output, as well as its own
+behavior. What distinguishes a statement from text is that statements are wrapped in curly braces: "\{" and "\}".
+Anything that's not wrapped in curly braces is treated as text and is copied very nearly verbatim to the
+output (more on all of these qualifications later).>>>
+            }
+
+        }} % end section "Template Files"
+
+        {section "Hello, Templ!" {'
+
+            {EXAMPLE-TEMPLATE "text"
+                {implode 
+<<<This wouldn't be much a programming tutorial without the classic "hello world" program. So let's see
+how it looks in {templ}. Open a plain text file, and enter the contents below. Save the file as "hello.templ":>>>
+                }
+
+                {implode
+<<<Now you need to invoke the {templ} processor in order to process this template file and produce the output. To do so
+simply execute this command from the directory where your "hello.templ" file is saved: {code "templ hello.templ"}. The
+output will be written to the console. It should look like this:>>>
+                }
+
+                "hello, templ!"
+            }
+
+            {p
+<<<I apologize if you were thoroughly bored by that example, but it serves to illustrate that there is no special format
+for template files: other than explicit {templ} statements, it's all just content for the output stream. So if all you do
+is write some text in a file without any curly braces, all templ will do is copy it to the output.>>>
+            }
+
+            {EXAMPLE-TEMPLATE "text"
+
+                {implode
+<<<But that is really boring, so let's do something just slightly more interesting. This time, we'll actually introduce a
+{templ} statement. Edit your "hello.templ" file to look like this:>>>
+                }
+
+                {implode
+<<<The statement we added is the stuff between the curly braces: {code "{echo templ}"}. The output is shown below: it looks the same. 
+That's because the {code echo} function simply tells {templ} to write the given string to the output stream.>>>
+                }
+
+                "hello, {echo templ}!"
+            }
+
+            {p
+<<<Ok, still pretty boring, but at least now we're actually writing {templ} code. There's a couple important things to notice in
+this example. For one thing, the format for invoking a function may not be what you're used to in most other languages. {templ}
+uses a syntax known as "S-expressions", similar to Lisp, in which the function to be invoked is the first element in a list whic
+also contains the arguments to be passed to the function. The syntax is semantically the same as the more familiar "M-expressions"
+in which the function is outside of the list of arguments, but the different way of writing it is important for allowing template
+files to be less structured than what you would normally see in source code.>>>
+            }
+
+            {p
+<<<The other thing to notice from this example is that the string we passed to the {code echo} function isn't quoted in any way.>>>
+            }
+
+
+        }} % end section "Hello, ..."
+
+    }} %end section "Introduction"
+        
+}}{#
+
+
+ vim: set ft=templ:
+}
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.