leshill / handlebars_assets

Use handlebars.js templates with the Rails asset pipeline.
MIT License
648 stars 159 forks source link

Support for ERB in JavaScript files #75

Closed rbhitchcock closed 11 years ago

rbhitchcock commented 11 years ago

If I understand things correctly, Sprockets will process Ruby in JavaScript files if .erb is appended to the end. It seems to me that this can be enabled by simply changing some of the file name checks to allow for .erb to be present at the end, and then Sprockets will handle the rest. Does this seem accurate? Or does handlebars_assets run before that sort of processing would occur? I'd be happy to attempt to implement it if you think it would be useful.

AlexRiedler commented 11 years ago

it should for the most part work out of the box "foo.hbs.erb" for instance; did this not work for you?

rbhitchcock commented 11 years ago

Actually I hadn't tried yet because it doesn't mention it in the README. I apologize if this issue is noise. But looking at the code for a PR I submitted I noticed that it determines, for instance, a haml file if it ends with a .haml extension. So it seems if I did something like file.haml.erb it would not compile properly.

leshill commented 11 years ago

Hi @rbhitchcock,

@AlexRiedler is correct, please try it.

For .hamlbars, we do not register the .hamlbars extension with sprockets, it is used to mark ‘compile haml too!’ whenever needed as part of the handlebars compile. .erb is registered by a sprockets engine that will handle that extension and then pass on to the next extension handler.

rbhitchcock commented 11 years ago

Excellent... thank you for the feedback! Again, I apologize for the noise. I just made an assumption but should have done my own testing before filing an issue.