Skip to content

Commit

Permalink
Merge pull request #43 from reaperhulk/support-new-plist-keys
Browse files Browse the repository at this point in the history
Dash supports more plist keys: DashDocSetFallbackURL & isJavaScriptEnabled
  • Loading branch information
hynek committed Oct 11, 2015
2 parents 9046788 + 7c5ca39 commit 27b8d51
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 6 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ contributors:
- `Dirkjan Ochtman <https://github.com/djc>`_
- `Henrique Bastos <https://github.com/henriquebastos>`_
- `Łukasz Langa <https://github.com/ambv>`_
- `Paul Kehrer <https://github.com/reaperhulk>`_
20 changes: 17 additions & 3 deletions doc2dash/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,18 @@ def emit(self, record):
@click.option(
"--verbose", "-v", is_flag=True, help="Be verbose."
)
@click.option(
"--enable-js", "-j", is_flag=True,
help="Enable bundled and external Javascript."
)
@click.option(
"--online-redirect-url", "-u", default=None,
help="The base URL of the online documentation."
)
@click.version_option(version=__version__)
def main(source, force, name, quiet, verbose, destination, add_to_dash,
add_to_global, icon, index_page):
add_to_global, icon, index_page, enable_js,
online_redirect_url):
"""
Convert docs from SOURCE to Dash.app's docset format.
"""
Expand Down Expand Up @@ -113,7 +122,8 @@ def main(source, force, name, quiet, verbose, destination, add_to_dash,
.format(click.format_filename(source))
)
raise SystemExit(errno.EINVAL)
docset = prepare_docset(source, dest, name, index_page)
docset = prepare_docset(source, dest, name, index_page, enable_js,
online_redirect_url)
doc_parser = dt(doc_path=docset.docs)
log.info((u'Converting ' + click.style('{parser_name}', bold=True) +
u' docs from "{src}" to "{dst}".')
Expand Down Expand Up @@ -212,7 +222,8 @@ class DocSet(object):
pass


def prepare_docset(source, dest, name, index_page):
def prepare_docset(source, dest, name, index_page, enable_js,
online_redirect_url):
"""
Create boilerplate files & directories and copy vanilla docs inside.
Expand All @@ -237,9 +248,12 @@ def prepare_docset(source, dest, name, index_page):
'DocSetPlatformFamily': name.lower(),
'DashDocSetFamily': 'python',
'isDashDocset': True,
'isJavaScriptEnabled': enable_js,
}
if index_page is not None:
plist_cfg['dashIndexFilePath'] = index_page
if online_redirect_url is not None:
plist_cfg['DashDocSetFallbackURL'] = online_redirect_url

plistlib.writePlist(
plist_cfg,
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changelog
The move from ``unicode_literals`` to explicit prefixes broke some things that are fixed now.
(`#29 <https://github.com/hynek/doc2dash/issues/29>`_, `#30 <https://github.com/hynek/doc2dash/issues/30>`_)
- Fix detection of `pydoctor 0.5 <http://bazaar.launchpad.net/~mwhudson/pydoctor/dev/revision/605>`_. (`#31 <https://github.com/hynek/doc2dash/issues/31>`_)
- Add support for ``--enable-js`` and ``--online-redirect-url`` options. See :doc:`/usage` for more information.


2.0.0 (2014-08-14)
Expand Down
10 changes: 10 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ Valid ``OPTIONS`` are the following:
Create docset in doc2dash's default global directory [``~/Library/Application Support/ doc2dash/DocSets``] and add it to Dash.app
Works only on OS X and when Dash.app is installed.

.. option:: -j, --enable-js

Enable bundled and external javascript.

.. option:: -u, --online-redirect-url

As of Dash 3.0 users can open the online version of pages from within docsets.
To enable this, you must set this value to the base URL of your online documentation.
e.g. ``https://doc2dash.readthedocs.org/``

.. option:: -q, --quiet

Limit output to errors and warnings.
Expand Down
59 changes: 56 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def test_normal_flow(monkeypatch, tmpdir, runner):
"""
Integration test with a mocked out parser.
"""
def fake_prepare(source, dest, name, index_page):
def fake_prepare(source, dest, name, index_page, enable_js,
online_redirect_url):
os.mkdir(dest)
db_conn = sqlite3.connect(':memory:')
db_conn.row_factory = sqlite3.Row
Expand Down Expand Up @@ -209,7 +210,8 @@ def test_plist_creation(self, monkeypatch, tmpdir):
monkeypatch.setattr(shutil, 'copytree', m_ct)
os.mkdir('bar')
docset = main.prepare_docset(
"some/path/foo", 'bar', name="foo", index_page=None
"some/path/foo", 'bar', name="foo", index_page=None,
enable_js=False, online_redirect_url=None
)
m_ct.assert_called_once_with(
'some/path/foo',
Expand All @@ -223,6 +225,7 @@ def test_plist_creation(self, monkeypatch, tmpdir):
'DocSetPlatformFamily': 'foo',
'DashDocSetFamily': 'python',
'isDashDocset': True,
'isJavaScriptEnabled': False,
}
with sqlite3.connect('bar/Contents/Resources/docSet.dsidx') as db_conn:
cur = db_conn.cursor()
Expand All @@ -239,7 +242,9 @@ def test_with_index_page(self, monkeypatch, tmpdir):
monkeypatch.setattr(shutil, 'copytree', m_ct)
os.mkdir('bar')
docset = main.prepare_docset('some/path/foo', 'bar', name='foo',
index_page='foo.html')
index_page='foo.html',
enable_js=False,
online_redirect_url=None)
p = plistlib.readPlist(docset.plist)
assert p == {
'CFBundleIdentifier': 'foo',
Expand All @@ -248,6 +253,54 @@ def test_with_index_page(self, monkeypatch, tmpdir):
'DashDocSetFamily': 'python',
'isDashDocset': True,
'dashIndexFilePath': 'foo.html',
'isJavaScriptEnabled': False,
}

def test_with_javascript_enabled(self, monkeypatch, tmpdir):
"""
If an index page is passed, it is added to the plist.
"""
monkeypatch.chdir(tmpdir)
m_ct = MagicMock()
monkeypatch.setattr(shutil, 'copytree', m_ct)
os.mkdir('bar')
docset = main.prepare_docset('some/path/foo', 'bar', name='foo',
index_page='foo.html',
enable_js=True,
online_redirect_url=None)
p = plistlib.readPlist(docset.plist)
assert p == {
'CFBundleIdentifier': 'foo',
'CFBundleName': 'foo',
'DocSetPlatformFamily': 'foo',
'DashDocSetFamily': 'python',
'isDashDocset': True,
'dashIndexFilePath': 'foo.html',
'isJavaScriptEnabled': True,
}

def test_with_online_redirect_url(self, monkeypatch, tmpdir):
"""
If an index page is passed, it is added to the plist.
"""
monkeypatch.chdir(tmpdir)
m_ct = MagicMock()
monkeypatch.setattr(shutil, 'copytree', m_ct)
os.mkdir('bar')
docset = main.prepare_docset('some/path/foo', 'bar', name='foo',
index_page='foo.html',
enable_js=False,
online_redirect_url="https://domain.com")
p = plistlib.readPlist(docset.plist)
assert p == {
'CFBundleIdentifier': 'foo',
'CFBundleName': 'foo',
'DocSetPlatformFamily': 'foo',
'DashDocSetFamily': 'python',
'isDashDocset': True,
'dashIndexFilePath': 'foo.html',
'isJavaScriptEnabled': False,
'DashDocSetFallbackURL': "https://domain.com",
}


Expand Down

0 comments on commit 27b8d51

Please sign in to comment.