handlebar-rider
Advanced tools
Comparing version 0.1.2 to 0.1.3
// handlebar rider | ||
handlebars = require('handlebars'); | ||
@@ -96,6 +98,8 @@ uglify = require('uglify-js'); | ||
var output = ['(function() {\n var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; Handlebars.partials = Handlebars.templates; \n']; | ||
output = ['(function() {']; | ||
output.push('\n var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\n'); | ||
output.push('\n Handlebars.partials = Handlebars.templates;\n') | ||
for(var t = 0; t < rider.templates.length; t++){ | ||
var data = fs.readFileSync(rider.templates[t].file, 'utf8'); | ||
data = fs.readFileSync(rider.templates[t].file, 'utf8'); | ||
@@ -106,3 +110,18 @@ // clean the data a bit | ||
var compiled = 'templates[\'' + rider.templates[t].namespace + '\'] = template(' + handlebars.precompile(data, {}) + ');\n' | ||
// check for partial conventions | ||
if (rider.templates[t].namespace.indexOf('/_') > 0){ | ||
compiled = 'templates[\'' + rider.templates[t].namespace.replace(/\/_/,'_') + '\'] = template(' + handlebars.precompile(data, {}) + ');\n' | ||
} else if( rider.templates[t].namespace.indexOf('partial') != 0 ) { | ||
compiled = 'templates[\'' + rider.templates[t].namespace + '\'] = template(' + handlebars.precompile(data, {}) + ');\n' | ||
} else { | ||
compiled = 'templates[\'' + rider.templates[t].namespace.replace(/partials\//,'') + '\'] = template(' + handlebars.precompile(data, {}) + ');\n' | ||
} | ||
output.push(compiled); | ||
@@ -109,0 +128,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description" : "Watches a directory and precompiles handlebars templates", | ||
"version" : "0.1.2", | ||
"version" : "0.1.3", | ||
@@ -8,0 +8,0 @@ "repository" : { |
@@ -1,17 +0,15 @@ | ||
handlebar-rider | ||
# handlebar-rider | ||
================ | ||
Command line tool that will watch a handlebars template directory pre-compile containing handlebars template files and concatenate them | ||
into a single javascript file in build/public. The directory structure you use will namespace the templates as expected with JST et all | ||
into a single javascript file in build/public. | ||
Run-time usage example: | ||
The directory structure you use will namespace the templates with ['directory/template'] as with JST et all | ||
html_output = Handlebars.templates['users/view'](data) | ||
Install: | ||
## Install: | ||
npm install -g handlebar-rider | ||
Usage: | ||
## Usage: | ||
@@ -26,1 +24,41 @@ handlebar-rider path/to/your/handlebars/dir/ | ||
## Run-time usage example: | ||
html_output = Handlebars.templates['users/view'](data) | ||
## Partial Support/Conventions: | ||
There are two methods for using partials within your templates: | ||
1. Global partials | ||
If you create a partials in a directory, aptly called "partials" which lives within your handlebars templates directory, the | ||
handlebars files will be pre compile and available in your templates | ||
2. Scoped partials | ||
If you prefix your template file name with an underscore, you can can access it as directory_partial | ||
### Example directory structure: | ||
templates | ||
-- users | ||
- _list.hb | ||
- _form.hb | ||
- edit.hb | ||
- view.hb | ||
-- partials | ||
- photo_uploader.hb | ||
### And usage: | ||
<h1>Edit User</h1> | ||
{{> users_list}} | ||
{{> users_form}} | ||
{{> photo_uploader}} | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9105
149
64