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

ongine

v0.0.3

Published

JSON-based template engine.

Downloads

2

Readme

Ongine

JSON-based template engine.

Features

  • JSON representation of HTML documents
  • HTML5 optimized
  • Raw text support
  • Conditions, iterations and inclusions through API
  • Multi outputs : string, buffer, stream
  • Pretty human-readable output options
  • Mold filling system

Installation

npm install ongine

Usage

ongine(view, fillers, options);

  • view : Object | Array | String
  • fillers : Object
  • options : Object

Description

The module function expects up to 3 arguments and return a string by default.

The first argument view can be either an object representing a template, or an array containing a set of template objects and/or strings (which will be rendered as raw text), or a string, in which case the engine will considered it as the filename of the template file. The full path of this file will be built from options.views (views directory path) and options.extension (template files extension).

The second argument fillers is an object containing the data which will be injected in template raw texts using the mold filling system. Each property can have any name and any value but these values will be rendered as string. This argument is optional but if there are molds refering to unexisting fillers, they will be replaced by 'undefined'.

The last argument options is an object containing a set of properties defining the global configuration of the engine for the rendering (these options override the default ones). This argument is optional. Options list is available in documentation.

For further information, see documentation.

Examples

Hello World

var render = require('ongine');
var html = render(
	{
		'tag' : 'p',
		'attributes' : {'id' : 'hello'},
		'in' : 'Hello World'
	},
	null,
	{
		'wrap' : false,
		'doctype' : false
	}
);

Output

<p id="hello">Hello World</p>

Basic HTML5 page

var render = require('ongine');

var view = {
	'tag' : 'html',
	'in' : [
		{
			'tag' : 'head',
			'in' : {'tag' : 'title', 'in' : '{{title}}'}
		},
		{
			'tag' : 'body',
			'in' : {'tag' : 'p', 'in' : '{{message}}'}
		}
	]
};

var fillers = {
	'title' : 'Home',
	'message' : 'Welcome to homepage.'
};

var options = {
	'wrap' : false,
	'pretty' : true
}

var html = render(view, fillers, options);

Output

<!DOCTYPE HTML>
<html>
	<head>
		<title>
			Home
		</title>
	</head>
	<body>
		<p>
			Welcome to homepage.
		</p>
	</body>
</html>

API sample

var render = require('ongine');

var view = [];
view.push(
	{
		'api' : 'if',
		'in' : {
			'condition' : '{{foo}}',
			'in' : '<p>fillers.foo returns true</p>'
		}
	},
	{
		'api' : 'if',
		'in' : [
			{
				'condition' : '{{bar}}',
				'in' : '<p>fillers.bar returns true</p>'
			},
			{
				'default' : true,
				'in' : '<p>fillers.bar does not return true</p>'
			}
		]
	}
);

var fillers = {
	'foo' : true,
	'bar' : false
};

var options = {
	'wrap' : false,
	'pretty' : true
};

var html = render(view, fillers, options);

Output

<!DOCTYPE HTML>
<p>fillers.foo returns true</p>
<p>fillers.bar does not return true</p>

Caution

Ongine is currently an experimental module. Please, use it as such.

This engine is intended to be server-side only.

The conditional nodes of the API are parsed with an unsafe eval(). Therefore, never render templates sent by clients, because an attacker would be able to execute JavaScript code on the server, specifying it in the condition/case property of the if/switch node. This evil will be banned in future releases.

The API syntax will evolve in next releases.