Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
allmarkedup committed Jan 14, 2016
1 parent f2289ad commit dad61e6
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# handlebars-engine
Use Handlebars templates with Fractal
# Handlebars Engine

Use Handlebars templates with Fractal.
46 changes: 46 additions & 0 deletions engine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

var Handlebars = require('handlebars');
var _ = require('lodash');

module.exports = {

/**
* Initialise the Handlebars instance.
* Register any custom helpers and partials set in the config.
*/

init: function(config){
var extras = config.extend || {};
_.each(extras.helpers || {}, function(helper, name){
Handlebars.registerHelper(name, helper);
});
_.each(extras.partials || {}, function(partial, name){
Handlebars.registerPartial(name, partial);
});
},

/**
* Register component view templates as partials.
* Called every time the component file tree changes.
*/

registerViews: function(views) {
views.forEach(function(view){
Handlebars.registerPartial(view.handle, view.content);
if (view.alias) {
Handlebars.registerPartial(view.alias, view.content);
}
});
},

/**
* Render the component view contents.
*/

render: function(str, context, meta) {
var template = Handlebars.compile(str);
return template(context);
}

};
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@frctl/handlebars-engine",
"version": "0.1.0",
"description": "Use Handlebars templates with Fractal.",
"main": "engine.js",
"repository": {
"type": "git",
"url": "https://github.com/frctl/handlebars-engine.git"
},
"author": "Clearleft <[email protected]> (http://clearleft.com/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/frctl/handlebars-engine/issues"
},
"homepage": "https://github.com/frctl/handlebars-engine",
"dependencies": {
"handlebars": "^4.0.5",
"lodash": "^4.0.0"
},
"devDependencies": {}
}

0 comments on commit dad61e6

Please sign in to comment.