Created
February 19, 2010 14:21
-
-
Save BDQ/308736 to your computer and use it in GitHub Desktop.
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
require 'rubygems' | |
require 'builder' | |
def add_directory(path, parent, name) | |
parent.dict do |dict| | |
dict.key "name" | |
dict.string name #"#{name} (#{path})" | |
dict.key "regexFolderFilter" | |
dict.string "!.*/(\\.[^/]*|CVS|_darcs|_MTN|\\{arch\\}|blib|.*~\\.nib|.*\\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$" | |
dict.key "sourceDirectory" | |
dict.string path[0...1] == "/" ? path : File.join(Dir.pwd, path) | |
end | |
end | |
def search_for_type(name, parent) | |
parent.dict do |dict| | |
dict.key "children" | |
dict.array do |arr| | |
#core (root) | |
path = name | |
if FileTest.directory? path | |
add_directory path, arr, "core (root)" | |
end | |
#core (vendored) | |
path = "vendor/spree/" + name | |
if FileTest.directory? path | |
add_directory path, arr, "core (vendor)" | |
end | |
add_extension_paths("vendor/extensions", arr, name) | |
end | |
dict.key "name" | |
dict.string name.split("/").last | |
end | |
end | |
def add_extension_paths(path, parent, name) | |
#check for vendor/extensions | |
if FileTest.directory? path | |
Dir::foreach(path) do |ext| | |
if FileTest.directory? File.join(path, ext) | |
next if %w(. ..).include? ext | |
ext_models_path = File.join(path, ext, name) | |
if FileTest.directory? ext_models_path | |
add_directory ext_models_path, parent, ext | |
end | |
end | |
end | |
end | |
end | |
def add_core_views(path, parent, name) | |
parent.dict do |dict| | |
dict.key "children" | |
dict.array do |arr| | |
if FileTest.directory? File.join(path, "app", "views") | |
add_directory File.join(path, "app", "views"), arr, "app-views" | |
end | |
add_extension_paths(File.join(path, "vendor", "extensions"), arr, "app/views") | |
end | |
dict.key "name" | |
dict.string name | |
end | |
end | |
#START | |
root_name = Dir.pwd.split("/").last | |
tmproj = Builder::XmlMarkup.new() | |
tmproj.instruct! :xml, :version => "1.0", :encoding => "UTF-8" | |
tmproj.declare! :DOCTYPE, :plist, :PUBLIC, "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd" | |
tmproj.plist(:version => "1.0") do |plist| | |
plist.dict do |dict| | |
dict.key "documents" | |
dict.array do |arr| | |
arr.dict do |dict| | |
dict.key "children" | |
dict.array do |arr| | |
#combine APP folders | |
arr.dict do |dict| | |
dict.key "children" | |
dict.array do |arr| | |
#process models first | |
search_for_type("app/models", arr) | |
#views | |
arr.dict do |dict| | |
dict.key "children" | |
dict.array do |arr| | |
# process views | |
if FileTest.directory? "vendor/spree" | |
#puts "Vendored Spree" | |
add_core_views("vendor/spree", arr, "core (vendor)") | |
add_extension_paths("vendor/extensions", arr, "app/views") | |
else | |
if FileTest.directory? "app" | |
#puts "Spree in root (clone?)" | |
add_core_views("./", arr, "core (root)") | |
else | |
#puts "Spree Gem" | |
env = File.new("config/environment.rb", "r").read | |
spree_version = env.scan(/^SPREE_GEM_VERSION ?= ?'(.*)'/) | |
if spree_version.size == 1 | |
spree_gem_path = File.join(ENV['GEM_HOME'], "gems", "spree-#{spree_version[0]}") | |
add_core_views(spree_gem_path, arr , "core (gem)") | |
end | |
add_extension_paths("vendor/extensions", arr, "app/views") | |
end | |
end | |
end | |
dict.key "name" | |
dict.string "views" | |
end | |
#finally controllers, helpers, metal | |
search_for_type("app/controllers", arr) | |
search_for_type("app/helpers", arr) | |
search_for_type("app/metal", arr) | |
end | |
dict.key "name" | |
dict.string "app" | |
end | |
#combine config folders | |
search_for_type("config", dict) | |
end | |
dict.key "name" | |
dict.string "virtual" | |
dict.key "expanded" | |
dict.true | |
end | |
add_directory("./", dict, root_name) | |
end | |
dict.key "showFileHierarchyDrawer" | |
dict.true | |
dict.key "windowFrame" | |
dict.string "{{200, 200}, {900, 900}}" | |
end | |
end | |
File.open("#{root_name}.tmproj", 'w') {|f| f.write(tmproj) } | |
`open #{root_name}.tmproj` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment