I have a bunch of Javascripts in a folder under /public/javascripts/test
and I want to include them in my layout using javascript_include_tag
in as few lines as possible.
Currently I have 25 lines of code using javascript_include_tag
, is there any way to do this better? Also I cannot use javascript_include_tag :all :recursive
since there are some JS files in other directories that I do not want included.
Thanks for the help.
UPDATE: So now I have a javascript.rb initializer that has this single line of code (very long):
ActionView::Helpers::AssetTagHelper.register_javascript_expansion :syntax_highlight => Dir["#{Rails.root.to_s}/public/javascripts/sh/*.js"].each {|js| js.gsub!("#{Rails.root.to_s}/public/javascripts/",'')}
Now in my layout I have the follwing:
<%= javascript_include_tag :syntax_highlight %>
Now when I render the page I get the following:
<script src="/javascripts/sh/shAutoloader.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushAppleScript.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushAS3.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushBash.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushColdFusion.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushCpp.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushCSharp.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushCss.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushDelphi.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushDiff.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushErlang.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushGroovy.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushJava.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushJavaFX.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushJScript.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushPerl.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushPhp.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushPlain.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushPowerShell.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushPython.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushRuby.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushSass.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushScala.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushSql.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushVb.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shBrushXml.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shCore.js?1278089940" type="text/javascript"></script>
<script src="/javascripts/sh/shLegacy.js?1278089940" type="text/javascript"></script>
But for some reason none of this works? What gives?