Opened 10 years ago
Last modified 5 years ago
#12238 new enhancement
IncludeMacro and pystache integration
Reported by: | aauzi | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | IncludeMacro |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 1.0 |
Description
In an attempt to use IncludeMacro to include a file README.trac in a page where the TOC macro was used, I first noticed that the titles present in my included file weren't reflected in the produced Table Of Content.
I first looked around to see if a solution to that itching issue was available, then discovered MarcinK's SearchForUltimateWikiTemplateMacro and finally decided to give it a shot.
Tipped by coderanger about Mustache template language, I discovered Pystache and thought it may be interesting to integrate it with IncludeMacro.
pystache allows to achieve parameters replacements.
Include replaces the macros named parameters with the syntax {{name}}
Similarly, it replaces arguments with the syntax {{argv[i]}}
where i
is the positional index of the argument.
The scope of those parameters is limited to the included source but named parameters are globals within the inclusion stack whereas arguments are not.
Block processor mode is supported, allowing templates without include, like:
{{{#!Include author=me This was written by {{author}}. }}}
To give it credit in this context, one may prefer the alias:
{{{#!pystache author=me This was written by {{author}}. }}}
Roughly the changes were:
- implementation an IWikiPageManipulator interface to:
- have the TOC macro work with whatever titles a template include may contain and
- manage the permissions on page validation.
- creation of the SystemMessage macro to render messages in wiki text format reported by the includes done by the IWikiPageManipulator.prepare_page.
- anti-recusion has been added
- to add robustness against urls page redirections the urllib2 urlf.geturl() method is used for the anti-recursion
- addition of permissions TEMPLATE_CREATE and INCLUDE_CREATE
- class documentation has been completed
- unittest and coverage procedures and results are provided
I run this on a Fedora 21 workstation with:
- python 2.7.8
- trac 1.0.2
- pystache 0.5.3
- python-coverage 3.7
NB: with it's anti-recursion feature, I believe this fixes #4272
Attachments (0)
Change History (5)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
We'll need to update setup.py
so that the dependencies are implicitly installed.
08:38:07 Trac[loader] ERROR: Skipping "includemacro.macros = includemacro.macros": Traceback (most recent call last): File "/Users/rjollos/Documents/Workspace/th-dev/srv/trac-hacks.org/src/Trac-1.0.5/trac/loader.py", line 68, in _load_eggs entry.load(require=True) File "/Users/rjollos/Documents/Workspace/th-dev/srv/trac-hacks.org/pve/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2310, in load return self.resolve() File "/Users/rjollos/Documents/Workspace/th-dev/srv/trac-hacks.org/pve/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2316, in resolve module = __import__(self.module_name, fromlist=['__name__'], level=0) File "/Users/rjollos/Documents/Workspace/th-dev/srv/trac-hacks.org/src/include-trunk/includemacro/macros.py", line 34, in <module> from pystache.common import MissingTags, TemplateNotFoundError ImportError: No module named pystache.common
comment:5 Changed 5 years ago by
Owner: | Ryan J Ollos deleted |
---|
Committed r14483