leshill / handlebars_assets

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

Templates in same folder with javascript files losing prefix #111

Closed darko1002001 closed 9 years ago

darko1002001 commented 9 years ago

I am using Rails 4.1 and I have the following structure of the javascript files and templates:

/javascripts
  /modules
    /module1
      /templates
        - view1.hbs
      - controller.js
    /module2
     /templates
        - view2.hbs
     - controller.js

in the application.js file i require_tree ./modules/

The issue is that i lose the prefix to the templates when inspecting the HandlebarsTemplates variable. So my template goes under the name view2 and view1 instead of modules/module1/templates/view1 for example.

I have read the documentation for requiring the templates before the javascript and that works fine if i use a single folder just for the templates but i would rather organize them inside modules.

Is there any way to achieve what i need?

I've used it like this with Rails 3 and it worked so i assume its an issue or a limitation?

AlexRiedler commented 9 years ago

@darko1002001 this is cause it defaults to search for templates in the path and take the remainder; you will need to change

e.g. in your applications config:

HandlebarsAssets::Config.path_prefix = 'app/assets/javascripts/modules'

Hopefully that will work for you :) sorry about the late response.

darko1002001 commented 9 years ago

Yeah this works thanks!