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

templating

v1.0.1

Published

Asynchronous templating engine for node js

Downloads

14

Readme

#Asynchronous template engine

##Installation

npm install templating

##What it does

Templating is a underscore like template engine for NodeJS that supports asynchronous and synchronous calls. Nested calls (both types) are also possible. Works only on the server side javascript!

##Usage

var templating = require('templating');

Create an instance and pass the template code to it:

var tmplInst = templating.getTemplatingInstance();
var template = tmplInst.template(templateCode, null, {variable: 'data'});

For details how to use Underscore Template Engine look at Underscore documentation http://underscorejs.org/#template

In the example here I use the namespace variable 'data' because it performs much better.

var templateHTML = template({
	param: 'Test string',
	asyncLongFunction: asyncLongFunction,
	asyncShortFunction: asyncShortFunction,
	syncFunction: syncFunction,
	templating: tmplInst,
}, function(callbackHTML) {
	console.log(callbackHTML);
}, this);

Pass the template parameters and functions that you want to use in you template code. Pass also the templating instance if you want to use it in the template code. Callback will be called when all the functions (sync and async) return and the callbackHTML is you parsed result code. You may notice that the function also returns a templateHTML code as a result. It is the same like the callbackHTML if no asynchronous calls were made in the template code. But it there were some the templateHTML result will be invalid or incomplete. Then you should use the callbackHTML result.

##Template code Template code works like undersore templates with one small difference: print function is now a member of the templating instance! So it is important to pass the templating instance as a paramater to use it.

| Code | Output | |<%= data.variable %> | Prints the variable content| |<% data.templating.print(variable) %> | Prints the variable content|

When using syncronous functions you can output the result directly.

Because of delayed output of asyncronous functions the template engine has to wait until the callback is called to process with the further operations. So you have to wrap you callback function in this code:

Instead of:

asyncronousFunction(function(callbackResult) {
	... do something with the callbackResult ...
})

Use

asyncronousFunction(templating.getRegisteredCallbackFunction(function(callbackResult) {
	... do something with the callbackResult ...
}))

That's all!