Skip to content

Commit

Permalink
v0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mamod committed Mar 22, 2015
1 parent ccf22fb commit 9447dcf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down
20 changes: 13 additions & 7 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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(){
Expand All @@ -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 + ")");
Expand All @@ -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
Expand All @@ -156,9 +164,7 @@ module.exports = function(grunt) {
fs.writeFileSync(get_file("dist" + currentDest + filename), out);
page_data = null;
}
};

LoopFiles(baseLocation);
})(baseLocation);
});

grunt.initConfig({
Expand Down
2 changes: 1 addition & 1 deletion less/elements.less
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,4 @@
-moz-background-clip: @argument;
-webkit-background-clip: @argument;
background-clip: @argument;
}
}
11 changes: 4 additions & 7 deletions source/init.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 9447dcf

Please sign in to comment.