Reputation: 1647
I'm building a JS widget using Coffeescript. I'm playing some tricks to get my CSS/SCSS and HTML/HAML templates into the JS widget upon compilation:
# widget.js.coffee.erb
class Widget
constructor: (options) ->
@template = <%= Haml::Engine.new(
File.read(
File.expand_path("../../templates/widget.html.haml", __FILE__))).
render.to_json %>
@css = <%= Sass.compile_file(
File.expand_path("../../stylesheets/widget.css.scss", __FILE__)).
to_json %>
The problem is that when I change the HTML or CSS, Rails is not recompiling the Coffeescript in development because the coffeescript file is not changing. I need to make silly whitespace changes to force it to recompile things. This is getting annoying :-)
Any ideas on how to force the asset pipeline to compile certain files on every request?
Upvotes: 1
Views: 208
Reputation: 1647
Got it. Sprockets has a depend_on directive. Adding the following lines to my widget.js.coffee.erb solved it:
# coffee.js.coffee.erb
#= depend_on '../templates/widget.html.haml'
#= depend_on '../stylesheets/widget.css.scss'
class Widget
...
Upvotes: 3