Commits

Brian Mearns committed 74bd410

Added a reST include template to replace the html one.

Comments (0)

Files changed (3)

templ/README.templ

     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 html.itmpl}{
+}{include rest.itmpl}{
 }{v
     {$ EXAMPLE-TEMPLATE {lambda
         {' :SYNTAX :INTRO :OUTRO :TEMPLATE }
             }
         >>> }
     }}
-}{html "templ - Template Processing Language"
-%Head content
-<<<
-    <style type='text/css'>
-    /* <![CDATA[ */
-
-        pre {ocb}
-            border: 1px dashed;
-            width: 80em;
-            font-family: monospace;
-            background-color: #FFC;
-            padding: 0.5em;
-        {ccb}
-
-    /* ]]> */
-    </style>
->>>
+}{reST "templ - Template Processing Language"
 
 %Body content
 {'
 
     {section "Introduction" {'
 
-        {p <<<
-{code {b templ}} is the {b Tem}plate {b P}rocessing {b L}anguage.
->>>
+        {p 
+<<<{b templ} is the {b Tem}plate {b P}rocessing {b L}anguage. >>>
         }
         
-        {p <<<
-{code templ} is a (Turing complete) programming language, used for content generation
+        {p
+<<<{code templ} is a (Turing complete) programming language, used for content generation
 from text-based template files and a simple but powerful processing language
-({code templ} itself) which is embedded directly in the template file.
->>>
+({code templ} itself) which is embedded directly in the template file. >>>
         }
         
-        {p <<<
-{code templ} can be used for:
-            {ul {'
+        {p <<<{code templ} can be used for: {ul {'
     "Code generation."
     "Form letters."
     "Server-side scripting for web servers."
     "Customized markup with variant output formats."
     "Any other kind of dynamic text-based content generation."
-            }}
->>>     
+            }}>>>     
         }
 
 
         {section "Contact Information" {'
 
-            {p <<<
-This project is currently hosted on {link bitbucket "https://bitbucket.org"}, 
+            {p <<<This project is currently hosted on {link bitbucket "https://bitbucket.org"}, 
 at {link "https://bitbucket.org/bmearns/templ/"}. The primary author is Brian Mearns:
-you can contact Brian through bitbucket at {link "https://bitbucket.org/bmearns"}.
->>>
+you can contact Brian through bitbucket at {link "https://bitbucket.org/bmearns"}. >>>
             }
 
         }}
 
         {section "Copyright and License" {'
 
-            {p <<<
-{code templ} is {em "free software"}: you can redistribute it and/or modify
+            {p <<<{code templ} is {em "free software"}: you can redistribute it and/or modify
 it under the terms of the {b 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.
-            >>> }
+(at your option) any later version. >>> }
 
-            {p <<<
-{code templ} is distributed in the hope that it will be useful,
+            {p <<<{code templ} is distributed in the hope that it will be useful,
 but {b without any warranty}; without even the implied warranty of
 {em merchantability} or {em fitness for a particular purpose}.  See the
-GNU Affero General Public License for more details.
-            >>> }
+GNU Affero General Public License for more details. >>> }
 
-            {p <<<
-A copy of the GNU Affero General Public License is available in the templ
+            {p <<<A copy of the GNU Affero General Public License is available in the templ
 distribution under the file LICENSE.txt. If you did not receive a copy of
-this file, see {link "http://www.gnu.org/licenses/"}.
-            >>> }
+this file, see {link "http://www.gnu.org/licenses/"}. >>> }
         }}
 
 
 
     {section "Examples" {'
 
-        {p <<<
-The following show some simple example templates and they're output, to give
-an idea of what can be done with templ.
-        >>> }
+        {p
+    <<<The following show some simple example templates and they're output, to give
+an idea of what can be done with templ.>>>
+        }
 
 
         {section "Templ Basics"
             <<< {EXAMPLE-TEMPLATE
                 "text"
-                {implode <<<
-                    The following template shows some of the basic elements of {code templ} templates:
-                >>>}
+                {implode <<<The following template shows some of the basic elements of {code templ} templates:>>>}
                 "The output looks like this:"
-                "Hello, World!
+"Hello, World!
 My Name is {set :NAME \"templ\"}. I am the TEMplate Processing Language.
 Sometimes, {$ :NAME} likes to speak in the third person.
 
     {join \":\" {$ :T} {:MY-FUNC {$ :T}}}
 }}}
 "
-        } >>> } % end section "Basics"
+        }
+        
+>>> } % end section "Basics"
 
         {section "Code Generation - A Sine Lookup Table"
             <<< {EXAMPLE-TEMPLATE
                     to generate C-code, in this case a sine lookup table.>>>
                 }
                 "The output looks like this:"
-                "{v
+"{v
     {set :SIZE 10}
 }const double sine_lut[{get :SIZE}] =
 \\{
         {lnbrk}
     }}
 }}\\};
-"
-            } >>>
-        } % end section "Code Generation..."
+" }
+
+>>> } % end section "Code Generation..."
 
 
         {section "Embedded Data"
     {$ :AGE {floor {div {- {$ :NOW} {$ :STAMP}} {* 60 60 24 365.25}}}}
     {echo {@ 0 {$ :ROW}} \", age \" {$ :AGE} \" years.\" {\\n} }
 }}"
-    } >>>
-        } % end section "Embedded Data"
+    }
+    
+>>> } % end section "Embedded Data"
 
 
         {section "Programmatic Invocation"
     {poe {::
 
         %Now define our Local Executables as elements of the list.
-        % we don't want these expressions evaluated when this macro
-        % gets called, so we wrap it up in vota, which returns the
-        % parsed and built but unprocessed expression.
         {set em {macro
             "Generates emphasized text."
             {' }
+{#
+    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/>.
+}{
+}{v {:
+
+{$ reST {macro
+    "Wraps content in reStructured text"
+
+    {' :pageTitle :contentList }
+    
+    %We're building up an expression that will be evaluated.
+    % That expression will be a List, so we're building a list.
+    %First thing in the list is the tag. In this case, we start
+    % by defining a new scope to put our local functions in.
+    {poe {::
+
+        %Now define our Local Executables as elements of the list.
+        {set em {macro
+            "Generates emphasized text."
+            {' :text }
+            {poe {wrap "\\ " {wrap * {implode " " {ete {esc-list {$ :argv }}}} }}}
+        }}
+
+        {set code {macro
+            "Generates text formatted to look like an inline code snippet."
+            {' :text }
+            {poe {wrap "\\ " {wrap `` {implode " " {ete {esc-list {$ :argv }}}} }}}
+        }}
+
+        {set b {macro
+            "Generates bold text."
+            {' :text }
+            {poe {wrap "\\ " {wrap ** {implode " " {ete {esc-list {$ :argv }}}} }}}
+        }}
+
+        {set p {macro
+            {' :textList }
+            {poe {wrap {glue {\n} {\n}} {implode "" {ete {$ :textList }}} }}
+        }}
+
+        {set ul {macro
+            {' :list }
+            {poe
+                {glue {\n} {\n}
+                    {implode {\n}
+                        {gen
+                            :item {ete {$ :list }}
+                            {glue "- " {strrep {\n} " " {$ :item}}}
+                        }
+                    }
+                }
+            }
+        }}
+
+        {set pre {lambda
+            {::
+                {let :options :content :class}
+                {$ :options {nil}}
+                {$ :content ""}
+
+                {if
+                    {== 1 {len {$ :argv}}} {:
+                        {$ :content {@ 0 {$ :argv}}}
+                    }
+
+                    {== 2 {len {$ :argv}}} {:
+                        {$ :options {@ 0 {$ :argv}}}
+                        {$ :content {@ 1 {$ :argv}}}
+
+                        %Check and parse options.
+                        {if                         
+                            {not {is-list {$ :options}}}
+                            {error "Invalid options, expected a list."}
+                        }
+                    }
+
+                    %else
+                    {error {glue "Incorrect number of arguments to pre: expected one or two, not " {len {$ :argv}}}}
+                }
+
+                {if
+                    {not {is-str {$ :content}}}
+                    {error {glue "Invalid content, expected a String, not a " {type {$ :content}}}}
+                }
+
+
+                {glue {\n} {\n} "::" {\n} {\n} "    " {strrep {\n} {glue {\n} "    "} {$ :content}}}
+            }
+        }}
+
+        {set link {macro
+            {if 
+                {== 1 {len {$ :argv}}} {poe {::
+                    {$ :href {ete {@ 0 {$ :argv}}}}
+                    {glue "`" {$ :href} " <" {$ :href} ">`_" }
+                }}
+
+                {== 2 {len {$ :argv}}} {poe {::
+                    {$ :text {ete {@ 0 {$ :argv}}}}
+                    {$ :href {ete {@ 1 {$ :argv}}}}
+                    {glue "`" {$ :text} " <" {$ :href} ">`_" }
+                }}
+
+                {error
+                    "Incorrect number of arguments for link. Expected exactly 1 or 2."
+                }
+            }
+        }}
+
+        {$ :rest-sect-lines {' = - ~ ` : ' "\"" ~ ^ _ * + # < > }}
+        {$ :rest-depth 0}
+        {$ :rest-section-number {' 0 }}
+        {$ :rest-sections {' }}
+
+        {set section {macro
+            {' :title :bodylist}
+            {:
+                %Increment the section number
+                {$ :rest-section-number
+                    {append 
+                        {+ 1 {@ -1 {$ :rest-section-number }}}
+                        {slice 0 -1 {$ :rest-section-number }}
+                    }
+                }
+
+                {$ :rest-sections {append {' {$ :rest-section-number} {$ :title}} {$ :rest-sections} }}
+
+                {$ :new-rest-section-number
+                    {append 0 {$ :rest-section-number }}
+                }
+
+                %The macro-subst.
+                {poe {::
+                    % Now copy the rest values into this new scope, and adjust appropriately.
+                    {let :rest-depth :rest-section-number }
+                    {$ :rest-depth {ete {+ 1 {$ :rest-depth}}}}
+                    {$ :rest-section-number {ete {insert ' {$ :new-rest-section-number }}}}
+
+                    {let :title-line}
+                    {$ :title-line {glue {ete {implode "." {$ :rest-section-number}}} ": " {ete {$ :title}}}}
+
+                    %FIXME: Check the depth.
+                    {let :line-char :line }
+                    {$ :line-char {@ {$ :rest-depth} {$ :rest-sect-lines}}}
+                    {$ :line {implode {gen i {range {strlen {$ :title-line}}} {$ :line-char}}}}
+
+
+                    {glue
+                        {$ :title-line}
+                        {\n}
+                        {$ :line}
+                        {implode "" {ete {$ :bodylist}} }
+                    }
+                }}
+            }
+        }}
+
+        %Evaluate this now, so we get all the sections and stuff. Generate macro
+        % subst to assign it (evaluated) to :htmlBodyContent.
+        {$ :bodyContent {implode {ete {$ :contentList}}}}
+
+        {glue 
+            {$ :bodyContent }
+        }
+
+        %end reST macro body.
+    }}
+
+}}}}