Skip to content

Instantly share code, notes, and snippets.

@noprompt
Created October 2, 2013 23:18
Show Gist options
  • Save noprompt/6801978 to your computer and use it in GitHub Desktop.
Save noprompt/6801978 to your computer and use it in GitHub Desktop.
Google Closure docset for Dash (Ruby script).
DOC_PATH = "./Closure.docset/Contents/Resources/Documents"
DB_PATH = "./Closure.docset/Contents/Resources/docSet.dsidx"
CLOSURE_GIT_URL = "https://code.google.com/p/closure-library.docs/"
ICON_URL = "http://docs.closure-library.googlecode.com/git/static/images/16px.png"
# Setup
puts "Setting up..."
system("mkdir -p #{DOC_PATH}")
puts "Downloading documentation..."
system("git clone #{CLOSURE_GIT_URL} #{DOC_PATH}")
puts "Downloading icon..."
unless File.exists?("icon.png")
system("curl -O #{ICON_URL}")
system("mv 16px.png Closure.docset/icon.png")
end
puts "Writing Info.plist..."
File.open("./Closure.docset/Contents/Info.plist", "w") do |f|
f.puts <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>Google Closure</string>
<key>CFBundleName</key>
<string>Google Closure</string>
<key>DocSetPlatformFamily</key>
<string>Google Closure</string>
<key>isDashDocset</key> <true/>
<key>isJavaScriptEnabled</key><true/>
<key>dashIndexFilePath</key>
<string>index.html</string>
</dict>
</plist>
PLIST
end
puts "Building the database..."
system("rm #{DB_PATH} 2>/dev/null")
system("touch #{DB_PATH}")
files = Dir.entries(DOC_PATH).grep(/^(?:class|namespace|interface)/)
blank_query = "INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ('%s', '%s', '%s');"
File.open("tmp.sqlite3", "w") do |f|
f.puts "DROP TABLE IF EXISTS searchIndex;"
f.puts "CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);"
f.puts "CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);"
files.each do |file|
type, name = file.split("_", 2)
name = name.split(".", 2).first.gsub(/_/, ".")
type = type.capitalize
f.puts(blank_query % [name, type, file])
end
end
system("sqlite3 #{DB_PATH} < tmp.sqlite3")
puts "Cleaning up..."
system("rm tmp.sqlite3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment