mercurial/templater.py
changeset 17635 8804e3cb51bd
parent 17634 6b307730c9f0
child 17636 ce18dbcd91c8
equal deleted inserted replaced
17634:6b307730c9f0 17635:8804e3cb51bd
     4 #
     4 #
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from i18n import _
     8 from i18n import _
     9 import sys, os
     9 import sys, os, re
    10 import util, config, templatefilters, parser, error
    10 import util, config, templatefilters, parser, error
    11 
    11 
    12 # template parsing
    12 # template parsing
    13 
    13 
    14 elements = {
    14 elements = {
   216             first = False
   216             first = False
   217         else:
   217         else:
   218             yield joiner
   218             yield joiner
   219         yield x
   219         yield x
   220 
   220 
       
   221 def sub(context, mapping, args):
       
   222     if len(args) != 3:
       
   223         raise error.ParseError(_("sub expects three arguments"))
       
   224 
       
   225     pat = stringify(args[0][0](context, mapping, args[0][1]))
       
   226     rpl = stringify(args[1][0](context, mapping, args[1][1]))
       
   227     src = stringify(args[2][0](context, mapping, args[2][1]))
       
   228     yield re.sub(pat, rpl, src)
       
   229 
   221 methods = {
   230 methods = {
   222     "string": lambda e, c: (runstring, e[1]),
   231     "string": lambda e, c: (runstring, e[1]),
   223     "symbol": lambda e, c: (runsymbol, e[1]),
   232     "symbol": lambda e, c: (runsymbol, e[1]),
   224     "group": lambda e, c: compileexp(e[1], c),
   233     "group": lambda e, c: compileexp(e[1], c),
   225 #    ".": buildmember,
   234 #    ".": buildmember,
   228     "func": buildfunc,
   237     "func": buildfunc,
   229     }
   238     }
   230 
   239 
   231 funcs = {
   240 funcs = {
   232     "join": join,
   241     "join": join,
       
   242     "sub": sub,
   233 }
   243 }
   234 
   244 
   235 # template engine
   245 # template engine
   236 
   246 
   237 path = ['templates', '../templates']
   247 path = ['templates', '../templates']