Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with template path since v0.17 #104

Open
ggarnier opened this issue Jun 26, 2014 · 13 comments
Open

Problem with template path since v0.17 #104

ggarnier opened this issue Jun 26, 2014 · 13 comments

Comments

@ggarnier
Copy link

I have a Rails project using handlebars_assets and a personal gem that defines some Handlebars templates. One of the templates in the gem is app/assets/javascripts/my-gem/component/templates/template_name.hbs. Until handlebars_assets 0.16, this template key in the template_namespace was my-gem/component/templates/template_name. But since 0.17, the key is just template_name.

I took a look at handlebars_assets code, and it seems that TemplatePath class constructor got a scope parameter, and now it gets a full_path parameter. This explains the behavior change, as I use the default path_prefix value (which is templates).

@AlexRiedler
Copy link
Collaborator

@ggarnier yeah, this is one of the changes I had to implement to keep consistency across the board; Otherwise through different versions of rails and sprocket engines the results were different.

The workaround would be to change as necessary (unless I am missing something).

@ggarnier
Copy link
Author

@AlexRiedler is it possible to set scope on TemplatePath constructor as before (https://github.com/leshill/handlebars_assets/blob/v0.16/lib/handlebars_assets/tilt_handlebars.rb#L91)? I think this could solve the problem.

@attenzione
Copy link

i have two template files

/assets/javascripts/builder/templates/nodes/edit.hrb.erb
/assets/javascripts/builder/templates/nodes/show.hrb

before version 0.17 both template has the same namespace, but after edit has nodes/edit, but show - builder/templates/nodes/show

@AlexRiedler
Copy link
Collaborator

@ggarnier I am trying to avoid excess work in the slim + haml in production... so using the previous method is not a clear solution; working on a better solution now.

@AlexRiedler
Copy link
Collaborator

@attenzione that is super weird, it should be nodes/edit and nodes/show ... what version of rails? (I tested on 4.0)

@attenzione
Copy link

@AlexRiedler i use latest 4.1.4, but all time expect builder/templates/nodes/edit, not nodes/edit. It's how it's worked before 0.17 and think should be. If i wanted nodes/edit, i would placed it to /assets/javascripts/templates/nodes/edit

@AlexRiedler
Copy link
Collaborator

@attenzione ah, okay that makes more sense. I was actually fixing a bug that had to deal with paths; the new version is very... loosely defined.

If you put this in an initializer this should fix your issue:

::HandlebarsAssets.configure do |config|
   config.path_prefix = 'assets'
end

anything after assets in the path will be then grabbed as the template name.

@AlexRiedler
Copy link
Collaborator

@ggarnier actually does ^ also work as a solution also work for you as well ? or not really cause of how the gem is bundled ? (noting that you can write regex's as the path prefix)

@attenzione
Copy link

@AlexRiedler very nice, it's resolved my problem! thanx
but another problem i think exist, when one template with *.erb extension has different namespace with template without

@AlexRiedler
Copy link
Collaborator

@attenzione I think that is mentioned in another ticket; I closed it because it actually is a by-product of the asset compilation pipeline (it does not allow two templates to have the same logical path).

@attenzione
Copy link

no, they're not the same logical path, see

/assets/javascripts/builder/templates/nodes/edit.hrb.erb
/assets/javascripts/builder/templates/nodes/show.hrb

and their namespaces should be

builder/templates/nodes/edit
builder/templates/nodes/show

but edit.hbs.erb has only nodes/edit, so the difference is only in extension, if i remove extension .erb, edit template will have the same namespace as show

@AlexRiedler
Copy link
Collaborator

yeah... I am still thinking of that case @attenzione; I might 'revert' this change; and remove this idea of 'TemplatePath' and use logical paths instead just for the template names (which means I believe the change I told you above will still work).

@ggarnier
Copy link
Author

ggarnier commented Jul 3, 2014

@AlexRiedler in my case, I use the default path_prefix = 'templates'. I solved my problem changing my templates path inside the gem from my-gem/component/templates/template_name to templates/my-gem/component/template_name. Now the template path is my-gem/component/template_name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants