Templated layout builders
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.npmignore
.travis.yml
Makefile
index.ls
package.json
readme.md
test.ls

readme.md

Brio Build Status

Templated layout builders.

npm install brio

brio

Usage

(Pretending that Javascript has multiline strings)

var brio = require('brio'), handlebars = require('handlebars');

var pages = brio(handlebars, {
	base: `<!doctype html>
	<html>
		<head>
			<title>{{page.title}}</title>
		</head>
		<body>
		{{{body}}}
		</body>
	</html>`,
	page: `---
	layout: 'base'
	---
	<h1>{{page.title}}</h1>
	<main>
	{{{body}}}
	</main>`,
	site: {
		home: `---
		title: 'Home',
		layout: 'page'
		---

		Welcome!`,
		post: `---
		title: 'Post'
		layout: 'page'
		---

		<h2>{{post.title}}</h2>
		<article>{{post.content}}</article>`
	}
});

pages('site.home', {}); /*⇒ <!doctype html>
	<html>
		<head>
			<title>Home</title>
		</head>
		<body>
		<h1>Home</h1>
			<main>
			Welcome!
			</main>
		</body>
	</html>
*/

pages('site.post', {post: {title: 'Hello world', content: 'Lorem ipsum dolor sit amet'}); /*⇒ <!doctype html>
	<html>
		<head>
			<title>Post</title>
		</head>
		<body>
		<h1>Post</h1>
			<main>
			<h2>Hello world</h2>
			<article>Lorem ipsum dolor sit amet</article>
			</main>
		</body>
	</html>
*/

API

brio :: (Template → Params → String) → Tree String Template → Path → Params → String

Takes a templater, a tree of templates, a path to a template, some params and spits out a compiled string.

Templaters

Are any curried function taking a template and some parameters and returning a string. Handlebars fits nicely, as does _.template.

Licence

MIT. © 2014 Matt Brennan.