We frequently need to reference rails app assets from our Javascript. I've seen methods where you create an assets.js.erb file and you include your references to assets in there. Similar to the example here: Avoid *.js.erb files by building all the asset_path values
I think this is quite messy and I'd like to hook into manifest generation and generate a manifest.js at the same time. I came up with the following to do this https://gist.github.com/49d3f12bed298f0685a1
This works fine when you run assets:precompile, however, for development I need this manifest.js to be dynamically generated. I can't find an appropriate place to do this though. Is there some middleware that routes requests to /assets/* to /app/assets// in development mode, would it be appropriate to hook in at that stage?
Any suggestions would be welcome.
I've been working away at this after reading the sprockets source and some of the actionpack sprockets stuff too I came up with this approach. Just put it in app/assets/javascripts/assets.js.erb or something like that. It uses the each_logical_path method from Sprockets::Environment to iterate over all asset files, then instantiates an Asset object with that path. The correct asset path is returned depending on whether asset digests are enabled for your rails env or not.
This still needs some work but I think I'm on the right track.