inlinefuncs.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """
  2. Inlinefunc
  3. Inline functions allow for direct conversion of text users mark in a
  4. special way. Inlinefuncs are deactivated by default. To activate, add
  5. INLINEFUNC_ENABLED = True
  6. to your settings file. The default inlinefuncs are found in
  7. evennia.utils.inlinefunc.
  8. In text, usage is straightforward:
  9. $funcname([arg1,[arg2,...]])
  10. Example 1 (using the "pad" inlinefunc):
  11. say This is $pad("a center-padded text", 50,c,-) of width 50.
  12. ->
  13. John says, "This is -------------- a center-padded text--------------- of width 50."
  14. Example 2 (using nested "pad" and "time" inlinefuncs):
  15. say The time is $pad($time(), 30)right now.
  16. ->
  17. John says, "The time is Oct 25, 11:09 right now."
  18. To add more inline functions, add them to this module, using
  19. the following call signature:
  20. def funcname(text, *args, **kwargs)
  21. where `text` is always the part between {funcname(args) and
  22. {/funcname and the *args are taken from the appropriate part of the
  23. call. If no {/funcname is given, `text` will be the empty string.
  24. It is important that the inline function properly clean the
  25. incoming `args`, checking their type and replacing them with sane
  26. defaults if needed. If impossible to resolve, the unmodified text
  27. should be returned. The inlinefunc should never cause a traceback.
  28. While the inline function should accept **kwargs, the keyword is
  29. never accepted as a valid call - this is only intended to be used
  30. internally by Evennia, notably to send the `session` keyword to
  31. the function; this is the session of the object viewing the string
  32. and can be used to customize it to each session.
  33. """
  34. # def capitalize(text, *args, **kwargs):
  35. # "Silly capitalize example. Used as {capitalize() ... {/capitalize"
  36. # session = kwargs.get("session")
  37. # return text.capitalize()