-
-
Save alandipert/136019 to your computer and use it in GitHub Desktop.
ruby script for turning golf component tree into components.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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