281 |
281 |
282 Usage:: |
282 Usage:: |
283 |
283 |
284 templatekeyword = registrar.templatekeyword() |
284 templatekeyword = registrar.templatekeyword() |
285 |
285 |
|
286 # new API (since Mercurial 4.6) |
|
287 @templatekeyword('mykeyword', requires={'repo', 'ctx'}) |
|
288 def mykeywordfunc(context, mapping): |
|
289 '''Explanation of this template keyword .... |
|
290 ''' |
|
291 pass |
|
292 |
|
293 # old API |
286 @templatekeyword('mykeyword') |
294 @templatekeyword('mykeyword') |
287 def mykeywordfunc(repo, ctx, templ, cache, revcache, **args): |
295 def mykeywordfunc(repo, ctx, templ, cache, revcache, **args): |
288 '''Explanation of this template keyword .... |
296 '''Explanation of this template keyword .... |
289 ''' |
297 ''' |
290 pass |
298 pass |
291 |
299 |
292 The first string argument is used also in online help. |
300 The first string argument is used also in online help. |
293 |
301 |
|
302 Optional argument 'requires' should be a collection of resource names |
|
303 which the template keyword depends on. This also serves as a flag to |
|
304 switch to the new API. If 'requires' is unspecified, all template |
|
305 keywords and resources are expanded to the function arguments. |
|
306 |
294 'templatekeyword' instance in example above can be used to |
307 'templatekeyword' instance in example above can be used to |
295 decorate multiple functions. |
308 decorate multiple functions. |
296 |
309 |
297 Decorated functions are registered automatically at loading |
310 Decorated functions are registered automatically at loading |
298 extension, if an instance named as 'templatekeyword' is used for |
311 extension, if an instance named as 'templatekeyword' is used for |
299 decorating in extension. |
312 decorating in extension. |
300 |
313 |
301 Otherwise, explicit 'templatekw.loadkeyword()' is needed. |
314 Otherwise, explicit 'templatekw.loadkeyword()' is needed. |
302 """ |
315 """ |
|
316 |
|
317 def _extrasetup(self, name, func, requires=None): |
|
318 func._requires = requires |
303 |
319 |
304 class templatefilter(_templateregistrarbase): |
320 class templatefilter(_templateregistrarbase): |
305 """Decorator to register template filer |
321 """Decorator to register template filer |
306 |
322 |
307 Usage:: |
323 Usage:: |