Metadata-Version: 2.1
Name: jinja2-simple-tags
Version: 0.2.2
Summary: Base classes for quick-and-easy template tag development
Home-page: https://github.com/dldevinc/jinja2-simple-tags
Author: Mihail Mishakin
Author-email: x896321475@gmail.com
Maintainer: Mihail Mishakin
Maintainer-email: x896321475@gmail.com
License: BSD
Description: # jinja2-simple-tags
        Base classes for quick-and-easy template tag development
        
        ## Installation
        `pip install jinja2-simple-tags`
        
        ## Examples
        
        ### `StandaloneTag`
        ```python
        from django.utils.timezone import now
        from django.utils.formats import date_format
        from jinja2_simple_tags import StandaloneTag
        
        
        class NowExtension(StandaloneTag):
            tags = {"now"}
        
            def render(self, format_string='DATETIME_FORMAT'):
                return date_format(now(), format_string)
        ```
        
        Usage:
        ```jinja2
        {% now %}           {# 7th July 2020, 10:07 a.m. #}
        {% now "Y-m-d" %}   {# 2020-07-07 #}
        ```
        
        
        ### `ContainerTag`
        ```python
        from django.core.cache import cache
        from django.utils.encoding import force_str
        from django.core.cache.utils import make_template_fragment_key
        from jinja2_simple_tags import ContainerTag
        
        
        class CacheExtension(ContainerTag):
            tags = {"cache"}
        
            def render(self, fragment_name, *vary_on, timeout=None, caller=None):
                cache_key = make_template_fragment_key(fragment_name, vary_on)
        
                value = cache.get(cache_key)
                if value is None:
                    value = caller()
                    cache.set(cache_key, force_str(value), timeout)
                else:
                    value = force_str(value)
        
                return value
        ```
        
        Usage:
        ```jinja2
        {% cache "footer", request.path, timeout=3600 %}
          <footer>
            ...
          </footer>
        {% endcache %}
        ```
        
        ### Context
        Current context is available through the `self.context`.
        
        ```python
        from django.urls import reverse
        from jinja2_simple_tags import StandaloneTag
        
        
        class AbsoluteURITag(StandaloneTag):
            tags = {'absolute_uri'}
        
            def render(self, name):
                request = self.context['request']
                url = reverse(name)        
                return request.build_absolute_uri(url)
        ```
        
        ### Assignment
        Both `StandaloneTag` and `ContainerTag` comes with out-of-the-box 
        support for assignment.
        
        Usage:
        ```jinja2
        {% now "Y-m-d" as today %}
        ...
        {{ today }}       {# 2020-07-07 #}
        ```
        
        ```jinja2
        {% cache "footer", request.path, timeout=3600 as footer %}
          <footer>
            ...
          </footer>
        {% endcache %}
        ...
        {{ footer }}
        ```
        
Platform: OS Independent
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Provides-Extra: testing
