JSIN - Javascript Include
Template engine for use at server and client side.
Features
- Well-known PHP-like template tags.
- Accurate quote parsing.
- Asynchronous compiling of templates on the fly.
- Pre-compiling for use in browser.
- Supports includings and layoutings.
Usage
Syntax
Constructions:
<?js /* any javascript code */ ?>
<?= /* print value or result of expression */ ?>
<?h= /* print value or result of expression with escaped html special chars <>&" */ ?>
<?s= /* print value or result of expression with backslashed script special chars \\n\r"' */ ?>
Functions:
print(string)
printh(string, [apos])
- if setapos
totrue
, then apostrophe'
will be escaped instead of quotes"
.prints(string)
include(template, [data])
layout(template, [data], callback)
contents()
Example
<!-- mytemplate.jsin -->Example <?= "Check ?>'\" special chars and variable " + boo ?> <?h= "Check html escaping &<>\"" ?> <?s= "Check script escaping \\\n\r\"\'" ?> <?js if (1 === 1) { ?> 1 === 1 <?js } else { ?> 1 !== 1 <?js } ?><?js include('include'); print("Example print\n"); ?><?js layout('layout', function(){ ?> Example layout inside <?js include('layout-include-inside') ?> <?js }) ?> Thanx!
<!-- layout.jsin --> Example layout begin with variable <?= boo ?> <?js contents() ?> <?js include('layout-include') ?> Example layout end
Server side
var jsin = ; jsin; // you can omit extension .jsinjsin;
Client side
Compile client-side script using jsinc
command-line tool:
$ jsinc path/to/*.jsin jsin.compiled.js
or
$ jsinc -d path/to/jsin/dir jsin.compiled.js
Options:
-d
- compile all files in directory and subdirectories, excluding this directory from template names.-t
- compile templates only, exclude definition of jsin object.-b
- beautify.-u
- uglify.
In browser:
License
Copyright © 2014 Maksim Krylosov Aequiternus@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.