Ticket #4760: 20070703_BuiltinLibrary.patch

File 20070703_BuiltinLibrary.patch, 1.0 KB (added by A. J. Ellerton <aj@…>, 17 years ago)

Patch file

  • __init__.py

     
    912912            return func
    913913        return dec
    914914
     915class BuiltinLibrary(Library):
     916    """
     917    Same as Library class but automatically registers filters/tags with DJango.
     918   
     919    Example filter::
     920   
     921      def filter_rst_h1(value, arg='-'):
     922        "Write a single underline under the text"
     923        line=arg * len(value)
     924        return "%s\n%s" % (value, line)
     925   
     926    To use this filter, do this::
     927   
     928      from django.template import BuiltinLibrary # <-- NEW!
     929   
     930      # set up extra library of routines for later use...
     931      library = BuiltinLibrary()
     932      library.filter('filter_rst_h1', filter_rst_h1)
     933    """
     934    def __init__(self, *args, **kwargs):
     935        Library.__init__(self, *args, **kwargs)
     936        builtins.append(self)
     937
    915938def get_library(module_name):
    916939    lib = libraries.get(module_name, None)
    917940    if not lib:
Back to Top