Client-side rendering of Twig/Jinja/Jinjs templates.
You can find demos under the /tests
folder:
<script src="lib/jinja.min.js"></script>
<script type="text/jinja" id="standalone">
<h1>Welcome to {{ title|capitalize}}!</h1>
</script>
<script src="lib/jinja.jquery.js"></script>
...
<script>
// Replace #content with rendered template
$('#content').jinja({ title: 'jinja.js' });
</script>
<script>
var script = document.getElementById('standalone');
var template = script.innerHTML;
var context = { title: 'jinja.js' };
var content = Jinja.render(template, context);
document.write(content);
// or
var container = document.createElement('div');
container.innerHTML = content;
script.parentNode.replaceChild(container, script);
</script>
A quick build script is included at bin/build
that will install dependencies, compile & compress:
$ ./bin/build
npm info it worked if it ends with ok
npm info using npm@1.1.0-2
…
Finished!
This will create:
build/build.js
->lib/jinja.js
build/build.min.js
->lib/jinja.min.js
- NodeJS
- npm
- Browserify
- Java (for YUI Compressor)
- Eric Clemmons eric@smarterspam.com