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

manila

v2.2.2

Published

A simple template engine for Node

Downloads

6

Readme

Manila

Manila is a no-frills template engine for Node 4+.

Installation

npm install manila

Use with Express

// index.js
const app = require('express')(),
	manila = require('manila')();

app.get('/', (req, res) => {
	res.render('index', {
		message: 'Hello, world!'
	});
});

// Pass Manila to Express
app.engine('mnla', manila);
// Register Manila as a view engine
app.set('view engine', 'mnla');
// Set the views directory
app.set('views', './views');

app.listen(3000);
<!-- views/index.mnla -->
<h1><:message:></h1>

Run node index and open http://localhost:3000 in your browser to see the rendered result.

Use with vanilla Node

// index.js
const http = require('http'),
	manila = require('manila')();

http.createServer((req, res) => {

	manila('index.mnla', { message: 'Hello, world!' }, function(err, html) {
		res.writeHead(200, 'text/html; charset=UTF-8');
		res.end(html);
	});

}).listen(3000);
<!-- views/index.mnla -->
<h1><:message:></h1>

Promise Support

When calling manila, you can either provide a callback or use a promise. The following is effectively the same as the example above:

// index.js
const http = require('http'),
	manila = require('manila')();

http.createServer((req, res) => {

	manila('index.mnla', { message: 'Hello, world!' })
		.then(html => {
			res.writeHead(200, 'text/html; charset=UTF-8');
			res.end(html);
		}).catch(err => {
        	console.trace(err);
        });

}).listen(3000);

Configuration

The Manila module accepts a configuration object with the following optional properties:

root: the absolute path to the root of your app. Defaults to the directory which contains the application entry point.

views: the path to the directory in which to look for views, relative to the root. Defaults to 'views'.

partials: the directory in which to look for partial mnla files to use with <: include ... :> tags, realtive to the root. Defaults to views.

extension: the file extension of your views/partials. Defaults to '.mnla'.

// defaults:
const manila = require('manila')({
	root: path.dirname(require.main.filename),
	views: 'views',
	partials: 'views',
	extension: '.mnla'
});

Variables

<:expression:> This tag will be replaced with the HTML-escaped result of evaluating the expression or variable with the current context.

<::expression::> Use two colons instead of one to prevent HTML-escaping of the expression.

Includes

<: include path/to/file :> Includes the content of the named file as part of the current template. path/to/file is relative to views/ unless overwritten during configuration.

Blocks

Manila tags are executed as plain 'ol JavaScript, so there's no template language to learn. While you can use any JavaScript you want, here are some examples:

Conditionals

<: if (expression) { :>
	<p>This markup renders if expression is truthy</p>
<: } else { :>
	<p>This markup renders if expression is falsy</p>
<: } :>

Array Loops

<: list.forEach(item => { :>
	<li><:item:></li>
<: }) :>

Object Loops

<: for (key in obj) { :>
	<li> <:key:> is <:obj[key]:> </li>
<: } :>