New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

comprise

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

comprise

Add layout and partial support to consolidate.js!

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-57.14%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 22 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc