can't import less.erb file with interpolated strings
stevenspiel opened this issue · comments
I'm on rails 4.2.5
with less-rails 2.7.1
and I'm having issues importing less.erb files.
My manifest file:
application.less
:
@import 'base';
@import 'layout';
@import 'module';
@import 'state';
@import 'theme.less.erb';
/*
*= require_tree .
*= require_self
*/
and theme.less.erb
is
.ui.button {
color: <%= @branding.primary_color %>
}
Without the erb
interpolation, it does fine, but otherwise, it raises:
Unrecognised input
The @branding
variable is being set in application_controller.rb
:
def render(*args)
@branding = Branding.new(cookies, params)
super
end
But the erb
interpolation doesn't work even without the variable:
.ui.button {
color: <%= '#ffffff' %>
}
I'd really like to have some per-user basis branding that is compiled (and possibly cached) on the fly. What do you suggest?
Since the asset is compiled at a different time to your request (i.e. when deploying into production) it won't have access to your request. I've solved this problem by inlining some override CSS in a <style>
tag in the head of the page. If you use Turbolinks you'll need to add this into the body of the page.