Description
tjst = Tiny JavaScript Templating
High performance JS template engine.
It supports:
Anything you can write on JS =)
Server-side and client-side compilation.
…?
It not supports:
Templates inheritence.
Includes.
…?
Installation
$ git clone https://bitbucket.org/dkuryakin/tjst.git $ cd tjst && python setup.py install
or
$ pip install tjst
Quickstart
tjst supports only <% %> and <%= %> tags.
Suppose, we have file index.html file in some folder:
<!doctype html>
<html>
<head>
<script src="tpl.js"></script>
</head>
<body>
<div id="content"></div>
<script>
var context = {
users: [
{name: "Jeff", online: true, info: "Jeff likes html"},
{name: "Mike", online: true, info: "Mike likes css"},
{name: "Rose", online: false, info: "Rose likes javascript"},
{name: "Anna", online: false, info: "Anna likes perl"},
]
};
document.getElementById('content').innerHTML = templates['tpl.html'](context);
</script>
</body>
</html>
And template file tpl.html in the same folder:
<% for (var i = 0; i < users.length; i++) { %>
<div>
<strong style="color: <%=users[i].online ? 'green' : 'red'%>"><%=users[i].name%></strong> - <%=users[i].info%>
</div>
<% } %>
Install tjst and go to this folder. Compile template:
$ tjst-compile tpl.html tpl.js
Now view index.html in your browser. You can find all examples here: https://bitbucket.org/dkuryakin/tjst/src/HEAD/tjst/examples/
Use as command-line tool
$ tjst-compile -e html,my-tpl-extension /path/to/template/file.html/or/folder /path/to/compiled/file.js
Use in python code
from tjst import compile_text2text, compile_file2file
js = compile_text2text('''
<div>
<% for (var i = 0; i < 10; i++) { %>
<p><%=i%></p>
<% } %>
''')
compile_file2file('templates_file_or_dir_path', 'dst_path.js', ['html', 'txt', 'my-ext'])
Tests
You can run tests with following commands:
$ git clone https://bitbucket.org/dkuryakin/tjst.git $ cd tjst && python setup.py test
Changelog
- v0.1.0
Basic functionality. Py3 support was not tested.
Metadata
Release files for tjst 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tjst-0.1.0.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tjst-0.1.0-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 11.8 kB
Release files / tjst-0.1.0.tar.gz
| Download URL | tjst-0.1.0.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
37af4a0312eaa6108156d175cc4f2eb6c3ecf1c1903fb90f3407ab1e4e25d143
|
|
BLAKE2b-256 checksum How to use checksums |
be3cdaca5eee2cd7b3aeb271f9cf0adf932a1f793b5527b5d52f52a4aacba9d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / tjst-0.1.0-py2-none-any.whl
| Download URL | tjst-0.1.0-py2-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
359ad4fa2d8deaa72ac3e74a0f0548e8501ee9115214cc5aaea086be9914f03b
|
|
BLAKE2b-256 checksum How to use checksums |
a245c6e6c7bfa330cab4fa16494e213c384703fc65dfd3926a05b944aae58649
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |