emblem-rails
emblem-rails copied to clipboard
Client Compiling
This gem appears to support either server or client compiling based on the setting of config.handlebars.precompile
in the rails environment file.
However, if set to false
for client compiling, the JS just crashes since Emblem
is not defined.
Are we doing something wrong or should the documentation mention something about this? We are using this with Rails 4 & Ember.
Should the gem support a way to require a JS file (in a JS manifest) so that the client rendering works? We tried doing a javascript_include_tag on a minified emblem.js in our application layout, but it didn't work.
Thanks for any help.
What's the use case for client compiling if you get server precompilation for free?
@machty not sure, but this gem supports it and doesn't give instructions about the option / requirement to set config.handlebars.precompile
to true
(unless that's the default? don't know why my project would've strayed from the default unless something told me too. Brand new rails apps with ember & emblem). Also, I am new to handlebars too, but maybe people change that config in development mode for some reason?
Basically, my teammate and I spent hours trying to figure out how to get it to consistently compile these on the server (due to asset pipeline & caching, flipping the value of that config option wasn't always deterministic to it working or not working) and I was hoping at least documentation could be improved to save others time. It is also a bit weird that the gem has this other code path for client compiling if it's expected not to work.
I can't think of a good reason to set handlebars.precompile to false. Note that this is different than the rake assets:precompile
task, which will precompile your assets into the public/assets
folder; if you leave handlebars.precompile
set to true in the Rails development environment, it'll still (pre)compile your Emblem/Handlebars templates per each request. In other words, you won't be losing any value or convenience by leaving precompile to true in a development setting.
Does this make sense?
Of course, but should this be mentioned somewhere (e.g. in the Installation instructions or in a new Common Issues section)?
And why does the gem have conditional code paths based on the setting of handlebars.precompile
if changing it isn't supported?
Ok, it looks like handlebars.precompile
does default to true
. When we set Ember.js up, something told us to set handlebars.precompile
to false
(I will check with my teammate on why that was done next week).
But for this gem, maybe the setting could be ignored or an exception raised if handlebars.precompile
is false
since it's not supported?
The ember-rails gem README contains the following:
Default behavior for ember-rails is to precompile handlebars templates. If you don't want this behavior you can turn > it off in your application configuration (or per environment in: config/environments/development.rb) block:
config.handlebars.precompile = false (Note: you must clear the local sprockets cache if you disable precompilation, stored by default in tmp/cache/assets)
So that's where we got the idea. Again, I think this gem should mention this, ignore the setting, or throw an exception for the unsupported setting.
Agreed, I think raising an error makes most sense if we detect that setting, I can't imagine why you'd want it in the context of a railsapp
just running into this as well now. I was using it because uncompiled handlebars is much easier to read (and debug) than the compiled version.
@mreinsch how is that true? Regardless of whether you client-side compiled or precompiled, you're still going to be stepping through the Handlebars VM' stack, right? (This code admittedly looks like sin, but I don't think it gets any better if you're client-side compiling...)
not stepping through Handlebars VM' stack, no. I'm just a normal user there. And for us, we make mistakes in emblem (or Handlebar) and then being able to compare that to simple Handlebar or show simple Handlebar to someone else is quite useful.
@mreinsch ah, I see. Seems legitimate. I'll try to get to this shortly.
@gerry3 did you arrive to solve this problem? I am also having hours to run an ember rails project with emblem and no way.