Edgewall Software
Modify

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#47 closed enhancement (fixed)

Include simple text-based templating?

Reported by: cmlenz Owned by: cmlenz
Priority: major Milestone: 0.3
Component: Template processing Version: 0.2
Keywords: Cc:

Description

As Markup already provides much of the functionality needed for general-purpose templating (not just XML-based templating), it should be possible to reuse this to create a very simple text-based template engine, for those cases where you need to generate plain text, and using a package such as Cheetah may be overkill.

Attachments (5)

texttmpl.diff (2.8 KB) - added by cmlenz 9 years ago.
Template subclass that does basic text-based templating
texttmpl.2.diff (4.3 KB) - added by cmlenz 9 years ago.
Updated to include position info
texttmpl.3.diff (3.6 KB) - added by cmlenz 9 years ago.
Bugfix: don't ignore last text partition
texttmpl.4.diff (4.4 KB) - added by cboos 9 years ago.
Based on attachment:texttmpl.3.diff and r281, integrates TextTemplate with the TemplateLoader
trac-ticket_notify_mail-r3697.diff (4.7 KB) - added by cboos 9 years ago.
Usage example, for Trac:source:sandbox/markup@3698: conversion of the ticket_notify_email.txt template, plus some adaptations to the Chrome component

Download all attachments as: .zip

Change History (8)

Changed 9 years ago by cmlenz

Template subclass that does basic text-based templating

comment:1 Changed 9 years ago by cmlenz

I've attached a patch that implements a simple text-based template engine (markup.template.TextTemplate) on top of the main Markup template engine (markup.template.Template).

The class reuses a lot of functionality already in place for XML-based templating, such as interpolation and evaluation of expressions, the set of directives (although some make no sense outside of XML), and the general processing logic.

Obviously, this would need more work: for example, there's no position reporting yet.

Changed 9 years ago by cmlenz

Updated to include position info

Changed 9 years ago by cmlenz

Bugfix: don't ignore last text partition

Changed 9 years ago by cboos

Based on attachment:texttmpl.3.diff and r281, integrates TextTemplate with the TemplateLoader

Changed 9 years ago by cboos

Usage example, for Trac:source:sandbox/markup@3698: conversion of the ticket_notify_email.txt template, plus some adaptations to the Chrome component

comment:2 Changed 9 years ago by cmlenz

  • Milestone set to 0.3
  • Resolution set to fixed
  • Status changed from new to closed

Basic implementation checked in in [292]. Any specific issues/shortcomings of the text templating language should be raised in separate tickets.

comment:3 Changed 9 years ago by cboos

Works great for Trac, see [trac 3730].

Forgot to mention in the commit log there that it requires r300, because of the stripped #end commands.

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain cmlenz.
The resolution will be deleted. Next status will be 'reopened'.
Author


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

 
Note: See TracTickets for help on using tickets.