Last active
February 3, 2018 05:49
-
-
Save jonschlinkert/9370326 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Handlebars Helpers for Pattern Lab | |
* Copyright (c) 2014 Jon Schlinkert | |
* Licensed under the MIT License (MIT). | |
*/ | |
'use strict'; | |
var path = require('path'); | |
var file = require('fs-utils'); | |
var _ = require('lodash'); | |
module.exports.register = function (Handlebars, options, params) { | |
var assemble = params.assemble; | |
options = options || {}; | |
var config = _.extend(options, options.data || {}); | |
var patterns = ['atom', 'molecule', 'organism']; | |
patterns.forEach(function(pattern) { | |
var inflection = pattern + 's'; | |
file.expand(options.patterns[inflection]).map(function(filepath) { | |
var name = pattern + '-' + file.base(filepath); | |
var template = file.readFileSync(filepath); | |
Handlebars.registerPartial(name, template); | |
}); | |
Handlebars.registerHelper(pattern, function(name, context) { | |
context = _.extend(config, context || {}); | |
var template = Handlebars.partials[pattern + '-' + name]; | |
console.log(name); | |
var fn = Handlebars.compile(template); | |
return new Handlebars.SafeString(fn(context)); | |
}); | |
}); | |
}; |
This file contains hidden or 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
assemble: { | |
options: { | |
flatten: true, | |
assets: 'source', | |
// Metadata | |
config: '<%= config %>', | |
data: ['<%= config.data %>/**/*.json'], | |
helpers: '<%= config.helpers %>/*.js', | |
// Templates | |
patterns: { | |
atoms: ['<%= config.atoms %>/**/*.hbs'], | |
molecules: ['<%= config.molecules %>/**/*.hbs'], | |
organisms: ['<%= config.organisms %>/**/*.hbs'], | |
} | |
}, | |
patterns: { | |
files: { | |
'_dist/': ['<%= config.pages %>/*.hbs'] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment