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

comprise

v0.2.0

Published

Add layout and partial support to consolidate.js!

Downloads

4

Readme

comprise Build Status

Add layout and partial support to consolidate.js!

This project was insprired by all the small projects which wraps a single template engine to integratate these into the express. Many of them exists only because they add the missing layout and partial support which is not provided by consolidate.js.

In many cases this is also fine because the most template engines includes already a simple extend and include mechanism. If not, or if you are interessted in mixing your templates give this project a try.

Comprise add layout and partial support to the great consolidate.js template engine. Means in general that all template engines which could call functions from the template ifself profits from the following functions:

  • Add layout and partial support to your templates.
  • Supports layout hierarchies (post extends default extends layout).
  • Allow setting a default template and override/disable this default in the template itself.
  • Partials use the origin variable by default. Supports also a new scope.
  • Support for mixing template engines (include ejb in jade or vise versa).

Tested with:

Doesn't work yet with:

  • haml -- ! layout('default') and != partial('partial1') does not work. Support welcome!
  • mustache -- {{{ layout 'default' }}} and {{ partial("partial1") }} does not work. Support welcome!

API

var Comprise = require('comprise').Comprise;

var comprise = new Comprise({
	engine: 'jade',
	layout: 'default',
	templateDir: __dirname + '/views'
});

comprise.render('your jade file', { user: user }, function(err, result) {
	if (err) {
		console.error(err);
	} else {
		console.log(result);
	}
});

Available options:

  • engine - See consolidate.js engine list
  • layout - Optional default layout
  • extension - file name extension, default is simular to engine
  • templateDir - Required
  • layoutDir - Optional, default is $templateDir/_layout
  • partialDir - Optional, default is $templateDir/_partials

express framework integration

var comprise = require('comprise');

app.engine('jade', comprise.express({
	engine: 'jade',
	layout: 'default'
}));
app.set('view engine', 'jade');

Available options see API section above.

templateDir was automatically set based on the express setting views (default ./views).

Example

Just render content.jade, but use the common default.jade template which extends the layout.jade.

content.jade template:

h1 This content use the standard layout!

div
	!= partial('partial1')
div
	!= partial('partial2.jade')

layout.jade layout:

html
	head
		title comprise
	body
		!= content()

default.jade included layout:

= layout('layout')

header
	nav navigation code

!= content()

How it works

Comprise provides a simple wrapper around consolidate.js and add four small functions to the local template variables:

  • layout(layout) adds a layout to the current template. Each call adds one to the layout hierachy. To replace a default layout call nolayout first.
  • nolayout() removes a default layout for the current template. You could set another layout with layout.
  • content() need to be called in a layout to insert the surrounded template.
  • partial(partialTemplate[, partialVariables]) could be used to include other templates. In the common case the partial template name don't need a file extension. If a extension is provided a different engine could be used.

Installation

npm install comprise --production

Run the unit tests

npm install --save-dev
npm test

# For code coverage
npm run-script coverjs; open cover_html/index.html
npm run-script istanbul; open coverage/lcov-report/index.html