summaryrefslogtreecommitdiff
path: root/doc/build/usage.rst
diff options
context:
space:
mode:
authorVincent Férotin <vincent.ferotin@gmail.com>2012-05-14 19:34:01 +0200
committerVincent Férotin <vincent.ferotin@gmail.com>2012-05-14 19:34:01 +0200
commitd8af6f5e00d57ab4f9bb6bc01947b137ac9a984a (patch)
tree360a97c36e1e75922583a395f43e0ee1809aead5 /doc/build/usage.rst
parent9262cac6a62a96e6bc8235a1ff95d4dde5820722 (diff)
downloadmako-d8af6f5e00d57ab4f9bb6bc01947b137ac9a984a.tar.gz
Fix some various typos in documentation:
fix misspelled words, remove line ending spaces, change ``-`` to ``--``, add some ``'`` between subject and 'to be' verb (e.g. "it's", "i'm"), add some ending dots to sentences, change some letters "capitalness", etc.
Diffstat (limited to 'doc/build/usage.rst')
-rw-r--r--doc/build/usage.rst112
1 files changed, 55 insertions, 57 deletions
diff --git a/doc/build/usage.rst b/doc/build/usage.rst
index 0aadacf..b4c5fee 100644
--- a/doc/build/usage.rst
+++ b/doc/build/usage.rst
@@ -16,10 +16,10 @@ The most basic way to create a template and render it is through
the :class:`.Template` class::
from mako.template import Template
-
+
mytemplate = Template("hello world!")
print mytemplate.render()
-
+
Above, the text argument to :class:`.Template` is **compiled** into a
Python module representation. This module contains a function
called ``render_body()``, which produces the output of the
@@ -35,10 +35,10 @@ sending them as additional keyword arguments to the :meth:`~.Template.render`
method::
from mako.template import Template
-
+
mytemplate = Template("hello, ${name}!")
print mytemplate.render(name="jack")
-
+
The :meth:`~.Template.render` method calls upon Mako to create a
:class:`.Context` object, which stores all the variable names accessible
to the template and also stores a buffer used to capture output.
@@ -48,7 +48,7 @@ render with it, using the :meth:`~.Template.render_context` method::
from mako.template import Template
from mako.runtime import Context
from StringIO import StringIO
-
+
mytemplate = Template("hello, ${name}!")
buf = StringIO()
ctx = Context(buf, name="jack")
@@ -62,10 +62,10 @@ A :class:`.Template` can also load its template source code from a file,
using the ``filename`` keyword argument::
from mako.template import Template
-
+
mytemplate = Template(filename='/docs/mytmpl.txt')
print mytemplate.render()
-
+
For improved performance, a :class:`.Template` which is loaded from a
file can also cache the source code to its generated module on
the filesystem as a regular Python module file (i.e. a .py
@@ -100,7 +100,7 @@ the :class:`.Template` objects it creates::
from mako.template import Template
from mako.lookup import TemplateLookup
-
+
mylookup = TemplateLookup(directories=['/docs'])
mytemplate = Template("""<%include file="header.txt"/> hello world!""", lookup=mylookup)
@@ -119,9 +119,9 @@ desired template::
from mako.template import Template
from mako.lookup import TemplateLookup
-
+
mylookup = TemplateLookup(directories=['/docs'], module_directory='/tmp/mako_modules')
-
+
def serve_template(templatename, **kwargs):
mytemplate = mylookup.get_template(templatename)
print mytemplate.render(**kwargs)
@@ -136,8 +136,8 @@ its search directories; so if you gave it a URI of
exception, which is a custom Mako exception.
When the lookup locates templates, it will also assign a ``uri``
-property to the :class:`.Template` which is the uri passed to the
-:meth:`~.TemplateLookup.get_template()` call. :class:`.Template` uses this uri to calculate the
+property to the :class:`.Template` which is the URI passed to the
+:meth:`~.TemplateLookup.get_template()` call. :class:`.Template` uses this URI to calculate the
name of its module file. So in the above example, a
``templatename`` argument of ``/etc/beans/info.txt`` will create a
module file ``/tmp/mako_modules/etc/beans/info.txt.py``.
@@ -147,14 +147,14 @@ Setting the Collection Size
The :class:`.TemplateLookup` also serves the important need of caching a
fixed set of templates in memory at a given time, so that
-successive uri lookups do not result in full template
+successive URI lookups do not result in full template
compilations and/or module reloads on each request. By default,
the :class:`.TemplateLookup` size is unbounded. You can specify a fixed
size using the ``collection_size`` argument::
- mylookup = TemplateLookup(directories=['/docs'],
+ mylookup = TemplateLookup(directories=['/docs'],
module_directory='/tmp/mako_modules', collection_size=500)
-
+
The above lookup will continue to load templates into memory
until it reaches a count of around 500. At that point, it will
clean out a certain percentage of templates using a least
@@ -184,9 +184,9 @@ output in any Python supported codec::
from mako.template import Template
from mako.lookup import TemplateLookup
-
+
mylookup = TemplateLookup(directories=['/docs'], output_encoding='utf-8', encoding_errors='replace')
-
+
mytemplate = mylookup.get_template("foo.txt")
print mytemplate.render()
@@ -199,12 +199,12 @@ return the template output as a Python ``unicode`` object, or in
Python 3 a ``string``::
print mytemplate.render_unicode()
-
+
The above method disregards the output encoding keyword
argument; you can encode yourself by saying::
print mytemplate.render_unicode().encode('utf-8', 'replace')
-
+
Note that Mako's ability to return data in any encoding and/or
``unicode`` implies that the underlying output stream of the
template is a Python unicode object. This behavior is described
@@ -237,13 +237,13 @@ To format exception traces, the :func:`.text_error_template` and
Usage of these handlers usually looks like::
from mako import exceptions
-
+
try:
template = lookup.get_template(uri)
print template.render()
except:
print exceptions.text_error_template().render()
-
+
Or for the HTML render function::
from mako import exceptions
@@ -271,7 +271,7 @@ will result in the output being substituted with the output of
template = Template(filename="/foo/bar", format_exceptions=True)
print template.render()
-
+
Note that the compile stage of the above template occurs when
you construct the :class:`.Template` itself, and no output stream is
defined. Therefore exceptions which occur within the
@@ -279,7 +279,7 @@ lookup/parse/compile stage will not be handled and will
propagate normally. While the pre-render traceback usually will
not include any Mako-specific lines anyway, it will mean that
exceptions which occur previous to rendering and those which
-occur within rendering will be handled differently...so the
+occur within rendering will be handled differently... so the
try/except patterns described previously are probably of more
general use.
@@ -289,7 +289,7 @@ directly to provide custom error views. Here's an example usage
which describes its general API::
from mako.exceptions import RichTraceback
-
+
try:
template = lookup.get_template(uri)
print template.render()
@@ -299,24 +299,24 @@ which describes its general API::
print "File %s, line %s, in %s" % (filename, lineno, function)
print line, "\n"
print "%s: %s" % (str(traceback.error.__class__.__name__), traceback.error)
-
+
Common Framework Integrations
=============================
The Mako distribution includes a little bit of helper code for
the purpose of using Mako in some popular web framework
-scenarios. This is a brief description of whats included.
+scenarios. This is a brief description of what's included.
WSGI
----
-A sample WSGI application is included in the distrubution in the
+A sample WSGI application is included in the distribution in the
file ``examples/wsgi/run_wsgi.py``. This runner is set up to pull
files from a `templates` as well as an `htdocs` directory and
includes a rudimental two-file layout. The WSGI runner acts as a
fully functional standalone web server, using ``wsgiutils`` to run
itself, and propagates GET and POST arguments from the request
-into the :class:`.Context`, can serve images, css files and other kinds
+into the :class:`.Context`, can serve images, CSS files and other kinds
of files, and also displays errors using Mako's included
exception-handling utilities.
@@ -330,7 +330,7 @@ also contains various setuptools entry points under the heading
``pygments.lexers``, including ``mako``, ``html+mako``, ``xml+mako``
(see the ``setup.py`` file for all the entry points).
-Babel
+Babel
------
Mako provides support for extracting gettext messages from
@@ -382,7 +382,7 @@ command line in the project's root directory::
myproj$ pybabel extract -F babel.cfg -c "TRANSLATORS:" .
-Will output a gettext catalog to stdout including the following::
+will output a gettext catalog to stdout including the following::
#. TRANSLATORS: This is a proper name. See the gettext
#. manual, section Names.
@@ -438,47 +438,45 @@ API Reference
:show-inheritance:
.. py:attribute:: error
-
+
the exception instance.
.. py:attribute:: message
-
- the exception error message as unicode
-
+
+ the exception error message as unicode.
+
.. py:attribute:: source
-
- source code of the file where the error occured.
- if the error occured within a compiled template,
+
+ source code of the file where the error occurred.
+ If the error occurred within a compiled template,
this is the template source.
-
+
.. py:attribute:: lineno
-
- line number where the error occured. if the error
- occured within a compiled template, the line number
- is adjusted to that of the template source
-
+
+ line number where the error occurred. If the error
+ occurred within a compiled template, the line number
+ is adjusted to that of the template source.
+
.. py:attribute:: records
-
- a list of 8-tuples containing the original
- python traceback elements, plus the
- filename, line number, source line, and full template source
+
+ a list of 8-tuples containing the original
+ python traceback elements, plus the
+ filename, line number, source line, and full template source
for the traceline mapped back to its originating source
template, if any for that traceline (else the fields are None).
-
+
.. py:attribute:: reverse_records
-
+
the list of records in reverse
- traceback - a list of 4-tuples, in the same format as a regular
- python traceback, with template-corresponding
- traceback records replacing the originals
-
+ traceback -- a list of 4-tuples, in the same format as a regular
+ python traceback, with template-corresponding
+ traceback records replacing the originals.
+
.. py:attribute:: reverse_traceback
-
- the traceback list in reverse
+
+ the traceback list in reverse.
.. autofunction:: mako.exceptions.html_error_template
.. autofunction:: mako.exceptions.text_error_template
-
-