dldevinc / jinja2-simple-tags Goto Github PK
View Code? Open in Web Editor NEWBase classes for quick-and-easy template tag development
License: BSD 3-Clause "New" or "Revised" License
Base classes for quick-and-easy template tag development
License: BSD 3-Clause "New" or "Revised" License
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!
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") .
How does one go about creating a tag like this one?
{% tag() %}
{% else %}
{% endtag %}
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!)
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!
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'.".
{% message %}
Some message.
{% endmessage %}
{% message %}Some message.{% endmessage %}
{% message %}
<div>
Some message.
</div>
{% endmessage %}
{% 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()
)
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.