npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rein

v0.1.5

Published

A fast and easy-to-use template language for every langauge (XML, HTML, SQL, CSS)

Downloads

3

Readme

Rein.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

NodeJS

for NodeJS you first need to install it with the following command and then you can go wild!

npm i rein

Web

and for the web you need add Rein(.min).js to your page, (note that compiling a template takes more time then just executing it, f.x. a different template langauge may be faster in compiling the template but is most likely not faster in executing it, so its recommend to compile the templates serverside)

Examples

Compiling server side and executing client side

Server.js

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

// 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

// 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 <strong>{{nr}}</strong>");
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!

Example

{{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

Example

{[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)

License

Rein.js is licensed under the MIT License (see LICENSE)