Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Point Sprockets' `depend_on` directive to a non-assets file

I have an app/assets/javascripts/moufa.js.erb file that gets populated with values from a config/moufa.yml file. I want to use the depend_on sprockets directive so that every time the yaml file gets changed, it recompiles the js file.

like image 656
Kostas Avatar asked Feb 05 '13 15:02

Kostas


1 Answers

We were able to solve this by adding a new directive. This directive (put this in config/initializers/sprockets.rb) adds a dependency on a file in the config/ directory:

class Sprockets::DirectiveProcessor
  def process_depend_on_config_directive(file)
    path = File.expand_path(file, "#{Rails.root}/config")
    context.depend_on(path)
  end
end
like image 127
Paul Brannan Avatar answered Nov 16 '22 01:11

Paul Brannan