diff --git a/README.md b/README.md index 4ddaeef..0333640 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,8 @@ Default layout which will be shared with all pages, you can modify as needed but This file contains general Template options - ``exports.outLocation`` : define compiled files destination -- ``exports.helpers`` : define handlebars helpers -- ``exports.partials`` : define handlebars partials -- ``exports.data`` : general data to use with handlebars template engine +- ``exports.handlebars`` : a function accepts handlebars object +- ``exports.data`` : general data to use with handlebars template engine ## Dealing with handlebars @@ -75,6 +74,19 @@ Each page can has it own set of options, *will override global options found in {{/config}} ``` +To define handlebars helpers and partials you need to export handlebars function from local ``init.js`` file + +``For Example`` + +````js +exports.handlebars = function(Handlebars){ + Handlebars.registerPartial({ + header: header.toString(), + footer: footer.toString() + }); +}; +```` + ## Dealing with Less CSS [LESS Elements] is pre installed so you can use it immediately. diff --git a/gruntfile.js b/gruntfile.js index 1dd835f..8b66a8b 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -78,8 +78,11 @@ module.exports = function(grunt) { //go through each page.hbs, and compile var baseLocation = get_file("pages"); var baseDestination = get_file("dist"); + if (init.handlebars && typeof init.handlebars === 'function'){ + init.handlebars(handlebars); + } - var LoopFiles = function(location){ + (function LoopFiles (location){ var rel = path.relative(location, baseLocation); var assets = rel.replace('\\', '/'); if (!assets){ @@ -93,7 +96,7 @@ module.exports = function(grunt) { var hbs = fs.readdirSync(location); var layoutContent = fs.readFileSync(layout); - var template = handlebars.compile(layoutContent.toString("utf8")); + var page_data; var data = (function(){ @@ -118,6 +121,8 @@ module.exports = function(grunt) { continue; } + var template = handlebars.compile(layoutContent.toString("utf8")); + handlebars.registerHelper("config", function(context, options){ var text = context.fn(); page_data = eval ("(" + text + ")"); @@ -144,9 +149,12 @@ module.exports = function(grunt) { handlebars.registerPartial("content", page_out); //split - var filename = hb.split('.')[0] + '.html'; - var out = template(page_data || data); + var f = hb.split('.'); + if (f[1] !== 'hbs'){ continue; } + var filename = f[0] + '.html'; + var out = template(page_data || data); + //FIXME: we compile 2 times just to parse //{{assets}} within global options //there must be a better way to do this @@ -156,9 +164,7 @@ module.exports = function(grunt) { fs.writeFileSync(get_file("dist" + currentDest + filename), out); page_data = null; } - }; - - LoopFiles(baseLocation); + })(baseLocation); }); grunt.initConfig({ diff --git a/less/elements.less b/less/elements.less index 9e45973..4b93afc 100644 --- a/less/elements.less +++ b/less/elements.less @@ -153,4 +153,4 @@ -moz-background-clip: @argument; -webkit-background-clip: @argument; background-clip: @argument; -} \ No newline at end of file +} diff --git a/source/init.js b/source/init.js index b029524..9e7f176 100644 --- a/source/init.js +++ b/source/init.js @@ -1,16 +1,13 @@ //where to compile html pages, (dist) by default exports.outLocation = ''; -//handlebars partials -exports.partials = {}; - -//handlebars helpers -exports.helpers = { - test : function(arg1){} +//handlebars object +exports.handlebars = function(Handlebars) { + }; exports.data = { - //define some javascript files to use with this project + //define some javascript files to use with this project "javascript" : [], //define fonts