leshill / handlebars_assets

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

HandlebarsTemplates namespace missing #90

Closed jithugopal closed 10 years ago

jithugopal commented 10 years ago

I just added the gem to my rails app, required handlebars in application.js, bundled and rebooted my server.

I am unable to get the HandlebarsTemplates namespace in javascript console. I am not entirely sure what I am missing here.

Rails 3.2.16

AlexRiedler commented 10 years ago

Have you required the templates directory as a directive in your application.js ?

As explained here: https://github.com/leshill/handlebars_assets#templates-directory

jithugopal commented 10 years ago

Yup, I required it before //= require_tree .

AlexRiedler commented 10 years ago

I have been trying to reproduce, but with no luck; can you try to provide a minimal set of code that reproduces.

jithugopal commented 10 years ago

I tried this on a vanilla rails app and it worked. It looks like my assumptions were a bit off.

The namespace global object wasn't generated because I didn't have any template files in my template directory. My assumption was that the namespace would be generated regardless of whether the templates exists or not (I think this is how smt_rails work as well).

Is there a particular reason you generate the namespace object only when there are template files? In the absence of templates, ideally the 'HandlebarsTemplates' namespace object should return me nothing, rather than complaining no refernce to HandlebarsTemplates found.

AlexRiedler commented 10 years ago

the logic behind this has to do with the fact you need to include some file (otherwise cannot inject JS), I could add an entire other file into the Repo for exactly this purpose, but it does not seem like the best idea, or provide any benefit to the overall project (without breaking backwards compatibility).

jithugopal commented 10 years ago

Makes sense. Do you think this is intuitive enough? Probably drop a line in the README?

AlexRiedler commented 10 years ago

Noted, thanks @jithugopal