Commits

Brian Mearns committed bf654a6

Finally got rid of stupid old_functions.

  • Participants
  • Parent commits fdaf928

Comments (0)

Files changed (4)

File templ/old_functions.py

-"""
-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/>.
-"""
-from ttypes import *
-from filepos import *
-from exceptions import *
-from stack import *
-import abc
-import collections
-import math
-import os
-
-
-
-
-@macro
-class CarriageRetMacro(TMacro):
-   """
-   {car-ret}
-   Expands to {esc r}.
-   """
-   __mnemonics__ = ("car-ret", "cr", "\\r")
-   def execute(self, name, args, ostream, stack):
-       if len(args) != 0:
-           raise Exception("Incorrect number of arguments for macro \"%s\": does not accept any arguments." % (name))
-       return List(["esc", "r"])
-
-@macro
-class BackspaceMacro(TMacro):
-   """
-   {backspace}
-   Expands to {esc b}.
-   """
-   __mnemonics__ = ("backspace", "\\b")
-   def execute(self, name, args, ostream, stack):
-       if len(args) != 0:
-           raise Exception("Incorrect number of arguments for macro \"%s\": does not accept any arguments." % (name))
-       return List(["esc", "b"])
-
-@macro
-class FormfeedMacro(TMacro):
-   """
-   {formfeed}
-   Expands to {esc f}.
-   """
-   __mnemonics__ = ("formfeed", "\\f")
-   def execute(self, name, args, ostream, stack):
-       if len(args) != 0:
-           raise Exception("Incorrect number of arguments for macro \"%s\": does not accept any arguments." % (name))
-       return List(["esc", "f"])
-
-@macro
-class VertTabMacro(TMacro):
-   """
-   {vert-tab}
-   Expands to {esc v}.
-   """
-   __mnemonics__ = ("vert-tab", "\\v")
-   def execute(self, name, args, ostream, stack):
-       if len(args) != 0:
-           raise Exception("Incorrect number of arguments for macro \"%s\": does not accept any arguments." % (name))
-       return List(["esc", "v"])
-
-@macro
-class TabMacro(TMacro):
-   """
-   {tab}
-   Expands to {esc t}.
-   """
-   __mnemonics__ = ("tab", "\\t")
-   def execute(self, name, args, ostream, stack):
-       if len(args) != 0:
-           raise Exception("Incorrect number of arguments for macro \"%s\": does not accept any arguments." % (name))
-       return List(["esc", "t"])
-
-@macro
-class AlertMacro(TMacro):
-   """
-   {alert}
-   Expands to {esc a}.
-   """
-   __mnemonics__ = ("alert", "\\a")
-   def execute(self, name, args, ostream, stack):
-       if len(args) != 0:
-           raise Exception("Incorrect number of arguments for macro \"%s\": does not accept any arguments." % (name))
-       return List(["esc", "a"])
-
-@macro
-class QuoteMacro(TMacro):
-   """
-   {quote}
-   Expands to a String consisting of one double-quote character.
-   """
-   __mnemonics__ = ("quote", "''",)
-   def execute(self, name, args, ostream, stack):
-       if len(args) != 0:
-           raise Exception("Incorrect number of arguments for macro \"%s\": does not accept any arguments." % (name))
-       return String('"')
-
-

File templ/tbuiltin.py

             w, a, s = args
         return ttypes.List(["join", "", w, s, a])
 
-
+@texec.macro
+class xQuote(texec.TMacro):
+   """
+   {quote STR}
+   Puts double-quotes around the given string, expands as a macro to {wrap "\\"" STR}.
+   This does NOT escape quote characters that may already be inside STR.
+   """
+   __mnemonics__ = ("quote", "''",)
+   def execute(self, name, args, ostream, stack):
+       self.checkArgCount(name, args, exact=[1,])
+       return ttypes.List(["wrap", "\"", args[0]])
+
+

File templ/test.templ

-{echo foo{bar }
+{quote "foo\"bar"}

File templ/tutorial.templ

 on the same line as the opening curly brace, generally with no space separating it from the brace. This makes it much
 more obvious what is being invoked.>>>
                     }
+
+                    {implode
+<<<Indent all subsequent elements of the list relative to the opening brace. This helps establish sematic scope for the reader.>>>
+                    }
+
+                    {implode
+<<<Don't ever use tabs, use spaces. Tabstops may be set differently by different users and in different editors, so things that are
+nicely aligned with tabs in one circumstance may look horrendous in another. The standard indentation level is 4 spaces. Three is
+also acceptable but kind of weird. Two in somewhat common, and econimical, but is not as visually helpful as a larger indent. More
+than 4 is excessive and will quickly lead to lines that don't have available width. If you want to use tabs because you can't handle
+the extra couple of backspaces, either stop being lazy or get a better editor.>>>
+                    }
+
+                    {implode
+<<<Put the closing brace on a new line, aligned in the same column as the opening brace. This make it obvious where
+the List ends, and therefore what is included in it.>>>
+                    }
+
                 }}
             }}