radiumsoftware/iridium — pull request #14 by paynerc (2012-08-30 05:06:15+00:00)
Title: Handlebars in subfolders

We are using subfolders with out templates to help organize the files for development (similar to that which ember-rails provides). This allows us to group a set of templates for a given set of functionality. Consider the following example layout:

- app
- javascripts
- templates
- account
- edit.handlebars
- new.handlebars
- show.handlebars
- person
- edit.handlebars
- new.handlebars
- show.handlebars

In the current implementation, the handlebars pipeline filter will find all of these handlebars files and will process them as we would expect… sort of. The standard handlebars filter will take the filename, sans extension, as the key for the Ember.TEMPLATES hash, thus causing key name collisions in this example. The example above would create:

Ember.TEMPLATES['edit']...
Ember.TEMPLATES['new']...
Ember.TEMPLATES['show']...

I have modified the Assetfile that Iridium operates on to take into account any subfolders when generating the key name for the Ember.TEMPLATES hash. If the handlebars file being processed exists in the standard templates location (app/javascripts/templates), any subfolders past the templates folder will be taken into account when generating the key for the Ember.TEMPLATES hash. If the handlebars file being processed exists somewhere other than the standard location, the default behavior is used. Now, the example above creates:

Ember.TEMPLATES['account/edit']...
Ember.TEMPLATES['account/new']...
Ember.TEMPLATES['account/show']...
Ember.TEMPLATES['person/edit']...
Ember.TEMPLATES['person/new']...
Ember.TEMPLATES['person/show']...

Unit tests have also been added that test when the handlebars file is found in the standard location, a non-standard location and when subfolders are present.

Thanks!