mercurial/templatefilters.py
changeset 26106 c568c4db036f
parent 25983 1245049da5f3
child 26127 7012be5ab5bd
equal deleted inserted replaced
26105:d67341f55429 26106:c568c4db036f
    78     return os.path.basename(path)
    78     return os.path.basename(path)
    79 
    79 
    80 def count(i):
    80 def count(i):
    81     """:count: List or text. Returns the length as an integer."""
    81     """:count: List or text. Returns the length as an integer."""
    82     return len(i)
    82     return len(i)
    83 
       
    84 def datefilter(text):
       
    85     """:date: Date. Returns a date in a Unix date format, including the
       
    86     timezone: "Mon Sep 04 15:13:13 2006 0700".
       
    87     """
       
    88     return util.datestr(text)
       
    89 
    83 
    90 def domain(author):
    84 def domain(author):
    91     """:domain: Any text. Finds the first string that looks like an email
    85     """:domain: Any text. Finds the first string that looks like an email
    92     address, and extracts just the domain component. Example: ``User
    86     address, and extracts just the domain component. Example: ``User
    93     <user@example.com>`` becomes ``example.com``.
    87     <user@example.com>`` becomes ``example.com``.
   346         return "".join([stringify(t) for t in thing if t is not None])
   340         return "".join([stringify(t) for t in thing if t is not None])
   347     if thing is None:
   341     if thing is None:
   348         return ""
   342         return ""
   349     return str(thing)
   343     return str(thing)
   350 
   344 
   351 def strip(text):
       
   352     """:strip: Any text. Strips all leading and trailing whitespace."""
       
   353     return text.strip()
       
   354 
       
   355 def stripdir(text):
   345 def stripdir(text):
   356     """:stripdir: Treat the text as path and strip a directory level, if
   346     """:stripdir: Treat the text as path and strip a directory level, if
   357     possible. For example, "foo" and "foo/bar" becomes "foo".
   347     possible. For example, "foo" and "foo/bar" becomes "foo".
   358     """
   348     """
   359     dir = os.path.dirname(text)
   349     dir = os.path.dirname(text)
   399 filters = {
   389 filters = {
   400     "addbreaks": addbreaks,
   390     "addbreaks": addbreaks,
   401     "age": age,
   391     "age": age,
   402     "basename": basename,
   392     "basename": basename,
   403     "count": count,
   393     "count": count,
   404     "date": datefilter,
       
   405     "domain": domain,
   394     "domain": domain,
   406     "email": email,
   395     "email": email,
   407     "escape": escape,
   396     "escape": escape,
   408     "fill68": fill68,
   397     "fill68": fill68,
   409     "fill76": fill76,
   398     "fill76": fill76,
   427     "shortbisect": shortbisect,
   416     "shortbisect": shortbisect,
   428     "shortdate": shortdate,
   417     "shortdate": shortdate,
   429     "splitlines": splitlines,
   418     "splitlines": splitlines,
   430     "stringescape": stringescape,
   419     "stringescape": stringescape,
   431     "stringify": stringify,
   420     "stringify": stringify,
   432     "strip": strip,
       
   433     "stripdir": stripdir,
   421     "stripdir": stripdir,
   434     "tabindent": tabindent,
   422     "tabindent": tabindent,
   435     "upper": upper,
   423     "upper": upper,
   436     "urlescape": urlescape,
   424     "urlescape": urlescape,
   437     "user": userfilter,
   425     "user": userfilter,