spirit-handlebars v1.0.1
Spirit Handlebars
Summary
A handlebar template parser middleware for the Spirit Core static file generator.
Usage
Install through npm
( or simply download the file )
npm install spirit-handlebars
To use simply require
it and pass it to the Spirit Core use
function.
var spiritCore = require( 'spirit-core' ) ;
var spiritHandlebars = require( 'spirit-handlebars' ) ;
var spirit = new SpiritCore( ) ;
spirit.use( spiritHandlebars ) ;
Configuration
The middleware will look for optional configuration settings in the Spirit Cores handlebars
config property.
config.handlebars.partials String
:
The relative path to the handlebar partials files.
Default value is /partials
.
config.handlebars.templates String
:
The relative path to the handlebar template files.
Default value is /templates
.
Parsing
The middleware will use the file data's front matter as priority. As such it is recommended you use the Spirit Front Matter in addition with the handlebars middleware, but is not required.
The middleware will parse any file name or templates
front matter data property that a .hb
or .handlebars
extension
and is not in the configured partials
or handlebars
directory. Using the corresponding template to render the file.
The template data is derived by merging the spirit site data Object
with the file data Object
with the file data taking priority.
All the partials will be available globally.
For more information on parsing please visit handlebars module. For more information on file data please see Spirit Files . For more information on the spirit site data please see Spirit Site Data .
Example
In Directory structure
> = Directory
- = File
> "example"
> "src"
- "about.hb"
> "templates"
- "post.handlebars"
> "partials"
- "header.hb"
- "footer.hb"
> "dest"
In header.hb
<html>
<head>
<title>{{title}}</title>
</head>
<body>
In footer.hb
</body>
</html>
In post.handlebars
file
{{> header}}
{{{content}}}
{{> footer}}
In about.hb
---
title : 'About'
template: 'post.handlebars'
---
<h1>This is the About page</h1>
<p>{{descirption}}</p>
Now simply use the middleware
var SpiritCore = require('spirit-core') ;
var spiritFrontMatter = require('spirit-front-matter') ;
var spiritHandlebars = require('spirit-handlebars') ;
var config = {
src : "src",
dest: "dest",
handlebars : {
templates : "templates",
partials : "partials"
},
site : {
data : {
description : "blah blah blah"
}
}
} ;
var spirit = new SpiritCore( "./example", config ) ;
spirit.use( spiritFrontMatter ) ;
spirit.use( spiritHandlebars ) ;
spirit.run( ) ;
The output directory structure.
> = Directory
- = File
> "example"
> "src"
- "about.hb"
> "templates"
- "post.handlebars"
> "partials"
- "header.hb"
- "footer.hb"
> "dest"
- "about.html"
about.html
<html>
<head>
<title>About</title>
<head>
<body>
<h1>This is the About page</h1>
<p>blah blah blah</p>
</body>
</html>
For more information please visit Spirit Core .
Handmade in San Francisco California by Alex Ray .