Skip to content
Browse files

removed oven and am attaching templates to handlebars instead

- also no more namespacing templates, instead have propertynames like ['a.b.c']
- all this to become consistent with client side templates
  • Loading branch information...
1 parent 20c2363 commit 62189bab0486f6f75ee7c6c6978dbd8c6315cc34 Thorsten Lorenz committed Aug 25, 2012
Showing with 35 additions and 73 deletions.
  1. +14 −14 README.md
  2. +6 −2 examples/app.js
  3. +2 −2 examples/server.js
  4. +1 −1 examples/templates/partials/site/content.hbs
  5. +11 −53 test/hotplates.js
  6. +1 −1 utl.js
View
28 README.md
@@ -35,14 +35,14 @@ hotplates.heat(
, renderSite);
```
-This compiles *index.hbs*, makes it accessible via `hotplates.oven.index` and
+This compiles *index.hbs*, makes it accessible via `handlebars.templates['index']` and
registers the following partials with handlebars:
- site.content
- site.header
- oven.partsIndex
- oven.filter.collector
- oven.filter.handle
+ 'site.content'
+ 'site.header'
+ 'oven.parts-index'
+ 'oven.filter.collector'
+ 'oven.filter.handle'
They are now accessible under that name in other templates and partials.
@@ -123,27 +123,27 @@ Templates with names and paths containing underscores or dashes will be [camelCa
E.g., 'dashed-path/underscored_name.hbs' is compiled/registered as 'dashedPath/underscoredName'
-## The oven
+## The templates
-***hotplates.oven***
+***handlebars.templates***
-After you heated your templates, they are shoved into the oven, namespaced according to the path they where found in.
+After you heated your templates, they are registered as `handlebars.templates` namespaced according to the path they where found in.
-E.g., a template found at 'site/reader/book.hbs' will be stored as a compiled `Function` under `hotplates.oven.site.reader.book`.
+E.g., a template found at 'site/reader/book.hbs' will be stored as a compiled `Function` under `handlebars.templates['oven.site.reader.book']`.
## Registered Partials
-Partials are registered in a similar fashion, but not shoved into the oven as they are registered with handlebars instead.
-
-However the namespacing schema for them is exactly the same.
+Partials are registered in a similar fashion as `handlebars.partials`.
Assuming the partial root was 'templates/partials', a partial found at 'templates/partials/book/page.hbs' will be accessible in other templates and partials under the name `book.page`.
+Additionally you can access this partial directly via `handlebars.partials['book.page']`.
+
## Burning templates
***burn()***
-In order to remove all templates from the oven and unregister all partials, you can burn them.
+In order to remove all templates from handlebars and unregister all partials, you can burn them.
This is useful in cases where you want to make sure that no obsolete templates or partials are sticking around.
View
8 examples/app.js
@@ -6,8 +6,12 @@ var hotplates = require('../hotplates')
;
hotplates
- .on('templateCompiled', function (fileInfo) { console.log('Compiled: \t', fileInfo.path); })
- .on('partialRegistered', function (fileInfo) { console.log('Registered:\t', fileInfo.path); })
+ .on('templateCompiled', function (fileInfo, name) {
+ console.log('Compiled: \t[ %s ] as [ %s ]', fileInfo.path, name);
+ })
+ .on('partialRegistered', function (fileInfo, name) {
+ console.log('Registered:\t[ %s ] as [ %s ]', fileInfo.path, name);
+ })
.heat(
{ templates:
{ root: path.join(__dirname, 'templates')
View
4 examples/server.js
@@ -1,8 +1,8 @@
var hotplates = require('../hotplates')
, handlebars = require('handlebars')
, path = require('path')
- , http = require('http')
- , PORT = 3000
+ , http = require('http')
+ , PORT = 3000
;
function renderSite () {
View
2 examples/templates/partials/site/content.hbs
@@ -1,3 +1,3 @@
<div>
- {{> oven.partsIndex }}
+ {{> oven.parts-index }}
</div>
View
64 test/hotplates.js
@@ -135,10 +135,10 @@ describe('compiling and registering', function () {
should.not.exist(error);
})
- it('adds each plate under its name to the oven', function () {
- Object.keys(hbs.oven).length.should.equal(2);
- hbs.oven['plateuno'].should.equal(memuno);
- hbs.oven['platedos'].should.equal(memdos);
+ it('adds each plate under its name to handlebars templates', function () {
+ Object.keys(hbStub.templates).length.should.equal(2);
+ hbStub.templates['plateuno'].should.equal(memuno);
+ hbStub.templates['platedos'].should.equal(memdos);
})
it('emits "templateCompiled" for each plate with correct file names', function () {
@@ -181,10 +181,6 @@ describe('compiling and registering', function () {
hbs.burn();
})
- it('deletes all templates from oven', function () {
- Object.keys(hbs.oven).should.have.length(0);
- })
-
it('deletes all templates from handlebars', function () {
Object.keys(hbStub.templates).should.have.length(0);
})
@@ -214,9 +210,9 @@ describe('compiling and registering', function () {
})
it('adds handledbar for each plate under its name at namespace reflecting subfolders', function () {
- Object.keys(hbs.oven).length.should.equal(1);
- hbs.oven.sub.subsub.plateuno.should.equal(memuno);
- hbs.oven.sub.subsub.platedos.should.equal(memdos);
+ Object.keys(hbStub.templates).length.should.equal(2);
+ hbStub.templates['sub.subsub.plateuno'].should.equal(memuno);
+ hbStub.templates['sub.subsub.platedos'].should.equal(memdos);
})
})
@@ -242,9 +238,9 @@ describe('compiling and registering', function () {
})
it('adds handledbar for each plate under its name at namespace reflecting subfolders', function () {
- Object.keys(hbs.oven).length.should.equal(1);
- hbs.oven.sub.subsub.plateuno.should.equal(memuno);
- hbs.oven.sub.subsub.platedos.should.equal(memdos);
+ Object.keys(hbStub.templates).length.should.equal(2);
+ hbStub.templates['sub.subsub.plateuno'].should.equal(memuno);
+ hbStub.templates['sub.subsub.platedos'].should.equal(memdos);
})
it('emits "templateCompiled" for each template including namespaced name', function () {
@@ -262,44 +258,6 @@ describe('compiling and registering', function () {
})
})
-
- describe('when plates "dashed-folder/name-with-dashes.hbs" and "underscored_folder/name_with__underscores" are found', function () {
- var specialPlateFiles = [
- { name : 'name-with-dashes.hbs'
- , parentDir : 'dashed-folder'
- , fullPath : 'does/not/matter/here'
- }
- , { name : 'name_with__underscores.hbs'
- , parentDir : 'underscored_folder'
- , fullPath : 'does/not/matter/here'
- }
- ]
- , localhbs;
-
- before(function (done) {
-
- localhbs = proxyquire
- .resolve('../hotplates', __dirname, {
- fs : { readFile: function (p, cb) { cb(null, 'not important here'); } }
- , handlebars : { compile: function () { return 'not needed'; } }
- , readdirp : function (opts, cb) {
- readdirpOpts.push(opts);
- cb(null, { files: specialPlateFiles });
- }
- })
- .heat({ templates: specialPlateFiles }, function (err) {
- done();
- });
- })
-
- it('adds plate "dashedFolder.nameWithDashes to oven', function () {
- should.exist(localhbs.oven.dashedFolder.nameWithDashes);
- })
-
- it('adds plate "underscoredFolder.nameWithUnderscores to oven', function () {
- should.exist(localhbs.oven.underscoredFolder.nameWithUnderscores);
- })
- })
})
describe('when no plates are found in plates path', function () {
@@ -318,7 +276,7 @@ describe('compiling and registering', function () {
})
it('adds no handledbar', function () {
- Object.keys(hbs.oven).length.should.equal(0);
+ Object.keys(hbStub.templates).length.should.equal(0);
})
})
View
2 utl.js
@@ -37,5 +37,5 @@ var namespace = module.exports.namespace = function (folder, root) {
var plateNameFrom = module.exports.plateNameFrom = function (filename) {
var nameWithoutExt = filename.substr(0, filename.length - path.extname(filename).length);
- return camelCase(nameWithoutExt);
+ return nameWithoutExt;
};

0 comments on commit 62189ba

Please sign in to comment.
Something went wrong with that request. Please try again.