summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirkjan Ochtman <dirkjan@ochtman.nl>2013-11-09 16:23:38 +0100
committerDirkjan Ochtman <dirkjan@ochtman.nl>2013-11-09 16:23:38 +0100
commitd56471a1cbecf50512d65d58181201873330db16 (patch)
treea25ee36799a1ae01a5d1957d5ba59f43f1c55f3b
parentb9fbec6e5faf979d6fe5a945ff936f9b26fe1227 (diff)
downloadcouchdb-dash-docset.tar.gz
docs: enable building a Dash docsetdash-docset
-rw-r--r--share/doc/build/Makefile.am1
-rw-r--r--share/doc/ext/dashdocset.py116
-rw-r--r--share/doc/images/icon-32px.pngbin0 -> 819 bytes
-rw-r--r--share/doc/src/conf.py2
4 files changed, 118 insertions, 1 deletions
diff --git a/share/doc/build/Makefile.am b/share/doc/build/Makefile.am
index a6a5e76dc..a521db38d 100644
--- a/share/doc/build/Makefile.am
+++ b/share/doc/build/Makefile.am
@@ -453,6 +453,7 @@ src_files_html = \
sphinx_extensions = \
../ext/configdomain.py \
+ ../ext/dashdocset.py \
../ext/github.py \
../ext/httpdomain.py \
../ext/http-api-descr.json
diff --git a/share/doc/ext/dashdocset.py b/share/doc/ext/dashdocset.py
new file mode 100644
index 000000000..a17518b0a
--- /dev/null
+++ b/share/doc/ext/dashdocset.py
@@ -0,0 +1,116 @@
+## Licensed under the Apache License, Version 2.0 (the "License"); you may not
+## use this file except in compliance with the License. You may obtain a copy of
+## the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+## License for the specific language governing permissions and limitations under
+## the License.
+
+# Based on Ruby script by Stephen Benner
+# https://github.com/SteveBenner/couchdb-dash-docset/
+
+from lxml import html
+from sphinx.util.console import bold
+import urllib2, os, sqlite3, shutil, plistlib, imp, tarfile
+
+FILE_PATH = os.path.abspath(__file__)
+DOC_DIR = os.path.dirname(os.path.dirname(FILE_PATH))
+BUILD_DIR = os.path.join(DOC_DIR, 'build', 'html')
+ICON_SRC = os.path.join(DOC_DIR, 'images', 'icon-32px.png')
+
+DS_DIR = os.path.join(BUILD_DIR, 'CouchDB.docset')
+DOCS = os.path.join(DS_DIR, 'Contents', 'Resources', 'Documents')
+PLIST_PATH = os.path.join(DS_DIR, 'Contents', 'info.plist')
+DB_PATH = os.path.join(DS_DIR, 'Contents', 'Resources', 'docSet.dsidx')
+
+FEED_PATH = os.path.join(BUILD_DIR, 'CouchDB.xml')
+DIST_PATH = os.path.join(BUILD_DIR, 'CouchDB.tgz')
+
+PLIST = {
+ 'CFBundleIdentifier': 'CouchDB',
+ 'DocSetPlatformFamily': 'CouchDB',
+ 'isDashDocset': True,
+ 'DocSetPublisherName': 'Apache CouchDB Project',
+ 'dashIndexFilePath': 'index.html',
+ 'isJavaScriptEnabled': True,
+}
+
+def ignore(dir, contents):
+ if '_sources' in dir:
+ return contents
+ elif 'docset' in dir:
+ return contents
+ else:
+ return []
+
+def build(app, exception):
+
+ if exception is not None:
+ return
+
+ if 'HTML' not in app.builder.__class__.__name__:
+ return
+
+ app.info(bold('building docset...'), True)
+ entries = []
+ title = lambda s: s.split(' ', 1)[1]
+ contents = html.parse(open(os.path.join(BUILD_DIR, 'contents.html')))
+ for a in contents.findall('.//li[@class="toctree-l1"]/a'):
+ entries.append(('Guide', title(a.text), a.attrib['href']))
+
+ for a in contents.findall('.//li[@class="toctree-l1"][10]/ul/li/a'):
+ if title(a.text) == 'API Basics': continue
+ entries.append(('Category', title(a.text), a.attrib['href']))
+
+ for a in contents.findall('.//li[@class="toctree-l1"][11]/ul/li/a'):
+ entries.append(('Struct', title(a.text), a.attrib['href']))
+
+ for a in contents.findall('.//li[@class="toctree-l1"][3]/ul/li/ul/li/a'):
+ if a.text.startswith('3.1'): continue
+ entries.append(('Option', title(a.text), a.attrib['href']))
+
+ for a in contents.findall('.//li[@class="toctree-l1"][10]/ul/li/ul/li/a'):
+ if a.text.startswith('10.1'): continue
+ text = title(''.join(i for i in a.itertext()))
+ entries.append(('Method', text, a.attrib['href']))
+
+ os.makedirs(os.path.dirname(DOCS))
+ shutil.copyfile(ICON_SRC, os.path.join(DS_DIR, 'icon.png'))
+ shutil.copytree(BUILD_DIR, DOCS, ignore=ignore)
+ PLIST['CFBundleName'] = 'CouchDB ' + app.config.version
+ plistlib.writePlist(PLIST, PLIST_PATH)
+
+ db = sqlite3.connect(DB_PATH)
+ cur = db.cursor()
+ cur.execute('CREATE TABLE searchIndex ('
+ 'id INTEGER PRIMARY KEY, '
+ 'name TEXT, '
+ 'type TEXT, '
+ 'path TEXT'
+ ');')
+
+ cur.execute('CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);')
+ for e in entries:
+ cur.execute('INSERT INTO searchIndex (type, name, path) VALUES (?, ?, ?)', e)
+
+ db.commit()
+ db.close()
+
+ with tarfile.open(DIST_PATH, 'w:gz') as f:
+ f.add(DS_DIR)
+
+ shutil.rmtree(DS_DIR)
+ with open(FEED_PATH, 'w') as f:
+ print >> f, '<entry>'
+ print >> f, '<version>%s</version>' % app.config.version
+ print >> f, '<url>http://docs.couchdb.org/latest/en/CouchDB.tgz</url>'
+ print >> f, '</entry>'
+
+ app.info(' done')
+
+def setup(app):
+ app.connect('build-finished', build)
diff --git a/share/doc/images/icon-32px.png b/share/doc/images/icon-32px.png
new file mode 100644
index 000000000..aaf8f9421
--- /dev/null
+++ b/share/doc/images/icon-32px.png
Binary files differ
diff --git a/share/doc/src/conf.py b/share/doc/src/conf.py
index 3d2536e25..73da03d1a 100644
--- a/share/doc/src/conf.py
+++ b/share/doc/src/conf.py
@@ -18,7 +18,7 @@ import sys
sys.path.insert(0, os.path.abspath('../ext'))
extensions = ["sphinx.ext.todo", "sphinx.ext.extlinks", 'github',
- 'httpdomain', 'configdomain']
+ 'httpdomain', 'configdomain', 'dashdocset']
_info = {}
_regex = re.compile('m4_define\(\[(.+)\],\s+\[(.+)\]\)')