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

Can't get hamlbars to play nicely with handlebars_assets #85

Open
timherby opened this issue Oct 1, 2013 · 7 comments
Open

Can't get hamlbars to play nicely with handlebars_assets #85

timherby opened this issue Oct 1, 2013 · 7 comments

Comments

@timherby
Copy link

timherby commented Oct 1, 2013

I'm trying to use hamlbars with handlebars_assets, but so far have failed to get them to integrate properly.

Out of the box, I tried including both gems:

  gem 'handlebars_assets'
  gem 'hamlbars'

And when I create a file with a .hamlbars file, it gets compiled properly, but by the handlebars_assets Tilt template, not the hamlbars Template class.

If I change the extension to "file.js.hbs.hamlbars" (as described here https://github.com/jamesotron/hamlbars#chaining-compilation-using-the-rails-asset-pipeline), I get "file.js.haml.js" as my include, and "file.js" cannot even be downloaded directly.

I then decided to pull the latest version of handlebars_assets which changes the initialization order so that the hamlbars template gets used. I did this by changing my gemfile to point to the latest commit in this branch: https://github.com/leshill/handlebars_assets/tree/fix-sprockets-register
as described in issue #73

  gem 'handlebars_assets', git: 'https://github.com/leshill/handlebars_assets.git', ref: '510fb66d96b881e08af67867d6773cf7a1a17ba2'
  gem 'hamlbars'

But that doesn't do the trick. If I keep the filename as "file.hamlbars" no files are included by

If I switch to "file.js.hbs.hamlbars", I run into this issue jimsynz/hamlbars#42 (Illegal nesting: nesting within plain text is illegal). If I follow the advice in that thread, and switch "file.js.hbs.hamlbars" to ".js.hamlbars" but then the handlebars template gets returned uncompiled to the browser.

If anyone has any tips about how to use both gems together, I would really appreciate it. I have cross-posted this to the other gem's forum too (jimsynz/hamlbars#51) for tracking.

@AlexRiedler
Copy link
Collaborator

I changed how registration is done in the fix-sprockets-register experimental branch (which is part of the next version).

In order to get it to work for templates of the name "foo.js.hbs.hamlbars":

e.g. config/initializers/templating.rb:

require 'handlebars_assets'

::HandlebarsAssets.configure do |config|
  config.haml_enabled = false
  # and/or
  config.hamlbars_extensions = []
end

I tested on Rails 3.2 locally, does this work for you?

@timherby
Copy link
Author

timherby commented Oct 4, 2013

Thanks @AlexRiedler. This worked great! I tried either one, and they both seem to do the trick.

BTW, when looking through config.rb, I noticed there may be a small typo. In the following, there is no 'hbs_extensions' registered in the attr_writer, so I assume you meant '@handlebars_extensions'

    def handlebars_extensions
      @hbs_extensions ||= ['.hbs', 'handlebars']
    end

Thanks again for the rapid fix.

@AlexRiedler
Copy link
Collaborator

@timherby, haha yeah, thanks for notifying me! and no problem!

@timherby
Copy link
Author

timherby commented Oct 5, 2013

One last thing. I tried to simplify to only disabling haml by using this setting:

  config.haml_enabled = false

but then the .hbs registration still kicks in and tries to process the template as haml because HanldeBarsTemplate.is_haml? is solely looking at the registered extensions. It should probably also look at whether haml is enabled.

For now, just using this in the configuration works fine:

  config.hamlbars_extensions = []

@rpocklin
Copy link

I just started using handlebars_assets yesterday with the .hamlbars extension and it works fine for me with Rails 3.2.14. I didn't include gem 'hamlbars' but i'm using gem 'haml' for my server side view templates.

I tried adding gem 'hamlbars' to my Gemfile and I got a big deprecation warning:
DEPRECATION WARNING: Hamlbars 2.0 removes asset compilation! but it still worked with the original file /app/assets/javascripts/templates/file.hamlbars. I'm requiring the full 'handlebars' compiler in application.js. Hope that helps.

@AlexRiedler
Copy link
Collaborator

@rpocklin I assume this is because the separation of pipelines that you are using. (or files are in both folders/symlinked) ? the 'handlebars_assets' gem does take '.hamlbars' files and compile them... they just won't support the 'hb' helper (which is why they are slightly incompatible right now).

@rpocklin
Copy link

Yeah, my templates for client-side are different than the server-side views. I'm not using the hb helper - maybe I missed something but I don't see much benefit - seems just as easy to use the {{foo}} notation in the .hamlbars files.

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