Modify

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:

  1. implementation an IWikiPageManipulator interface to:
    1. have the TOC macro work with whatever titles a template include may contain and
    2. manage the permissions on page validation.
  2. creation of the SystemMessage macro to render messages in wiki text format reported by the includes done by the IWikiPageManipulator.prepare_page.
  3. anti-recusion has been added
  4. to add robustness against urls page redirections the urllib2 urlf.geturl() method is used for the anti-recursion
  5. addition of permissions TEMPLATE_CREATE and INCLUDE_CREATE
  6. class documentation has been completed
  7. 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 aauzi

Committed r14483

comment:2 Changed 10 years ago by Ryan J Ollos

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:3 Changed 10 years ago by Ryan J Ollos

In 14550:

3.0.0dev: Moving ticket #12238 work to a branch for staging. Refs #12238.

comment:4 Changed 10 years ago by Ryan J Ollos

In 14551:

3.0.0dev: Reverse merge of [14438]. Refs #12238.

The changes will be improved on the ticket-12238 branch before being merged back to the trunk.

comment:5 Changed 5 years ago by Ryan J Ollos

Owner: Ryan J Ollos deleted

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.