Skip to content

Instantly share code, notes, and snippets.

@cho45
Created February 9, 2010 09:26
Show Gist options
  • Select an option

  • Save cho45/299044 to your computer and use it in GitHub Desktop.

Select an option

Save cho45/299044 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby1.9
#
require 'rubygems'
require 'nokogiri'
require 'pathname'
require 'yaml'
require 'uri'
require 'fileutils'
sdk = Pathname.new(ARGV[0] || '~/sdk/android/').expand_path
sdk_ref = sdk + 'docs'
classes = sdk_ref + 'reference/classes.html'
index = []
refroot = Pathname.new('docs/reference')
classes.open {|f| Nokogiri.HTML(f) }.search('tr.api').each do |api|
a = api.at('td.jd-linkcol a')
from = classes.parent + a["href"]
path = (refroot + a["href"]).to_s
name = a.text
index << [name, [ URI.escape(path) ]]
p "File: #{path}"
from.open {|f| Nokogiri.HTML(f) }.search('#pubctors, #pubmethods, #promethods').search('tr.api td.jd-linkcol a').each do |a|
pathl = ((refroot + from.parent).relative_path_from(sdk) + a["href"]).to_s
next unless pathl[path]
p "Link: #{pathl}"
index << ["#{name}.#{a.text}", [ URI.escape(pathl, /[^a-zA-Z0-9;_#\/-]/) ]]
end
end
index.uniq!
root = Pathname.new("AndroidSDK.chm")
root.rmtree rescue nil
root.mkpath
contents = root + "Contents"
contents.mkpath
(contents + "PkgInfo").open("w") {|f| f << "BNDL????" }
(contents + "Info.plist").open("w") {|f| f << DATA.read }
resources = contents + "Resources"
resources.mkpath
(resources + "docs").mkpath
%w|images assets reference|.each do |name|
FileUtils.cp_r(sdk_ref + name, resources + "docs" + name, :verbose => true)
end
(resources + "keyword.yaml").open("w") {|f| f << index.to_yaml }
(resources + "toc.yaml").open("w") {|f| f << {} }
(resources + "docs/assets/android-developer-docs.css").open("a") {|f|
f << <<-EOS
#header {
height: auto;
border: none;
min-width: auto;
}
#headerLeft,
#headerLinks,
#search,
#side-nav {
display: none;
}
#body-content {
position: static;
}
#doc-content {
overflow: show;
width: auto;
margin: 0;
}
html {
overflow: auto;
}
body {
overflow: show;
}
EOS
}
Pathname.glob((resources + "docs/assets/android-developer-docs.js").to_s) do |f|
f.truncate(0)
end
__END__
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string></string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CHMTitle</key>
<string>Android</string>
<key>CHMHome</key>
<string>/index.html</string>
<key>CHMKeyword</key>
<string>/keyword.yaml</string>
<key>CHMTOC</key>
<string>/toc.yaml</string>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment