mercurial/templater.py
changeset 28373 9a9dd71e882c
parent 28349 7cb2f2438f85
child 28374 af3bd9d1dbc1
equal deleted inserted replaced
28372:74d03766f962 28373:9a9dd71e882c
   229 
   229 
   230 def evalstring(context, mapping, arg):
   230 def evalstring(context, mapping, arg):
   231     func, data = arg
   231     func, data = arg
   232     return stringify(func(context, mapping, data))
   232     return stringify(func(context, mapping, data))
   233 
   233 
       
   234 def evalstringliteral(context, mapping, arg):
       
   235     """Evaluate given argument as string template, but returns symbol name
       
   236     if it is unknown"""
       
   237     func, data = arg
       
   238     if func is runsymbol:
       
   239         thing = func(context, mapping, data, default=data)
       
   240     else:
       
   241         thing = func(context, mapping, data)
       
   242     return stringify(thing)
       
   243 
   234 def runinteger(context, mapping, data):
   244 def runinteger(context, mapping, data):
   235     return int(data)
   245     return int(data)
   236 
   246 
   237 def runstring(context, mapping, data):
   247 def runstring(context, mapping, data):
   238     return data
   248     return data
   243     return showrecursion
   253     return showrecursion
   244 
   254 
   245 def _runrecursivesymbol(context, mapping, key):
   255 def _runrecursivesymbol(context, mapping, key):
   246     raise error.Abort(_("recursive reference '%s' in template") % key)
   256     raise error.Abort(_("recursive reference '%s' in template") % key)
   247 
   257 
   248 def runsymbol(context, mapping, key):
   258 def runsymbol(context, mapping, key, default=''):
   249     v = mapping.get(key)
   259     v = mapping.get(key)
   250     if v is None:
   260     if v is None:
   251         v = context._defaults.get(key)
   261         v = context._defaults.get(key)
   252     if v is None:
   262     if v is None:
   253         # put poison to cut recursion. we can't move this to parsing phase
   263         # put poison to cut recursion. we can't move this to parsing phase
   255         safemapping = mapping.copy()
   265         safemapping = mapping.copy()
   256         safemapping[key] = _recursivesymbolblocker(key)
   266         safemapping[key] = _recursivesymbolblocker(key)
   257         try:
   267         try:
   258             v = context.process(key, safemapping)
   268             v = context.process(key, safemapping)
   259         except TemplateNotFound:
   269         except TemplateNotFound:
   260             v = ''
   270             v = default
   261     if callable(v):
   271     if callable(v):
   262         return v(**mapping)
   272         return v(**mapping)
   263     return v
   273     return v
   264 
   274 
   265 def buildtemplate(exp, context):
   275 def buildtemplate(exp, context):