I'm writing a mountable Rails 3.1 engine that adds features to the main app (i.e. it isn't isolated). The engine's JS depends on jQuery, jQueryUI, DataTables and JSTree (among other libraries) so the engine's manifest looks a little something like:
// my_engine.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jstree_pre1.0_fix_1/jquery.jstree.js
//= require_tree .
I can then conditionally load this file into the main app's layout using:
<%= javascript_include_tag 'application' %>
<%= javascript_include_tag 'my_engine/my_engine' if user_logged_in? %>
However, if the main app's manifest already includes one of the dependencies (most likely jQuery and jQuery_UJS) then those dependencies will be loaded twice. I'll see something like:
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
...
<script src="/assets/application.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-ui.js?body=1" type="text/javascript"></script>
<script src="/assets/jstree_pre1.0_fix_1/jquery.jstree.js?body=1" type="text/javascript"></script>
...
<script src="/assets/cms/application.js?body=1" type="text/javascript"></script>
Sprocket's require directive will only require an asset once within the same bundle but here I am working with two bundles. To make it simple for other devs implementing my engine, I'd like them to be able to include one line that detects whether or not the shared dependencies are already included. Is there are nice way of doing this using Sprockets?