summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2017-11-02 11:28:46 -0500
committerJason Madden <jamadden@gmail.com>2017-11-02 11:28:46 -0500
commita8bb76bc054662905d106a1a716538a00ef911b7 (patch)
treee594aa5d63ae93feda69a4113f24c71b25254d80
parent0aa5944a718040a77174857521ab70e5b566a4e8 (diff)
downloadzope-pagetemplate-a8bb76bc054662905d106a1a716538a00ef911b7.tar.gz
Build documents with Sphinx for RTD
Fixes #8 Run doctests with Sphinx on all versions as well.
-rw-r--r--.travis.yml5
-rw-r--r--CHANGES.rst2
-rw-r--r--MANIFEST.in6
-rw-r--r--README.rst19
-rw-r--r--doc-requirements.txt1
-rw-r--r--docs/Makefile177
-rw-r--r--docs/architecture.rst (renamed from src/zope/pagetemplate/architecture.txt)26
-rw-r--r--docs/changelog.rst1
-rw-r--r--docs/conf.py278
-rw-r--r--docs/engine.rst5
-rw-r--r--docs/hello_world.pt1
-rw-r--r--docs/index.rst30
-rw-r--r--docs/interfaces.rst5
-rw-r--r--docs/make.bat242
-rw-r--r--docs/pagetemplate.rst7
-rw-r--r--docs/using.rst78
-rw-r--r--setup.py14
-rw-r--r--src/zope/pagetemplate/engine.py19
-rw-r--r--src/zope/pagetemplate/interfaces.py61
-rw-r--r--src/zope/pagetemplate/pagetemplate.py23
-rw-r--r--src/zope/pagetemplate/readme.txt53
-rw-r--r--tox.ini13
22 files changed, 939 insertions, 127 deletions
diff --git a/.travis.yml b/.travis.yml
index f44d718..e770bda 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,13 +6,14 @@ python:
- 3.5
- 3.6
- pypy
- - pypy3.5-5.8.0
+ - pypy3
install:
- pip install -U pip setuptools
- pip install -U coverage coveralls
- - pip install -U -e .[test]
+ - pip install -U -e .[test,docs]
script:
- coverage run -m zope.testrunner --test-path=src
+ - coverage run -a -m sphinx -b doctest -d docs/_build/doctrees docs docs/_build/doctest
after_success:
- coveralls
notifications:
diff --git a/CHANGES.rst b/CHANGES.rst
index ad4a9d9..c53231e 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -5,7 +5,7 @@
4.3.1 (unreleased)
==================
-- Nothing changed yet.
+- Host documentation at https://zopepagetemplate.readthedocs.io/
4.3.0 (2017-09-04)
diff --git a/MANIFEST.in b/MANIFEST.in
index 931b611..0fde81c 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -7,3 +7,9 @@ include .travis.yml
include .coveragerc
recursive-include src *.txt *.html *.pt
+
+recursive-include docs *.rst
+recursive-include docs *.py
+recursive-include docs *.pt
+recursive-include docs Makefile
+recursive-include docs *.bat
diff --git a/README.rst b/README.rst
index 8e3d2d4..cf9bd5a 100644
--- a/README.rst
+++ b/README.rst
@@ -1,6 +1,6 @@
-=======================
- ``zope.pagetemplate``
-=======================
+===================
+ zope.pagetemplate
+===================
.. image:: https://img.shields.io/pypi/v/zope.pagetemplate.svg
:target: https://pypi.python.org/pypi/zope.pagetemplate/
@@ -16,8 +16,21 @@
.. image:: https://coveralls.io/repos/github/zopefoundation/zope.pagetemplate/badge.svg?branch=master
:target: https://coveralls.io/github/zopefoundation/zope.pagetemplate?branch=master
+.. image:: https://readthedocs.org/projects/zopepagetemplate/badge/?version=latest
+ :target: https://zopepagetemplate.readthedocs.org/en/latest/
+ :alt: Documentation Status
+
Page Templates provide an elegant templating mechanism that achieves a
clean separation of presentation and application logic while allowing
for designers to work with templates in their visual editing tools
(FrontPage, Dreamweaver, GoLive, etc.).
+
+Page Templates are based on `a Template Attribute Language
+<https://pypi.python.org/pypi/zope.tal>`_ with expressions provided by
+`TALES <https://pypi.python.org/pypi/zope.tales>`_. For a description
+of their syntax, see `the reference documentation
+<https://docs.zope.org/zope2/zope2book/AppendixC.html>`_.
+
+For detailed documentation on the usage of this package, see
+https://zopepagetemplate.readthedocs.io
diff --git a/doc-requirements.txt b/doc-requirements.txt
new file mode 100644
index 0000000..e9704b8
--- /dev/null
+++ b/doc-requirements.txt
@@ -0,0 +1 @@
+.[docs]
diff --git a/docs/Makefile b/docs/Makefile
new file mode 100644
index 0000000..4c2d034
--- /dev/null
+++ b/docs/Makefile
@@ -0,0 +1,177 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+PAPER =
+BUILDDIR = _build
+
+# User-friendly check for sphinx-build
+ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
+$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
+endif
+
+# Internal variables.
+PAPEROPT_a4 = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
+
+help:
+ @echo "Please use \`make <target>' where <target> is one of"
+ @echo " html to make standalone HTML files"
+ @echo " dirhtml to make HTML files named index.html in directories"
+ @echo " singlehtml to make a single large HTML file"
+ @echo " pickle to make pickle files"
+ @echo " json to make JSON files"
+ @echo " htmlhelp to make HTML files and a HTML help project"
+ @echo " qthelp to make HTML files and a qthelp project"
+ @echo " devhelp to make HTML files and a Devhelp project"
+ @echo " epub to make an epub"
+ @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+ @echo " latexpdf to make LaTeX files and run them through pdflatex"
+ @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
+ @echo " text to make text files"
+ @echo " man to make manual pages"
+ @echo " texinfo to make Texinfo files"
+ @echo " info to make Texinfo files and run them through makeinfo"
+ @echo " gettext to make PO message catalogs"
+ @echo " changes to make an overview of all changed/added/deprecated items"
+ @echo " xml to make Docutils-native XML files"
+ @echo " pseudoxml to make pseudoxml-XML files for display purposes"
+ @echo " linkcheck to check all external links for integrity"
+ @echo " doctest to run all doctests embedded in the documentation (if enabled)"
+
+clean:
+ rm -rf $(BUILDDIR)/*
+
+html:
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+ $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+ $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+ @echo
+ @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+ $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+ @echo
+ @echo "Build finished; now you can process the pickle files."
+
+json:
+ $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+ @echo
+ @echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+ $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+ @echo
+ @echo "Build finished; now you can run HTML Help Workshop with the" \
+ ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+ $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+ @echo
+ @echo "Build finished; now you can run "qcollectiongenerator" with the" \
+ ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+ @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/zopecatalog.qhcp"
+ @echo "To view the help file:"
+ @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/zopecatalog.qhc"
+
+devhelp:
+ $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+ @echo
+ @echo "Build finished."
+ @echo "To view the help file:"
+ @echo "# mkdir -p $$HOME/.local/share/devhelp/zopecatalog"
+ @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/zopecatalog"
+ @echo "# devhelp"
+
+epub:
+ $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+ @echo
+ @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo
+ @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+ @echo "Run \`make' in that directory to run these through (pdf)latex" \
+ "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through pdflatex..."
+ $(MAKE) -C $(BUILDDIR)/latex all-pdf
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+latexpdfja:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through platex and dvipdfmx..."
+ $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+text:
+ $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+ @echo
+ @echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+ $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+ @echo
+ @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+texinfo:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo
+ @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+ @echo "Run \`make' in that directory to run these through makeinfo" \
+ "(use \`make info' here to do that automatically)."
+
+info:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo "Running Texinfo files through makeinfo..."
+ make -C $(BUILDDIR)/texinfo info
+ @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+gettext:
+ $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+ @echo
+ @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+changes:
+ $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+ @echo
+ @echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+ $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+ @echo
+ @echo "Link check complete; look for any errors in the above output " \
+ "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+ $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+ @echo "Testing of doctests in the sources finished, look at the " \
+ "results in $(BUILDDIR)/doctest/output.txt."
+
+xml:
+ $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
+ @echo
+ @echo "Build finished. The XML files are in $(BUILDDIR)/xml."
+
+pseudoxml:
+ $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
+ @echo
+ @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
diff --git a/src/zope/pagetemplate/architecture.txt b/docs/architecture.rst
index 2d07ca4..cf71106 100644
--- a/src/zope/pagetemplate/architecture.txt
+++ b/docs/architecture.rst
@@ -1,31 +1,39 @@
-ZPT (Zope Page-Template) Architecture
-=====================================
+=======================================
+ ZPT (Zope Page-Template) Architecture
+=======================================
There are a number of major components that make up the page-template
-architecture:
+architecture:
- The TAL *compiler* and *interpreter*. This is responsible for
compiling source files and for executing compiled templates. See
- the `zope.tal` package for more information.
+ the zope.tal_ package for more information.
- An *expression engine* is responsible for compiling expressions and
for creating expression execution contexts. It is common for
applications to override expression engines to provide custom
expression support or to change the way expressions are implemented.
- The `zope.app.pagetemplate` package uses this to implement trusted
+
+ The :mod:`zope.pagetemplate.engine` module uses this to implement trusted
and untrusted evaluation; a different engine is used for each, with
different implementations of the same type of expressions.
+ The z3c.ptcompat_ package extends these engines to use the
+ Chameleon_ templating system for increased speed.
+
Expression contexts support execution of expressions and provide
APIs for setting up variable scopes and setting variables. The
expression contexts are passed to the TAL interpreter at execution
time.
-
+
The most commonly used expression implementation is that found in
- `zope.tales`.
+ zope.tales_.
- Page templates tie everything together. They assemble an expression
engine with the TAL interpreter and orchestrate management of source
- and compiled template data. See `zope.pagetemplate.interfaces`.
+ and compiled template data. See :mod:`zope.pagetemplate.interfaces`.
-
+.. _z3c.ptcompat: https://pypi.python.org/pypi/z3c.ptcompat
+.. _zope.tal: https://pypi.python.org/pypi/zope.tal
+.. _zope.tales: https://pypi.python.org/pypi/zope.tales
+.. _Chameleon: https://chameleon.readthedocs.io/en/latest/
diff --git a/docs/changelog.rst b/docs/changelog.rst
new file mode 100644
index 0000000..d9e113e
--- /dev/null
+++ b/docs/changelog.rst
@@ -0,0 +1 @@
+.. include:: ../CHANGES.rst
diff --git a/docs/conf.py b/docs/conf.py
new file mode 100644
index 0000000..480fafb
--- /dev/null
+++ b/docs/conf.py
@@ -0,0 +1,278 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# zope.index documentation build configuration file, created by
+# sphinx-quickstart on Thu Jan 29 11:31:12 2015.
+#
+# This file is execfile()d with the current directory set to its
+# containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+import sys
+import os
+import pkg_resources
+sys.path.append(os.path.abspath('../src'))
+rqmt = pkg_resources.require('zope.pagetemplate')[0]
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#sys.path.insert(0, os.path.abspath('.'))
+
+# -- General configuration ------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = [
+ 'sphinx.ext.autodoc',
+ 'sphinx.ext.doctest',
+ 'sphinx.ext.intersphinx',
+ 'sphinx.ext.viewcode',
+ 'repoze.sphinx.autointerface',
+]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The encoding of source files.
+#source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = 'zope.pagetemplate'
+copyright = '2015-2017, Zope Foundation and Contributors'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = '%s.%s' % tuple(map(int, rqmt.version.split('.')[:2]))
+# The full version, including alpha/beta/rc tags.
+release = rqmt.version
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+exclude_patterns = ['_build']
+
+# The reST default role (used for this markup: `text`) to use for all
+# documents.
+#default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+# If true, keep warnings as "system message" paragraphs in the built documents.
+#keep_warnings = False
+
+
+# -- Options for HTML output ----------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. See the documentation for
+# a list of builtin themes.
+html_theme = 'default'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further. For a list of options available for each theme, see the
+# documentation.
+#html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this directory.
+#html_theme_path = []
+
+# The name for this set of Sphinx documents. If None, it defaults to
+# "<project> v<release> documentation".
+#html_title = None
+
+# A shorter title for the navigation bar. Default is the same as html_title.
+#html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#html_logo = None
+
+# The name of an image file (within the static path) to use as favicon of the
+# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+#html_static_path = ['_static']
+
+# Add any extra paths that contain custom files (such as robots.txt or
+# .htaccess) here, relative to this directory. These files are copied
+# directly to the root of the documentation.
+#html_extra_path = []
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_domain_indices = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+#html_show_sphinx = True
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#html_show_copyright = True
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it. The value of this option must be the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = None
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'zopepagetemplatedoc'
+
+
+# -- Options for LaTeX output ---------------------------------------------
+
+latex_elements = {
+# The paper size ('letterpaper' or 'a4paper').
+#'papersize': 'letterpaper',
+
+# The font size ('10pt', '11pt' or '12pt').
+#'pointsize': '10pt',
+
+# Additional stuff for the LaTeX preamble.
+#'preamble': '',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title,
+# author, documentclass [howto, manual, or own class]).
+latex_documents = [
+ ('index', 'zopeindex.tex', 'zope.pagetemplate Documentation',
+ 'Zope Foundation and Contributors', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_domain_indices = True
+
+
+# -- Options for manual page output ---------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+ ('index', 'zopepagetemplate', 'zope.pagetemplate Documentation',
+ ['Zope Foundation and Contributors'], 1)
+]
+
+# If true, show URL addresses after external links.
+#man_show_urls = False
+
+
+# -- Options for Texinfo output -------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+# dir menu entry, description, category)
+texinfo_documents = [
+ ('index', 'zopepagetemplate', 'zope.pagetemplate Documentation',
+ 'Zope Foundation and Contributors', 'zopepagetemplate', 'One line description of project.',
+ 'Miscellaneous'),
+]
+
+# Documents to append as an appendix to all manuals.
+#texinfo_appendices = []
+
+# If false, no module index is generated.
+#texinfo_domain_indices = True
+
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
+#texinfo_show_urls = 'footnote'
+
+# If true, do not generate a @detailmenu in the "Top" node's menu.
+#texinfo_no_detailmenu = False
+
+
+# Example configuration for intersphinx: refer to the Python standard library.
+intersphinx_mapping = {
+ 'https://docs.python.org/': None,
+}
+
+autodoc_default_flags = ['members', 'show-inheritance']
+autoclass_content = 'both'
+autodoc_member_order = 'bysource'
diff --git a/docs/engine.rst b/docs/engine.rst
new file mode 100644
index 0000000..cf39181
--- /dev/null
+++ b/docs/engine.rst
@@ -0,0 +1,5 @@
+=======================
+ Page Template Engines
+=======================
+
+.. automodule:: zope.pagetemplate.engine
diff --git a/docs/hello_world.pt b/docs/hello_world.pt
new file mode 100644
index 0000000..360c6f9
--- /dev/null
+++ b/docs/hello_world.pt
@@ -0,0 +1 @@
+<html><body>Hello World</body></html>
diff --git a/docs/index.rst b/docs/index.rst
new file mode 100644
index 0000000..9f87ef3
--- /dev/null
+++ b/docs/index.rst
@@ -0,0 +1,30 @@
+.. include:: ../README.rst
+
+
+Documentation
+=============
+
+.. toctree::
+ :maxdepth: 1
+
+ architecture
+ using
+ changelog
+
+Reference
+=========
+
+.. toctree::
+ :maxdepth: 2
+
+ interfaces
+ engine
+ pagetemplate
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
diff --git a/docs/interfaces.rst b/docs/interfaces.rst
new file mode 100644
index 0000000..7c68916
--- /dev/null
+++ b/docs/interfaces.rst
@@ -0,0 +1,5 @@
+============
+ Interfaces
+============
+
+.. automodule:: zope.pagetemplate.interfaces
diff --git a/docs/make.bat b/docs/make.bat
new file mode 100644
index 0000000..9372f64
--- /dev/null
+++ b/docs/make.bat
@@ -0,0 +1,242 @@
+@ECHO OFF
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+ set SPHINXBUILD=sphinx-build
+)
+set BUILDDIR=_build
+set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
+set I18NSPHINXOPTS=%SPHINXOPTS% .
+if NOT "%PAPER%" == "" (
+ set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
+ set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
+)
+
+if "%1" == "" goto help
+
+if "%1" == "help" (
+ :help
+ echo.Please use `make ^<target^>` where ^<target^> is one of
+ echo. html to make standalone HTML files
+ echo. dirhtml to make HTML files named index.html in directories
+ echo. singlehtml to make a single large HTML file
+ echo. pickle to make pickle files
+ echo. json to make JSON files
+ echo. htmlhelp to make HTML files and a HTML help project
+ echo. qthelp to make HTML files and a qthelp project
+ echo. devhelp to make HTML files and a Devhelp project
+ echo. epub to make an epub
+ echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
+ echo. text to make text files
+ echo. man to make manual pages
+ echo. texinfo to make Texinfo files
+ echo. gettext to make PO message catalogs
+ echo. changes to make an overview over all changed/added/deprecated items
+ echo. xml to make Docutils-native XML files
+ echo. pseudoxml to make pseudoxml-XML files for display purposes
+ echo. linkcheck to check all external links for integrity
+ echo. doctest to run all doctests embedded in the documentation if enabled
+ goto end
+)
+
+if "%1" == "clean" (
+ for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
+ del /q /s %BUILDDIR%\*
+ goto end
+)
+
+
+%SPHINXBUILD% 2> nul
+if errorlevel 9009 (
+ echo.
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
+ echo.installed, then set the SPHINXBUILD environment variable to point
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
+ echo.may add the Sphinx directory to PATH.
+ echo.
+ echo.If you don't have Sphinx installed, grab it from
+ echo.http://sphinx-doc.org/
+ exit /b 1
+)
+
+if "%1" == "html" (
+ %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The HTML pages are in %BUILDDIR%/html.
+ goto end
+)
+
+if "%1" == "dirhtml" (
+ %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
+ goto end
+)
+
+if "%1" == "singlehtml" (
+ %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
+ goto end
+)
+
+if "%1" == "pickle" (
+ %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can process the pickle files.
+ goto end
+)
+
+if "%1" == "json" (
+ %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can process the JSON files.
+ goto end
+)
+
+if "%1" == "htmlhelp" (
+ %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can run HTML Help Workshop with the ^
+.hhp project file in %BUILDDIR%/htmlhelp.
+ goto end
+)
+
+if "%1" == "qthelp" (
+ %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can run "qcollectiongenerator" with the ^
+.qhcp project file in %BUILDDIR%/qthelp, like this:
+ echo.^> qcollectiongenerator %BUILDDIR%\qthelp\zopecatalog.qhcp
+ echo.To view the help file:
+ echo.^> assistant -collectionFile %BUILDDIR%\qthelp\zopecatalog.ghc
+ goto end
+)
+
+if "%1" == "devhelp" (
+ %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished.
+ goto end
+)
+
+if "%1" == "epub" (
+ %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The epub file is in %BUILDDIR%/epub.
+ goto end
+)
+
+if "%1" == "latex" (
+ %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
+ goto end
+)
+
+if "%1" == "latexpdf" (
+ %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+ cd %BUILDDIR%/latex
+ make all-pdf
+ cd %BUILDDIR%/..
+ echo.
+ echo.Build finished; the PDF files are in %BUILDDIR%/latex.
+ goto end
+)
+
+if "%1" == "latexpdfja" (
+ %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+ cd %BUILDDIR%/latex
+ make all-pdf-ja
+ cd %BUILDDIR%/..
+ echo.
+ echo.Build finished; the PDF files are in %BUILDDIR%/latex.
+ goto end
+)
+
+if "%1" == "text" (
+ %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The text files are in %BUILDDIR%/text.
+ goto end
+)
+
+if "%1" == "man" (
+ %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The manual pages are in %BUILDDIR%/man.
+ goto end
+)
+
+if "%1" == "texinfo" (
+ %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
+ goto end
+)
+
+if "%1" == "gettext" (
+ %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
+ goto end
+)
+
+if "%1" == "changes" (
+ %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.The overview file is in %BUILDDIR%/changes.
+ goto end
+)
+
+if "%1" == "linkcheck" (
+ %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Link check complete; look for any errors in the above output ^
+or in %BUILDDIR%/linkcheck/output.txt.
+ goto end
+)
+
+if "%1" == "doctest" (
+ %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Testing of doctests in the sources finished, look at the ^
+results in %BUILDDIR%/doctest/output.txt.
+ goto end
+)
+
+if "%1" == "xml" (
+ %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The XML files are in %BUILDDIR%/xml.
+ goto end
+)
+
+if "%1" == "pseudoxml" (
+ %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.
+ goto end
+)
+
+:end
diff --git a/docs/pagetemplate.rst b/docs/pagetemplate.rst
new file mode 100644
index 0000000..d6e5010
--- /dev/null
+++ b/docs/pagetemplate.rst
@@ -0,0 +1,7 @@
+================
+ Page Templates
+================
+
+.. automodule:: zope.pagetemplate.pagetemplate
+
+.. automodule:: zope.pagetemplate.pagetemplatefile
diff --git a/docs/using.rst b/docs/using.rst
new file mode 100644
index 0000000..157db3a
--- /dev/null
+++ b/docs/using.rst
@@ -0,0 +1,78 @@
+===========
+ ZPT Usage
+===========
+
+This document focuses on usage of the Page Templates API.
+
+For information about writing Page Templates documents and using TAL
+and TALES, refer to the `reference documentation
+<https://docs.zope.org/zope2/zope2book/AppendixC.html>`_ or the
+`Chameleon documentation
+<https://chameleon.readthedocs.io/en/latest/reference.html>`_ if you
+are using z3c.ptcompat.
+
+.. testsetup::
+
+ __file__ = 'docs/using.rst'
+
+Simple Usage
+============
+
+Using Page Templates is very easy and straight forward. Let's look at
+a quick example. Suppose we have a file called ``hello_world.pt`` with
+these contents:
+
+.. literalinclude:: hello_world.pt
+
+.. doctest::
+
+ >>> from zope.pagetemplate.pagetemplatefile import PageTemplateFile
+ >>> my_pt = PageTemplateFile('hello_world.pt')
+ >>> print(my_pt().strip())
+ <html><body>Hello World</body></html>
+
+Subclassing PageTemplates
+=========================
+
+Lets say we want to alter page templates such that keyword arguments
+appear as top level items in the namespace. We can subclass
+:class:`~.PageTemplate` and alter the default behavior of
+:meth:`~.pt_getContext()` to add them in:
+
+.. testcode::
+
+ from zope.pagetemplate.pagetemplate import PageTemplate
+
+ class mypt(PageTemplate):
+ def pt_getContext(self, args=(), options={}, **kw):
+ rval = PageTemplate.pt_getContext(self, args=args)
+ options.update(rval)
+ return options
+
+ class foo(object):
+ def getContents(self): return 'hi'
+
+So now we can bind objects in a more arbitrary fashion, like the
+following:
+
+.. testcode::
+
+ template = """
+ <html>
+ <body>
+ <b tal:replace="das_object/getContents">Good Stuff Here</b>
+ </body>
+ </html>
+ """
+
+ pt = mypt()
+ pt.write(template)
+ print(pt(das_object=foo()).strip())
+
+.. testoutput::
+
+ <html>
+ <body>
+ hi
+ </body>
+ </html>
diff --git a/setup.py b/setup.py
index 5e1c07d..1cd7eec 100644
--- a/setup.py
+++ b/setup.py
@@ -43,14 +43,6 @@ setup(name='zope.pagetemplate',
long_description=(
read('README.rst')
+ '\n\n' +
- '======================\n'
- 'Detailed Documentation\n' +
- '======================'
- + '\n\n' +
- read('src', 'zope', 'pagetemplate', 'architecture.txt')
- + '\n\n' +
- read('src', 'zope', 'pagetemplate', 'readme.txt')
- + '\n\n' +
read('CHANGES.rst')),
keywords="zope3 page template",
classifiers=[
@@ -72,7 +64,7 @@ setup(name='zope.pagetemplate',
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope3',
],
- url='http://github.com/zopefoundation/zope.pagetemplate',
+ url='https://github.com/zopefoundation/zope.pagetemplate',
license='ZPL 2.1',
packages=find_packages('src'),
package_dir={'': 'src'},
@@ -87,6 +79,10 @@ setup(name='zope.pagetemplate',
'untrusted:python_version == "2.7"': [
'zope.untrustedpython',
],
+ 'docs': [
+ 'Sphinx',
+ 'repoze.sphinx.autointerface',
+ ],
},
install_requires=[
'setuptools',
diff --git a/src/zope/pagetemplate/engine.py b/src/zope/pagetemplate/engine.py
index cea32d7..01df54c 100644
--- a/src/zope/pagetemplate/engine.py
+++ b/src/zope/pagetemplate/engine.py
@@ -170,6 +170,9 @@ class ZopeContext(ZopeContextBase):
Therefore, this method removes any proxy from the evaluated
expression.
+ >>> from zope.pagetemplate.engine import ZopeContext
+ >>> from zope.tales.tales import ExpressionEngine
+ >>> from zope.security.proxy import ProxyFactory
>>> output = [('version', 'xxx'), ('mode', 'html'), ('other', 'things')]
>>> def expression(context):
... return ProxyFactory(output)
@@ -236,11 +239,13 @@ class AdapterNamespaces(object):
>>> def adapter1(ob):
... return 1
>>> adapter1.__component_adapts__ = (None,)
+ >>> from zope.traversing.interfaces import IPathAdapter
>>> provideAdapter(adapter1, None, IPathAdapter, 'a1')
Now, with this adapter in place, we can try out the namespaces:
>>> ob = object()
+ >>> from zope.pagetemplate.engine import AdapterNamespaces
>>> namespaces = AdapterNamespaces()
>>> namespace = namespaces['a1']
>>> namespace(ob)
@@ -301,11 +306,13 @@ class ZopeBaseEngine(ExpressionEngine):
return context
class ZopeEngine(ZopeBaseEngine):
- """Untrusted expression engine.
+ """
+ Untrusted expression engine.
This engine does not allow modules to be imported; only modules
already available may be accessed::
+ >>> from zope.pagetemplate.engine import _Engine
>>> modname = 'zope.pagetemplate.tests.trusted'
>>> engine = _Engine()
>>> context = engine.getContext(engine.getBaseNames())
@@ -391,7 +398,7 @@ class ZopeEngine(ZopeBaseEngine):
Note that this engine special-cases dicts during path traversal:
it traverses only to their items, but not to their attributes
- (e.g. methods on dicts), because of performance reasons:
+ (e.g. methods on dicts), because of performance reasons::
>>> d = engine.getBaseNames()
>>> d['adict'] = {'items': 123}
@@ -404,7 +411,7 @@ class ZopeEngine(ZopeBaseEngine):
...
KeyError: 'keys'
- This special-casing also applies to non-proxied dict subclasses:
+ This special-casing also applies to non-proxied dict subclasses::
>>> class TraverserDict(dict):
... def __init__(self):
@@ -433,10 +440,12 @@ class ZopeEngine(ZopeBaseEngine):
super(ZopeEngine, self).getFunctionNamespace(namespacename))
class TrustedZopeEngine(ZopeBaseEngine):
- """Trusted expression engine.
+ """
+ Trusted expression engine.
This engine allows modules to be imported::
+ >>> from zope.pagetemplate.engine import _TrustedEngine
>>> modname = 'zope.pagetemplate.tests.trusted'
>>> engine = _TrustedEngine()
>>> context = engine.getContext(engine.getBaseNames())
@@ -450,7 +459,7 @@ class TrustedZopeEngine(ZopeBaseEngine):
True
Since this is trusted code, we can look at whatever is in the
- module, not just __name__ or what's declared in a security
+ module, not just ``__name__`` or what's declared in a security
assertion::
>>> m.x
diff --git a/src/zope/pagetemplate/interfaces.py b/src/zope/pagetemplate/interfaces.py
index 4929b39..9a0fe71 100644
--- a/src/zope/pagetemplate/interfaces.py
+++ b/src/zope/pagetemplate/interfaces.py
@@ -25,8 +25,8 @@ class IPageTemplate(Interface):
The argument handling is specific to particular
implementations. Normally, however, positional arguments are
- bound to the top-level `args` variable and keyword arguments
- are bound to the top-level `options` variable.
+ bound to the top-level ``args`` variable and keyword arguments
+ are bound to the top-level ``options`` variable.
"""
def pt_edit(source, content_type):
@@ -39,7 +39,7 @@ class IPageTemplate(Interface):
The errors may occur when the template is compiled or
rendered.
- `namespace` is the set of names passed to the TALES expression
+ *namespace* is the set of names passed to the TALES expression
evaluator, similar to what's returned by pt_getContext().
This can be used to let a template author know what went wrong
@@ -50,20 +50,20 @@ class IPageTemplate(Interface):
"""Get the template source
"""
- macros = Attribute("An object that implements the __getitem__ "
- "protocol, containing page template macros.")
+ macros = Attribute("An object that implements the ``__getitem__`` "
+ "protocol (e.g., a :class:`dict`), containing page template macros.")
class IPageTemplateSubclassing(IPageTemplate):
"""Behavior that may be overridden or used by subclasses
"""
-
+
def pt_getContext(**kw):
"""Compute a dictionary of top-level template names
-
+
Responsible for returning the set of
top-level names supported in path expressions
-
+
"""
def pt_getEngine():
@@ -79,7 +79,7 @@ class IPageTemplateSubclassing(IPageTemplate):
This is sometimes overridden to provide additional argument
binding.
"""
-
+
def pt_source_file():
"""return some text describing where a bit of ZPT code came from.
@@ -89,8 +89,8 @@ class IPageTemplateSubclassing(IPageTemplate):
def _cook():
"""Compile the source
- Results are saved in the variables: _v_errors, _v_warnings,
- _v_program, and _v_macros, and the flag _v_cooked is set.
+ Results are saved in the variables: ``_v_errors``, ``_v_warnings``,
+ ``_v_program``, and ``_v_macros``, and the flag ``_v_cooked`` is set.
"""
def _cook_check():
"""Compiles the source if necessary
@@ -115,8 +115,8 @@ class IPageTemplateEngine(Interface):
def cook(source_file, text, engine, content_type):
"""Parse text and return prepared template program and macros.
- Note that while ``source_file`` is provided to name the source
- of the input ``text``, it should not be relied on to be an
+ Note that while *source_file* is provided to name the source
+ of the input *text*, it should not be relied on to be an
actual filename (it may be an application-specific, virtual
path).
@@ -128,36 +128,29 @@ class IPageTemplateProgram(Interface):
"""Cooked template program."""
def __call__(
- context, macros, debug=0, wrap=60, metal=1, tal=1, showtal=-1,
- strictinsert=1, stackLimit=100, i18nInterpolate=1,
- sourceAnnotations=0):
- """Render template in the provided template ``context``.
+ context, macros, debug=0, wrap=60, metal=1, tal=1, showtal=-1,
+ strictinsert=1, stackLimit=100, i18nInterpolate=1,
+ sourceAnnotations=0):
+ """
+ Render template in the provided template *context*.
Optional arguments:
- debug -- enable debugging output to sys.stderr (off by default).
-
- wrap -- try to wrap attributes on opening tags to this number of
+ :keyword bool debug: enable debugging output to sys.stderr (off by default).
+ :keyword int wrap: try to wrap attributes on opening tags to this number of
column (default: 60).
-
- metal -- enable METAL macro processing (on by default).
-
- tal -- enable TAL processing (on by default).
-
- showtal -- do not strip away TAL directives. A special value of
+ :keyword bool metal: enable METAL macro processing (on by default).
+ :keyword bool tal: enable TAL processing (on by default).
+ :keyword int showtal: do not strip away TAL directives. A special value of
-1 (which is the default setting) enables showtal when TAL
processing is disabled, and disables showtal when TAL processing is
enabled. Note that you must use 0, 1, or -1; true boolean values
are not supported (for historical reasons).
-
- strictinsert -- enable TAL processing and stricter HTML/XML
+ :keyword bool strictinsert: enable TAL processing and stricter HTML/XML
checking on text produced by structure inserts (on by default).
Note that Zope turns this value off by default.
-
- stackLimit -- set macro nesting limit (default: 100).
-
- i18nInterpolate -- enable i18n translations (default: on).
-
- sourceAnnotations -- enable source annotations with HTML comments
+ :keyword int stackLimit: set macro nesting limit (default: 100).
+ :keyword bool i18nInterpolate: enable i18n translations (default: on).
+ :keyword bool sourceAnnotations: enable source annotations with HTML comments
(default: off).
"""
diff --git a/src/zope/pagetemplate/pagetemplate.py b/src/zope/pagetemplate/pagetemplate.py
index 9c05c89..81b2c8b 100644
--- a/src/zope/pagetemplate/pagetemplate.py
+++ b/src/zope/pagetemplate/pagetemplate.py
@@ -34,8 +34,7 @@ _default_options = {}
class StringIO(list):
- """Unicode aware append-only version of StringIO.
- """
+ # Unicode aware append-only version of StringIO.
write = list.append
def __init__(self, value=None):
@@ -49,25 +48,27 @@ class StringIO(list):
@implementer(IPageTemplateSubclassing)
class PageTemplate(object):
- """Page Templates using TAL, TALES, and METAL.
+ """
+ Page Templates using TAL, TALES, and METAL.
+
+ **Subclassing**
- Subclassing
- -----------
+ This class implements :class:`~zope.pagetemplate.interfaces.IPageTemplateSubclassing`.
The following methods have certain internal responsibilities.
- pt_getContext(**keywords)
+ ``pt_getContext(**keywords)``
Should ignore keyword arguments that it doesn't care about,
and construct the namespace passed to the TALES expression
engine. This method is free to use the keyword arguments it
receives.
- pt_render(namespace, source=False, sourceAnnotations=False, showtal=False)
+ ``pt_render(namespace, source=False, sourceAnnotations=False, showtal=False)``
Responsible the TAL interpreter to perform the rendering. The
namespace argument is a mapping which defines the top-level
namespaces passed to the TALES expression engine.
- __call__(*args, **keywords)
+ ``__call__(*args, **keywords)``
Calls pt_getContext() to construct the top-level namespace
passed to the TALES expression engine, then calls pt_render()
to perform the rendering.
@@ -245,7 +246,11 @@ class PTRuntimeError(RuntimeError):
@implementer(IPageTemplateProgram)
@provider(IPageTemplateEngine)
class PageTemplateEngine(object):
- """Page template engine that uses the TAL interpreter to render."""
+ """
+ Page template engine that uses the TAL interpreter to render.
+
+ This class implements :class:`zope.pagetemplate.interfaces.IPageTemplateProgram`.
+ """
def __init__(self, program):
diff --git a/src/zope/pagetemplate/readme.txt b/src/zope/pagetemplate/readme.txt
deleted file mode 100644
index 85f6fda..0000000
--- a/src/zope/pagetemplate/readme.txt
+++ /dev/null
@@ -1,53 +0,0 @@
-ZPT Usage
-=========
-
-This document focuses on usage of Page Templates outside of a Zope
-context, it does *not* explain how to write page templates as there
-are several resources on the web which do so.
-
-Simple Usage
-------------
-
-Using Page Templates outside of Zope3 is very easy and straight
-forward. A quick example::
-
- >>> from zope.pagetemplate.pagetemplatefile import PageTemplateFile
- >>> my_pt = PageTemplateFile('hello_world.pt')
- >>> my_pt()
- u'<html><body>Hello World</body></html>'
-
-Subclassing PageTemplates
--------------------------
-
-Lets say we want to alter page templates such that keyword arguments
-appear as top level items in the namespace. We can subclass
-`PageTemplate` and alter the default behavior of `pt_getContext()` to
-add them in::
-
- from zope.pagetemplate.pagetemplate import PageTemplate
-
- class mypt(PageTemplate):
- def pt_getContext(self, args=(), options={}, **kw):
- rval = PageTemplate.pt_getContext(self, args=args)
- options.update(rval)
- return options
-
- class foo:
- def getContents(self): return 'hi'
-
-So now we can bind objects in a more arbitrary fashion, like the
-following::
-
- template = """
- <html>
- <body>
- <b tal:replace="das_object/getContents">Good Stuff Here</b>
- </body>
- </html>
- """
-
- pt = mypt()
- pt.write(template)
- pt(das_object=foo())
-
-See `interfaces.py`.
diff --git a/tox.ini b/tox.ini
index 90869b2..8a26210 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,12 +1,13 @@
[tox]
envlist =
- py27,py34,py35,py36,pypy,pypy3,coverage
+ py27,py34,py35,py36,pypy,pypy3,coverage,docs
[testenv]
commands =
zope-testrunner --test-path=src []
+ sphinx-build -b doctest -d {envdir}/doctrees docs {envdir}/doctest
deps =
- .[test]
+ .[test,docs]
[testenv:coverage]
usedevelop = true
@@ -14,7 +15,15 @@ basepython =
python2.7
commands =
coverage run -m zope.testrunner --test-path=src []
+ coverage run -a -m sphinx -b doctest -d {envdir}/.cache/doctrees docs {envdir}/.cache/doctest
coverage report --fail-under=100
deps =
{[testenv]deps}
coverage
+
+[testenv:docs]
+basepython =
+ python2.7
+commands =
+ sphinx-build -b html -d docs/_build/doctrees docs docs/_build/html
+ sphinx-build -b doctest -d docs/_build/doctrees docs docs/_build/doctest