Patchwork [1,of,2] templater: add no-op template function 'label'

login
register
mail settings
Submitter Sean Farley
Date Dec. 29, 2012, 1:30 a.m.
Message ID <f80de1a51abf62994016.1356744621@laptop.local>
Download mbox | patch
Permalink /patch/328/
State Accepted
Commit 9bfb53106328743a2c5879b0f399d6fd7cfe59b6
Delegated to: Bryan O'Sullivan
Headers show

Comments

Sean Farley - Dec. 29, 2012, 1:30 a.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1356234386 21600
# Node ID f80de1a51abf6299401672ce29ae38b1c192e3ec
# Parent  8019f96ec4ce96f97dde775fe6f45007f29dabc3
templater: add no-op template function 'label'
Bryan O'Sullivan - Jan. 8, 2013, 10:57 p.m.
On Fri, Dec 28, 2012 at 07:30:21PM -0600, Sean Farley wrote:
> templater: add no-op template function 'label'

It's not clear to me what this patch series is supposed to do. Could
you clarify in the comments, please?
Sean Farley - Jan. 9, 2013, 7:31 p.m.
On Tue, Jan 8, 2013 at 4:57 PM, Bryan O'Sullivan <bos@serpentine.com> wrote:
> On Fri, Dec 28, 2012 at 07:30:21PM -0600, Sean Farley wrote:
>> templater: add no-op template function 'label'
>
> It's not clear to me what this patch series is supposed to do. Could
> you clarify in the comments, please?

Sure, no problem. FYI, it's for adding the ability to label (and hence
colorize) template output.

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -263,10 +263,19 @@ 
         yield runtemplate(context, mapping, compiletemplate(t, context))
     elif len(args) == 4:
         t = stringify(args[3][0](context, mapping, args[3][1]))
         yield runtemplate(context, mapping, compiletemplate(t, context))
 
+def label(context, mapping, args):
+    if len(args) != 2:
+        # i18n: "label" is a keyword
+        raise error.ParseError(_("label expects two arguments"))
+
+    # ignore args[0] (the label string) since this is supposed to be a a no-op
+    t = stringify(args[1][0](context, mapping, args[1][1]))
+    yield runtemplate(context, mapping, compiletemplate(t, context))
+
 methods = {
     "string": lambda e, c: (runstring, e[1]),
     "symbol": lambda e, c: (runsymbol, e[1]),
     "group": lambda e, c: compileexp(e[1], c),
 #    ".": buildmember,
@@ -278,10 +287,11 @@ 
 funcs = {
     "if": if_,
     "ifeq": ifeq,
     "join": join,
     "sub": sub,
+    "label": label,
 }
 
 # template engine
 
 path = ['templates', '../templates']