GithubHelp home page GithubHelp logo

dldevinc / jinja2-simple-tags Goto Github PK

View Code? Open in Web Editor NEW
33.0 33.0 3.0 49 KB

Base classes for quick-and-easy template tag development

License: BSD 3-Clause "New" or "Revised" License

Python 99.65% HTML 0.35%
django jinja2 templatetags

jinja2-simple-tags's People

Contributors

pix666 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

jinja2-simple-tags's Issues

Can we assign an object instead of a string?

Thanks so much for your work!!

For assignment section: {% hmac 'SECRET', digest='sha1' as signature %}Hello world!{% endhmac %}. Here is the customized tag class:

import hmac
from jinja2_simple_tags import ContainerTag


class HMACExtension(ContainerTag):
    tags = {"hmac"}

    def render(self, secret, digest="sha256", caller=None):
        content = str(caller()).encode()

        if isinstance(secret, str):
            secret = secret.encode()

        signing = hmac.new(secret, content, digestmod=digest)
        return signing.hexdigest()

It seems the last line is required to return a string (i.e., signing.hexdigest()). Do you know if it is possible to be a complex object, such as a Pandas data frame?

Thanks!

Question: ContainerTag implementation

When using ContainerTag, how to access tag contents?
I'd like to do something like this:

{% mytag "myarg" %}

this is some text

{% endmytag %}

I can access tag arguments, but can't figure out how to get to the tag's content ("this is some text") .

Thank you!!

Just wanted to say, thank you so much for this wrapper library!

This saved me so much effort trying to figure out how to use Jinja's extension system and does exactly what I needed.
(And thanks to @mikeabrahamsen for your blog post which led me here!)

Registering with FastAPI

Hi, I am very interested in using this but I can't figure out how to register it for FastAPI. Django made it so easy that I never had to really figure out how to register but I am running into issues when I create a tag and then try to use it elsewhere in my code.

Any tips would be much appreciated!

Unexpected end of template

We use jinja2-simple-tags in a larger context of a website with Pelican and Markdown. Today I've found two issues when trying to use ContainerTag. They both lead to Unexpected end of template. Jinja was looking for the following tags: 'endmessage'. The innermost block that needs to be closed is 'message'.".

  1. I cannot use my message tag as follows:
    {% message %}
    Some message.
    {% endmessage %}
    
    it must be inline
    {% message %}Some message.{% endmessage %}
    
    Adding an html tag also avoids the error:
    {% message %}
    <div>
    Some message.
    </div>
    {% endmessage %} 
    
  2. If I put only a markdown link into the message, there must be a space before the closing tag, for example, {% message %}[Some message.](link) {% endmessage %}.

The details can be viewed in the original MR.

Here's my ContainerTag:

from jinja2_simple_tags import ContainerTag


class MessageExtension(ContainerTag):
    tags = {'message'}

    def render(self, title=None, size='is-normal', caller=None):
        header_template = '''
            <div class="message-header">
                <p>{title}</p>
            </div>
        '''
        message_template = '''
            <article class="message is-info {size}">
            {message_header}
            <div class="message-body">
                {message_body}
            </div>
            </article>
        '''

        message_header = ''
        if title:
            message_header = header_template.format(title=title)
        return message_template.format(
            size=size,
            message_header=message_header,
            message_body=caller()
        )

Would you consider adding a "Inclusion Tag"?

Hi and first of all thanks a lot for this project!

I am going to develop an equivalent of the InclusionTag as found in django-classy-tags based on this project.

I can either put it in an independent project or, if you are interested, contribute to this project.

I would, of course, follow your code styles, provide unit tests and be open to feedback.

What do you say?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.