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

softmotions-jazz

v0.0.19

Published

A simple template engine built specifically for nodejs (forked from shinetech/jazz)

Downloads

7

Readme

Jazz is a simple template engine built specifically for nodejs.

Usage

var jazz = require("jazz");

var template = jazz.compile("my template source code {someVariable}");
template.eval({"someVariable": "lolmuffin"}, function(data) { sys.puts(data); });

This example would output the following:

my template source code lolmuffin

Syntax

Printing variables

{someVariable}

This works for any type of expression, so the following should also work:

{users.fred}
{"hello"}
{45}
{a eq b}

Filter functions

You can call filter functions like so:

{someFilter(arg1, arg2)}

Filter functions are statements, NOT expressions so they cannot be chained nor used in if/forelse/etc. tests. However, calls can be made on any type of expression -- e.g.

{math.sin(45)}

Implementing filter functions

Filter functions may block so rather than returning the value you want rendered as you might in other frameworks, jazz passes in a callback to your filter function that you then call to indicate that you have a result. e.g. here we simulate a blocking operation using setTimeout().

// sum.jazz

{sum(5, 10)}

// sum.js

var sys = require("sys");
var jazz = require("jazz");

var params = {
    sum: function(arg1, arg2, cb) {
        setTimeout(function() {
            cb((arg1 + arg2).toString());
        }, 2000);
    }
}
jazz.compile("sum.jazz").eval(params, function(output) { sys.puts(output); });

Note that even though the execution of the callback is delayed, this example still works.

Conditional Statements

You can check if a variable evaluates to a true value like so:

{if name}
    Hello, {name}
{end}

Else clauses are also supported:

{if name}
    Hello, {name}
{else}
    Hello, Captain Anonymous
{end}

As are else..if clauses:

{if firstName}
    Hello, {firstName}
{elif lastName}
    Hello, Mr. {lastName}
{else}
    Hello, Captain Anonymous
{end}

Limited logical expressions are also possible:

{if user.lastName and user.isVip}
    Hello, Mr. {user.lastName}, my good man!
{end}

{if fred.tired or fred.bored}
    Fred: "Yawn!"
{end}

{if not awake}
    Zzz
{end}

eq & neq comparison operators are available for comparing two values:

{if config.feature eq "enabled"}
    Feature is enabled!
{end}

{if status neq "inactive"}
    Huzzah!
{end}

You can also group expressions using parentheses:

{if (a and b) or c}
    ...
{end}

Looping over an array

{foreach item in someArray}
    <p>{item}</p>
{end}

The value being iterated over can be any expression supporting an Array-like interface.