Skip to content

Instantly share code, notes, and snippets.

@alandipert
Forked from anonymous/componentize.rb
Created June 25, 2009 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alandipert/136019 to your computer and use it in GitHub Desktop.
Save alandipert/136019 to your computer and use it in GitHub Desktop.
ruby script for turning golf component tree into components.js
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
# given a components directory, poop a components.js to stdout
raise(ArgumentError, "target dir is required") unless cdir = ARGV[0]
exts = ["css", "html", "js", "res"]
puts "jQuery.golf.components="+Hash[*exts.collect{|e|
Dir.glob(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