Skip to content

Instantly share code, notes, and snippets.

@collin
Created March 10, 2009 12:21
Show Gist options
  • Select an option

  • Save collin/76875 to your computer and use it in GitHub Desktop.

Select an option

Save collin/76875 to your computer and use it in GitHub Desktop.
module AssetsHelper
def javascripts
scripts = []
manifest = File.read("site/javascripts/vendor/manifest").to_s
scripts += manifest.split("\n").map{|file| "site/javascripts/vendor/#{file}.js"}
Dir.glob("site/javascripts/*").reject{|dir| dir[/vendor/] }.each do |dir|
files = Dir.glob("#{dir}/*.js")
scripts << files.find{ |file| file[/preamble/] }
scripts += files.reject{ |file| file[/preamble|postamble/]}
scripts << files.find{ |file| file[/postamble/] }
end
scripts.compact!
%{
<script>
#{
scripts.map{|script|
content = File.read("#{script}") || ""
js = ""
js << %{console.log("loading site/javascripts/#{script} ContentLength: #{content.length}");}
js << content
js}
}
</script>
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment