##// END OF EJS Templates
templater: add consistent docstrings to functions...
Gregory Szorc -
r24586:90e3f5d2 default
parent child Browse files
Show More
@@ -219,6 +219,8 b' def buildfunc(exp, context):'
219 219 raise error.ParseError(_("unknown function '%s'") % n)
220 220
221 221 def date(context, mapping, args):
222 """:date(date[, fmt]): Format a date. See :hg:`help dates` for formatting
223 strings."""
222 224 if not (1 <= len(args) <= 2):
223 225 # i18n: "date" is a keyword
224 226 raise error.ParseError(_("date expects one or two arguments"))
@@ -230,6 +232,8 b' def date(context, mapping, args):'
230 232 return util.datestr(date)
231 233
232 234 def diff(context, mapping, args):
235 """:diff([includepattern [, excludepattern]]): Show a diff, optionally
236 specifying files to include or exclude."""
233 237 if len(args) > 2:
234 238 # i18n: "diff" is a keyword
235 239 raise error.ParseError(_("diff expects one, two or no arguments"))
@@ -247,6 +251,8 b' def diff(context, mapping, args):'
247 251 return ''.join(chunks)
248 252
249 253 def fill(context, mapping, args):
254 """:fill(text[, width[, initialident[, hangindent]]]): Fill many
255 paragraphs with optional indentation. See the "fill" filter."""
250 256 if not (1 <= len(args) <= 4):
251 257 # i18n: "fill" is a keyword
252 258 raise error.ParseError(_("fill expects one to four arguments"))
@@ -270,8 +276,8 b' def fill(context, mapping, args):'
270 276 return templatefilters.fill(text, width, initindent, hangindent)
271 277
272 278 def pad(context, mapping, args):
273 """usage: pad(text, width, fillchar=' ', right=False)
274 """
279 """:pad(text, width[, fillchar=' '[, right=False]]): Pad text with a
280 fill character."""
275 281 if not (2 <= len(args) <= 4):
276 282 # i18n: "pad" is a keyword
277 283 raise error.ParseError(_("pad() expects two to four arguments"))
@@ -296,6 +302,9 b' def pad(context, mapping, args):'
296 302 return text.ljust(width, fillchar)
297 303
298 304 def get(context, mapping, args):
305 """:get(dict, key): Get an attribute/key from an object. Some keywords
306 are complex types. This function allows you to obtain the value of an
307 attribute on these type."""
299 308 if len(args) != 2:
300 309 # i18n: "get" is a keyword
301 310 raise error.ParseError(_("get() expects two arguments"))
@@ -317,6 +326,8 b' def _evalifliteral(arg, context, mapping'
317 326 yield t
318 327
319 328 def if_(context, mapping, args):
329 """:if(expr, then[, else]): Conditionally execute based on the result of
330 an expression."""
320 331 if not (2 <= len(args) <= 3):
321 332 # i18n: "if" is a keyword
322 333 raise error.ParseError(_("if expects two or three arguments"))
@@ -328,6 +339,8 b' def if_(context, mapping, args):'
328 339 yield _evalifliteral(args[2], context, mapping)
329 340
330 341 def ifcontains(context, mapping, args):
342 """:ifcontains(search, thing, then[, else]): Conditionally execute based
343 on whether the item "search" is in "thing"."""
331 344 if not (3 <= len(args) <= 4):
332 345 # i18n: "ifcontains" is a keyword
333 346 raise error.ParseError(_("ifcontains expects three or four arguments"))
@@ -341,6 +354,8 b' def ifcontains(context, mapping, args):'
341 354 yield _evalifliteral(args[3], context, mapping)
342 355
343 356 def ifeq(context, mapping, args):
357 """:ifeq(expr1, expr2, then[, else]): Conditionally execute based on
358 whether 2 items are equivalent."""
344 359 if not (3 <= len(args) <= 4):
345 360 # i18n: "ifeq" is a keyword
346 361 raise error.ParseError(_("ifeq expects three or four arguments"))
@@ -353,6 +368,7 b' def ifeq(context, mapping, args):'
353 368 yield _evalifliteral(args[3], context, mapping)
354 369
355 370 def join(context, mapping, args):
371 """:join(list, sep): Join items in a list with a delimiter."""
356 372 if not (1 <= len(args) <= 2):
357 373 # i18n: "join" is a keyword
358 374 raise error.ParseError(_("join expects one or two arguments"))
@@ -375,6 +391,9 b' def join(context, mapping, args):'
375 391 yield x
376 392
377 393 def label(context, mapping, args):
394 """:label(label, expr): Apply a label to generated content. Content with
395 a label applied can result in additional post-processing, such as
396 automatic colorization."""
378 397 if len(args) != 2:
379 398 # i18n: "label" is a keyword
380 399 raise error.ParseError(_("label expects two arguments"))
@@ -383,8 +402,8 b' def label(context, mapping, args):'
383 402 yield _evalifliteral(args[1], context, mapping)
384 403
385 404 def revset(context, mapping, args):
386 """usage: revset(query[, formatargs...])
387 """
405 """:revset(query[, formatargs...]): Execute a revision set query. See
406 :hg:`help revset`."""
388 407 if not len(args) > 0:
389 408 # i18n: "revset" is a keyword
390 409 raise error.ParseError(_("revset expects one or more arguments"))
@@ -413,6 +432,7 b' def revset(context, mapping, args):'
413 432 return templatekw.showlist("revision", revs, **mapping)
414 433
415 434 def rstdoc(context, mapping, args):
435 """:rstdoc(text, style): Format ReStructuredText."""
416 436 if len(args) != 2:
417 437 # i18n: "rstdoc" is a keyword
418 438 raise error.ParseError(_("rstdoc expects two arguments"))
@@ -423,8 +443,8 b' def rstdoc(context, mapping, args):'
423 443 return minirst.format(text, style=style, keep=['verbose'])
424 444
425 445 def shortest(context, mapping, args):
426 """usage: shortest(node, minlength=4)
427 """
446 """:shortest(node, minlength=4): Obtain the shortest representation of
447 a node."""
428 448 if not (1 <= len(args) <= 2):
429 449 # i18n: "shortest" is a keyword
430 450 raise error.ParseError(_("shortest() expects one or two arguments"))
@@ -475,6 +495,7 b' def shortest(context, mapping, args):'
475 495 return shortest
476 496
477 497 def strip(context, mapping, args):
498 """:strip(text[, chars]): Strip characters from a string."""
478 499 if not (1 <= len(args) <= 2):
479 500 # i18n: "strip" is a keyword
480 501 raise error.ParseError(_("strip expects one or two arguments"))
@@ -486,6 +507,8 b' def strip(context, mapping, args):'
486 507 return text.strip()
487 508
488 509 def sub(context, mapping, args):
510 """:sub(pattern, replacement, expression): Perform text substitution
511 using regular expressions."""
489 512 if len(args) != 3:
490 513 # i18n: "sub" is a keyword
491 514 raise error.ParseError(_("sub expects three arguments"))
@@ -496,6 +519,8 b' def sub(context, mapping, args):'
496 519 yield re.sub(pat, rpl, src)
497 520
498 521 def startswith(context, mapping, args):
522 """:startswith(pattern, text): Returns the value from the "text" argument
523 if it begins with the content from the "pattern" argument."""
499 524 if len(args) != 2:
500 525 # i18n: "startswith" is a keyword
501 526 raise error.ParseError(_("startswith expects two arguments"))
@@ -508,7 +533,7 b' def startswith(context, mapping, args):'
508 533
509 534
510 535 def word(context, mapping, args):
511 """return nth word from a string"""
536 """:word(number, text[, separator]): Return the nth word from a string."""
512 537 if not (2 <= len(args) <= 3):
513 538 # i18n: "word" is a keyword
514 539 raise error.ParseError(_("word expects two or three arguments, got %d")
General Comments 0
You need to be logged in to leave comments. Login now