johnbintz/jasmine-headless-webkit — Issue #102: Sprockets not compiling JavaScript templates
Author: malandrew
Created: 2011-12-24 04:19:53+00:00
State: open

When sprockets handles template assets it moves from right to left compiling a template and then adding it to the JST array. So if a file is template.jst.hbs, it will first take the template and package it as an hbs object and then it will wrap it as an object in a this.JST array.

Here's one of my Handlebars templates compiled correctly when I run my server normally or run ```rake jasmine```

```
(function() {
this.JST || (this.JST = {});
this.JST["mobile/meeting/story_feed_item"] = (function() {
this.HandlebarsTemplates || (this.HandlebarsTemplates = {});
this.HandlebarsTemplates["mobile/meeting/story_feed_item"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
helpers = helpers || Handlebars.helpers;
var buffer = "", stack1, self=this, functionType="function", helperMissing=helpers.helperMissing, undef=void 0, escapeExpression=this.escapeExpression;

buffer += "
\n

\n ";
stack1 = helpers.story || depth0.story;
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.invitee_name);
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "story.invitee_name", { hash: {} }); }
buffer += escapeExpression(stack1) + "\n ";
stack1 = helpers.story || depth0.story;
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.content);
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "story.content", { hash: {} }); }
buffer += escapeExpression(stack1) + "\n

\n
\n";
return buffer;});
return HandlebarsTemplates["mobile/meeting/story_feed_item"];
}).call(this);;
}).call(this);
```

It looks like Sprockets isn't being called so that it handles template precompiling correctly. Here is the jasmine-headless-webkit output for the same file:

```

```

In this script, the template string is being compiled straight to an object in the this.JST array, without being processed by Handlebars (or any other templating system) first. I observed this same issue with EJS files.

Any clue why this my not be working with JHW, but work via ```rake jasmine```? Thanks!