-
-
Save rgrove/564388 to your computer and use it in GitHub Desktop.
This file contains 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
require 'yui-utils' | |
task :default, [:file, :replace, :filter, :jsdir] do |t, args| | |
args.with_defaults( | |
:filter => nil, | |
:jsdir => nil, | |
:replace => nil | |
) | |
modules = YUIUtils.build_module_list(args.filter, args.jsdir) | |
YUIUtils.output(modules, args.file, args.replace) | |
end |
This file contains 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
class YUIUtils | |
@@module_regex = /YUI\.add\((['"][\w\-]+['"]).*\}, ['"].+['"], \{\s*(.+)\s*\}\);?/mi | |
def self.build_module_list(filter = "**/*.js", jsdir = "Public/js") | |
out = [] | |
FileList[filter].each do |file| | |
match = File.read(file).scan(@@module_regex) | |
if match[0] && match[0][0] && match[0][1] #filter out files that didn't match | |
#prettier names | |
yuimodule = match[0][0] | |
config = match[0][1] | |
out.push(%(\t#{yuimodule} : {\n\t\t"path" : "#{file.gsub(jsdir, "")}",\n\t\t#{config}\n\t})) | |
end | |
end | |
"{\n#{out.join(",\n")}\n}" | |
end | |
def self.output(modules, filename, replace = false) | |
File.open(filename, "r+") do |file| | |
contents = (replace) ? file.read.gsub(replace, modules) : modules | |
file.puts(contents) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment