Differences between revisions 1 and 4 (spanning 3 versions)
Revision 1 as of 2011-08-24 11:50:16
Size: 943
Editor: medusa
Comment:
Revision 4 as of 2012-05-08 15:16:22
Size: 956
Editor: mpm
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
##master-date:Unknown-Date
Line 5: Line 4:

<<Include(A:style)>>
Line 6: Line 8:
Line 8: Line 9:
This page shows you how to create a custom filter.
For that, we are going to write a python script, and add it as an extension.
This page shows you how to create a custom filter. For that, we are going to write a python script, and add it as an extension.
Line 14: Line 14:
Line 26: Line 25:
Line 37: Line 35:
Line 41: Line 38:
}}} }}}
----
CategoryDeveloper

{i} This page does not meet our wiki style guidelines. Please help improve this page by cleaning up its formatting.

Create a custom filter

Objective

This page shows you how to create a custom filter. For that, we are going to write a python script, and add it as an extension.

Our filter will convert the text passed to it to uppercase.

Write script

First step, write the script and save it somewhere.

   1 from mercurial import templatefilters
   2 
   3 def upper(s):
   4     return s.upper()
   5 
   6 def extsetup(ui):
   7     templatefilters.filters["upper"] = upper

Add Extension

In mercurial.ini, add this script under the [extensions] section.

[extensions]
upper = ~/.hgext/myfeature.py

(if this doesn't work, see Using Mercurial Extensions for help on configuring extensions)

Example

>hg tip --template "{author|upper}\n"
GUIDO VAN ROSSUM <BDFL@PYTHON.ORG>


CategoryDeveloper

TemplateFilters (last edited 2012-05-08 15:16:22 by mpm)