mercurial/templater.py
changeset 20370 aa51392da507
parent 20369 9c6b86dd2ed2
child 20371 6f3fb6a974e0
equal deleted inserted replaced
20369:9c6b86dd2ed2 20370:aa51392da507
   243         except IndexError:
   243         except IndexError:
   244             pass
   244             pass
   245 
   245 
   246     return templatefilters.fill(text, width, initindent, hangindent)
   246     return templatefilters.fill(text, width, initindent, hangindent)
   247 
   247 
       
   248 def pad(context, mapping, args):
       
   249     """usage: pad(text, width, fillchar=' ', right=False)
       
   250     """
       
   251     if not (2 <= len(args) <= 4):
       
   252         raise error.ParseError(_("pad() expects two to four arguments"))
       
   253 
       
   254     width = int(args[1][1])
       
   255 
       
   256     text = stringify(args[0][0](context, mapping, args[0][1]))
       
   257     if args[0][0] == runstring:
       
   258         text = stringify(runtemplate(context, mapping,
       
   259             compiletemplate(text, context)))
       
   260 
       
   261     right = False
       
   262     fillchar = ' '
       
   263     if len(args) > 2:
       
   264         fillchar = stringify(args[2][0](context, mapping, args[2][1]))
       
   265     if len(args) > 3:
       
   266         right = util.parsebool(args[3][1])
       
   267 
       
   268     if right:
       
   269         return text.rjust(width, fillchar)
       
   270     else:
       
   271         return text.ljust(width, fillchar)
       
   272 
   248 def get(context, mapping, args):
   273 def get(context, mapping, args):
   249     if len(args) != 2:
   274     if len(args) != 2:
   250         # i18n: "get" is a keyword
   275         # i18n: "get" is a keyword
   251         raise error.ParseError(_("get() expects two arguments"))
   276         raise error.ParseError(_("get() expects two arguments"))
   252 
   277 
   405     "get": get,
   430     "get": get,
   406     "if": if_,
   431     "if": if_,
   407     "ifeq": ifeq,
   432     "ifeq": ifeq,
   408     "join": join,
   433     "join": join,
   409     "label": label,
   434     "label": label,
       
   435     "pad": pad,
   410     "rstdoc": rstdoc,
   436     "rstdoc": rstdoc,
   411     "shortest": shortest,
   437     "shortest": shortest,
   412     "strip": strip,
   438     "strip": strip,
   413     "sub": sub,
   439     "sub": sub,
   414 }
   440 }