<commit_before>.. module:: shrubbery.utils
.. _utils_templatetags:

============================
shrubbery.utils.templatetags
============================
   
Provides a template library called ``shrubbery_utils``.
<commit_msg>Initial docs for shrubbery.utils.templatetags<commit_after>.. module:: shrubbery.utils
.. _utils_templatetags:

============================
shrubbery.utils.templatetags
============================
   
Provides a template library called ``shrubbery_utils``.

Filters
=======

concat
    ``lambda a, b: "%s%s" % (a, b))``

contains
    ``lambda a, b: b in a``

in
    ``lambda a, b: a in b``

eq
    ``lambda a, b: a == b``

lt
    ``lambda a, b: a < b``

le
    ``lambda a, b: a <= b``

gt
    ``lambda a, b: a > b``

ge
    ``lambda a, b: a >= b``

add
    ``lambda a, b: a + b``

sub
    ``lambda a, b: a - b``

mul
    ``lambda a, b: a * b``

neg
    ``lambda a: -a``

invert
    ``lambda a: ~a``

pair
    ``lambda a, b: (a, b)``

get
    ``lambda a, b: a.get(b)``

getattr
    ``lambda a, b: getattr(a, b, '')``

getitem
    ``lambda a, b: a[b]``

repeat
    ``lambda a, b: mark_safe(unicode(a) * b)``

range
    ``lambda n: xrange(n)``

sum:[attr]
    ``sum(a)``. If ``attr`` is given: ``sum([getattr(x, attr) for x in a])``.

min:[attr]
    ``min(a)``. If ``attr`` is given: ``min([getattr(x, attr) for x in a])``.

max:[attr]
    ``max(a)``. If ``attr`` is given: ``max([getattr(x, attr) for x in a])``.
    
widont
    joins the last two words of its input with ``'\u00A0'`` (non-breaking space). Django's autoescaping will turn this into ``'&nbsp;'``.

widont_html
    joins the last two words of its input with ``'&nbsp;'`` and leaves html tags intact.

Tags
====

{% getvars %}
~~~~~~~~~~~~~

Requires the `request context processor <http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-request>`_.

.. code-block:: django
    
    <!-- querystring: foo=1&bar=2 -->
    {% getvars %} will render the querystring as-is: foo=1&bar=2
    {% getvars baz=3 %} will add baz=3: foo=1&bar=2&baz=3
    {% getvars foo=4 %} will replace foo: foo=4&bar=2
    {% getvars foo+=4 %} will add foo=42: foo=1&foo=4&bar=2
    {% getvars foo+=4 bar=5 baz=3 %} will result in foo=1&foo=4&bar=5&baz=3
    
    
{'fraction_non_alphanumeric': 0.23784261715296198, 'fraction_numerical': 0.01237842617152962, 'mean_word_length': 3.351923076923077, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5187530', 'n_tokens_mistral': 897, 'n_tokens_neox': 867, 'n_words': 252}