Show More
@@ -37,6 +37,7 b' from . import (' | |||
|
37 | 37 | revset, |
|
38 | 38 | templatefilters, |
|
39 | 39 | templatekw, |
|
40 | templater, | |
|
40 | 41 | ui as uimod, |
|
41 | 42 | util, |
|
42 | 43 | ) |
@@ -768,6 +769,7 b' extraloaders = [' | |||
|
768 | 769 | ('filesetpredicate', fileset, 'loadpredicate'), |
|
769 | 770 | ('revsetpredicate', revset, 'loadpredicate'), |
|
770 | 771 | ('templatefilter', templatefilters, 'loadfilter'), |
|
772 | ('templatefunc', templater, 'loadfunction'), | |
|
771 | 773 | ('templatekeyword', templatekw, 'loadkeyword'), |
|
772 | 774 | ] |
|
773 | 775 |
@@ -216,3 +216,29 b' class templatefilter(_templateregistrarb' | |||
|
216 | 216 | |
|
217 | 217 | Otherwise, explicit 'templatefilters.loadkeyword()' is needed. |
|
218 | 218 | """ |
|
219 | ||
|
220 | class templatefunc(_templateregistrarbase): | |
|
221 | """Decorator to register template function | |
|
222 | ||
|
223 | Usage:: | |
|
224 | ||
|
225 | templatefunc = registrar.templatefunc() | |
|
226 | ||
|
227 | @templatefunc('myfunc(arg1, arg2[, arg3])') | |
|
228 | def myfuncfunc(context, mapping, args): | |
|
229 | '''Explanation of this template function .... | |
|
230 | ''' | |
|
231 | pass | |
|
232 | ||
|
233 | The first string argument is used also in online help. | |
|
234 | ||
|
235 | 'templatefunc' instance in example above can be used to | |
|
236 | decorate multiple functions. | |
|
237 | ||
|
238 | Decorated functions are registered automatically at loading | |
|
239 | extension, if an instance named as 'templatefunc' is used for | |
|
240 | decorating in extension. | |
|
241 | ||
|
242 | Otherwise, explicit 'templater.loadfunction()' is needed. | |
|
243 | """ | |
|
244 | _getname = _funcregistrarbase._parsefuncdecl |
@@ -1069,5 +1069,11 b' def stylemap(styles, paths=None):' | |||
|
1069 | 1069 | |
|
1070 | 1070 | raise RuntimeError("No hgweb templates found in %r" % paths) |
|
1071 | 1071 | |
|
1072 | def loadfunction(ui, extname, registrarobj): | |
|
1073 | """Load template function from specified registrarobj | |
|
1074 | """ | |
|
1075 | for name, func in registrarobj._table.iteritems(): | |
|
1076 | funcs[name] = func | |
|
1077 | ||
|
1072 | 1078 | # tell hggettext to extract docstrings from these functions: |
|
1073 | 1079 | i18nfunctions = funcs.values() |
@@ -3693,3 +3693,26 b' utf8 filter:' | |||
|
3693 | 3693 | [255] |
|
3694 | 3694 | |
|
3695 | 3695 | $ cd .. |
|
3696 | ||
|
3697 | Test that template function in extension is registered as expected | |
|
3698 | ||
|
3699 | $ cd a | |
|
3700 | ||
|
3701 | $ cat <<EOF > $TESTTMP/customfunc.py | |
|
3702 | > from mercurial import registrar | |
|
3703 | > | |
|
3704 | > templatefunc = registrar.templatefunc() | |
|
3705 | > | |
|
3706 | > @templatefunc('custom()') | |
|
3707 | > def custom(context, mapping, args): | |
|
3708 | > return 'custom' | |
|
3709 | > EOF | |
|
3710 | $ cat <<EOF > .hg/hgrc | |
|
3711 | > [extensions] | |
|
3712 | > customfunc = $TESTTMP/customfunc.py | |
|
3713 | > EOF | |
|
3714 | ||
|
3715 | $ hg log -r . -T "{custom()}\n" --config customfunc.enabled=true | |
|
3716 | custom | |
|
3717 | ||
|
3718 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now