templatefilters: add "upper" and "lower" for case conversion
authorYuya Nishihara <yuya@tcha.org>
Mon, 30 Mar 2015 23:54:29 +0900
changeset 24566 6abce80e6cbf
parent 24565 2f7cb6e6acdd
child 24567 13f0af2a5a4c
templatefilters: add "upper" and "lower" for case conversion Typically it will be used in patchbomb's flag template, which will be implemented by future patches.
mercurial/templatefilters.py
tests/test-command-template.t
--- a/mercurial/templatefilters.py	Wed Apr 01 12:50:10 2015 -0700
+++ b/mercurial/templatefilters.py	Mon Mar 30 23:54:29 2015 +0900
@@ -234,6 +234,10 @@
     """:localdate: Date. Converts a date to local date."""
     return (util.parsedate(text)[0], util.makedate()[1])
 
+def lower(text):
+    """:lower: Any text. Converts the text to lowercase."""
+    return encoding.lower(text)
+
 def nonempty(str):
     """:nonempty: Any text. Returns '(none)' if the string is empty."""
     return str or "(none)"
@@ -344,6 +348,10 @@
     """
     return indent(text, '\t')
 
+def upper(text):
+    """:upper: Any text. Converts the text to uppercase."""
+    return encoding.upper(text)
+
 def urlescape(text):
     """:urlescape: Any text. Escapes all "special" characters. For example,
     "foo bar" becomes "foo%20bar".
@@ -387,6 +395,7 @@
     "json": json,
     "jsonescape": jsonescape,
     "localdate": localdate,
+    "lower": lower,
     "nonempty": nonempty,
     "obfuscate": obfuscate,
     "permissions": permissions,
@@ -402,6 +411,7 @@
     "strip": strip,
     "stripdir": stripdir,
     "tabindent": tabindent,
+    "upper": upper,
     "urlescape": urlescape,
     "user": userfilter,
     "emailuser": emailuser,
--- a/tests/test-command-template.t	Wed Apr 01 12:50:10 2015 -0700
+++ b/tests/test-command-template.t	Mon Mar 30 23:54:29 2015 +0900
@@ -1871,6 +1871,16 @@
   o  0: children: 1, tags: 0, file_adds: 1, ancestors: 1
   
 
+Upper/lower filters:
+
+  $ hg log -r0 --template '{branch|upper}\n'
+  DEFAULT
+  $ hg log -r0 --template '{author|lower}\n'
+  user name <user@hostname>
+  $ hg log -r0 --template '{date|upper}\n'
+  abort: template filter 'upper' is not compatible with keyword 'date'
+  [255]
+
 Error on syntax:
 
   $ echo 'x = "f' >> t