About
pwt.jinja2js is an extension to the Jinja2 template engine that compiles valid Jinja2 templates containing macros to JavaScript. The JavaScript output can be included via script tags or can be added to the applications JavaScript.
Nutshell
Here a small example of a Jinja template:
{% namespace ns1 %}
{% macro printusers(users) %}
<ul>
{% for user in users %}
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
{% endfor %}
</ul>
{% endmacro %}
Which after running through the pwt.jinja2js compiler we need up the following JavaScript:
if (typeof ns1 == 'undefined') { var ns1 = {}; }
ns1.printusers = function(opt_data, opt_sb, opt_caller) {
var output = '';
output += '\n<ul>\n';
var userList = opt_data.users;
var userListLen = userList.length;
for (var userIndex = 0; userIndex < userListLen; userIndex++) {
var userData = userList[userIndex];
output += '\n <li><a href="' + userData.url + '">' + userData.username + '</a></li>\n';
}
output += '\n</ul>\n';
return output;
}
By slipping a switch we can produce Java Script that takes advantage of Closure Library:
goog.provide('ns1');
goog.require('soy');
ns1.printusers = function(opt_data, opt_sb) {
var output = opt_sb || new soy.StringBuilder();
output.append('\n<ul>\n');
var userList = opt_data.users;
var userListLen = userList.length;
for (var userIndex = 0; userIndex < userListLen; userIndex++) {
var userData = userList[userIndex];
output.append('\n <li><a href="', userData.url, '">', userData.username, '</a></li>\n');
}
output.append('\n</ul>\n');
if (!opt_sb) return output.toString();
}
More user documentation is available on the pwt.jinja2js PyPI package page. The Jinja2 site is also available to learn more about the Jinja2 syntax.
Devloper information
In order to get started with this project and to see what it can do:
git clone git://github.com/mkerrin/pwt.jinja2js.git
cd pwt.jinja2js
python bootstrap
./bin/buildout
Testing
To run the tests run
./bin/test -v
To run a basic server in order to run the JavaScript tests.
./bin/serve –reload
To run the JavaScript tests open a browser and load the url:
http://localhost:8000/
There is links to two test suites from there.
Metadata
Release files for pwt.jinja2js 0.8.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pwt.jinja2js-0.8.1.tar.gz | 68.8 kB | Without provenance | Details for pwt.jinja2js-0.8.1.tar.gz |
Release files / pwt.jinja2js-0.8.1.tar.gz
| Download URL | pwt.jinja2js-0.8.1.tar.gz |
|---|---|
| Size | 68.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
83a7974dcdbc2cf3a7c0c98d8ac3abcd4b5b7d10c3a6bba06197476e44cd647a
|
|
BLAKE2b-256 checksum How to use checksums |
40d9f5d6ef2c82ffff2a77fdb603f8705202b6a7cd68d939a9be986cd17bd437
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pwt.jinja2js 0.8.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.