A fast and easy-to-use template language for every langauge (XML, HTML, SQL, CSS)
npm install reinRein.js
=======
One of the fastest and easy-to-use template language for every langauge (XML, HTML, SQL, CSS)
Why the weird name?
====
Rein is german/dutch for clean, neat and that was exactly the goal of this project, create a clean and neat template language.
What is it?
=====
It's another template langauge! It originally was a template langauge for SQL. but after I ported it to JavaScript, it became suitable for HTML too! and after some tweaking it became one of the fastest template engines there is
When should I use it?
====
When you need a simple, lightweight and superfast template engine, that can be used server side but also client side
How do I use it
====
npm i rein
javascript
var fs = require('fs');
var rein = require('rein');
var templates = {
list:rein(fs.readFileSync('./list.rein')),
friends:rein(fs.readFileSync('./friends.rein'))
};
// createBundle will make a little javascript script
// with the compiled templates ready to execute client side
// via the ReinBundle function, so if you send jsCode
// to your client and execute it there
// you can fully use that as described in Client.js
var jsCode = rein.createBundle(templates);
`
Client.js
`javascript
// ReinBundle takes 2 arguments, id and args
// the id is from the object which is used to generate
// this bundle.
var html = ReinBundle('list',{ items:["soap","shampoo","wig"] });
`
Compiling and executing client side
`javascript
// The client side version is very simple
// with Rein you build your template
// and with Template.parse you (compile and) execute it
var tpl = Rein("Your are customer {{nr}}");
var html = tpl.parse({nr:425});
`
Template syntax
==
The template syntax is simple, easy to use and fluid. at least, I tried to make it that way.
Variables
variables just work as you expect them to work, you can also execute functions and all the things you would normally do between a ( and )
`
I'm {{name}} and I'm {{age}} old, I'm a {{gender.name}}, and {{this()}} is my weapon!
`
If
if's are structured like {{ expression : MOAR TEMPLATE }}, well that's simple isn't it?!
There is currently no else :( I will work on that!
$3
`
{{gotKids && doIReallyGotKids():
I got like {{numKids}} kids! You can have {{ numKids - ((numKids + hisNumKids)/2) }} kids from me if you want?
}}
`
For
for loops are almost like if's {[ variable : TEMPLATE INCEPTION ]}, it won't get much harder!
Although there are some things you need to know!
first off we reset the scope of the for to the current object we are looping on, so be aware of that!
we also add the following variables to the for scope, I mean, these could be usefull, sometimes, like when you need it.
__i: current index
__amount: length of current array
__first: returns true if this is the first element
__last: returns true if this is the last element
$3
`
{[arr:
Im {{__first: the first }} looping: {{this}}
{{__last: bye bye!}}
]}
`
Well. that's it! now create your own neat adventures! and be sure to give some (supportive) feedback.
API
===
Rein(tpl) alias for Rein.build(tpl)
Rein(tpl,vars) alias for Rein.build(tpl).parse(vars)
* .createBundle(tplobj) returns code for the client with a bundle of template code
* .build(tpl) build template and return Rein.Template object
* .Template template object
* .parse(vars) parses template and returns a string with the parsed template
* .compile() compiles template to 1 function, which works like .parse(vars)`