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

mustlayout

v0.2.0

Published

A layout and partials pre-compile tool for mustache based template engine using in express.

Downloads

14

Readme

MustLayout

简体中文

This package is for express.js 3.0+ (4.0+ also supported) users who want to use layout and partial in mustache based (mustache, hogan, handlebars) template engines, with only a really simple configuration.

A few features:

  • Same usage to render template in your controller as before.
  • Never need to manage partial and layout variable when render.
  • Compatible for all mustache based template engines.

Installation

$ npm install --save mustlayout

Usage

In your express application main file app.js:

var express = require('express');

var app = express();

require('mustlayout').engine(app, {
    engine: require('hogan'),
    ext: '.tpl',
    views: '/views',
    partials: '/views/partials', // optional, default to '/views'
    layouts: '/views/layouts', // optional, default to '/views'
    cache: '/views/cache', // optional, default to '/views/cache'
    verbose: true // optional, default is false
});

app.get('/', function (req, res, next) {
    res.render('index');
});

app.listen(6060);

By using MustLayout, you never need to write the native view engine configuration of express.

For more infomation just look into the example folder.

Syntax

MustLayout use handlebars' syntax {{!<layoutName}} for layout definition in a template file. Ordinarily, you should place this line at the beginning of your template file.

Then use {{+blockName}}...{{/blockName}} to define a extensible layout block like in Smarty.

An example for template index.tpl which extended layout page.tpl:

{{!<page}}
{{+header}}
<h1>My Title</h1>
{{/header}}

{{+body}}
...
{{/body}}

And in layout page.tpl:

<!DOCTYPE html>
<html>
<head>
<title>MustLayout</title>
</head>
<body>
<div id="header">
{{+header}}Just Header{{/header}}
</div>
<div id="main">
{{+body}}Nothing{{/body}}
</div>
{{> footer }}
</body>
</html>

After you invoke res.render('index') in a controller, you will get this in browser:

<!DOCTYPE html>
<html>
<head>
<title>MustLayout</title>
</head>
<body>
<div id="header">
<h1>My Title</h1>
</div>
<div id="main">
...
</div>
<!-- something in footer.tpl -->
</body>
</html>

cache

MustLayout build all your templates to a target cache folder (cache for default) in /views. So you must make sure that /views should be writable for everyone:

$ chmod 777 views/

And by building, layout and partial syntax will be pre-compiled into common mustache based templates in that folder before server starting. You should never worried about the performance of rendering layouts, because it only depends on what mustache engine you are using.

Troubleshooting

  1. Gmail me: mytharcher
  2. Write a issue
  3. Send your pull request to me.

MIT Licensed

-EOF-