Skip to content

Instantly share code, notes, and snippets.

Created June 25, 2009 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/136018 to your computer and use it in GitHub Desktop.
Save anonymous/136018 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
# given a components directory, poop a components.js to stdout
exts = ["css", "html", "js", "res"]
cdir = ARGV[0]
puts "jQuery.golf.components="+Hash[*exts.collect{|e|
Dir.glob(File.join(File.join(cdir, "**"), "*."+e))
}.flatten.map{|e|
e.scan(/(^.*)\.\w+$/).first.to_s
}.uniq.collect{|c|
[
c[cdir.length, c.length].gsub(/\//,'.'), Hash[*exts.collect{|e|
if e=='res'
[e, Hash[*Dir.glob(File.join(c+"."+e, "*")).collect{|r|
[File.basename(r), r]
}.flatten]]
else
[e, File.open(c+"."+e, "rb").read]
end
}.flatten]
]
}.flatten].to_json+";jQuery.golf.setupComponents();"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment