This repository has been archived by the owner on Jul 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2289ad
commit dad61e6
Showing
4 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} |