Skip to content

Commit

Permalink
Merge pull request #13 from cjsheets/dev
Browse files Browse the repository at this point in the history
rewrite dropdown logic
  • Loading branch information
cjsheets authored Mar 12, 2018
2 parents 20cc779 + dda7d39 commit 9053d4f
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 90 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: python
python:
- '2.7'
script:
- touch foo
deploy:
provider: pypi
user: cjsheets
password:
secure: w/ma9MlBTjsF4cstbIVyPNfEqOdo52P6PSvP/apn8wzRVgHwqW6FnUYrkpVM1Jxu80ReeIzy34P9bt43ihsoWc/NnvTSm2Zfer2QR0xKUXW+lg0yVQbSaqznp7eBY/9stAAYU1lCoK/EhuyGLxbErMk3F9OaSi42RrC19XahkjpHPIyCPhZ/a71ADgdbhusEvaavaqEfJKfQ4+RT49AZCJnt87nMtmqmSgNe3N2xLD7kfig/9VJlmC7gDBHEIXOP3kphAStngknxQ+UMRnTqr/K34+yOFlDzfrM+AEmHbSeOl9a9Ung3KuVnz9mdlwRQUmUwW06b1nYNUW7QGdXG1LaybLbLY5p8CFMggXS97o7YXbHLyJdF0pyxMWkP2rhaeAXDJAbKtz/i5DCd1P7tEPjf4q+potqkp/LGq7T+lCLxnA6tN8zfuCHyMmTcSbvWpm06RiSZsXTw+LvevCcIeAq36jzaI6/kkc5mwVVLI6P+r8Raf2s9iIEStaG5o2rDyetiP/228So6fIdAhn+ZqG3DxLSVx0ULXevB8cW6jskDw0uKaTUEcdqsc9ndsHGiS+B9kbKPF85XBSPnZviUsYaKA8u7+y59sn59COQ31j4npf0+ukf1i+kouT2lpFX6bwMiBWu7ZrJhD7KvMO0JGb83L26zE6iEclprj5zvH2E=
on:
tags: true
branch: master
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A ReadTheDocs theme for [MkDocs](http://www.mkdocs.org/) with collapsing menu su
![Dropdown Demo](docs/img/example.png)


How to use
How to install
----------

Install the ReadTheDocs Dropdown theme with pip:
Expand All @@ -27,19 +27,34 @@ theme:
```


Features
--------
How to use
----------

You have a couple folder/document-structure options when using this theme.

## Default Settings

Both ReadTheDocs and MkDocs use a "long-page" document structure. There is no nesting of pages. See [user-guide/instructions/](http://readthedocs.sheets.ch/user-guide/instructions/) as an example.

Collapsing is based on top-level headings in each page.

```
# Page Title <-- Top level heading
content, content, content
```


* Based on the ReadTheDocs theme build-into MkDocs
* Adds dropdown functionality to the sidebar (similar to ReadTheDocs)

For further discussion, see [this issue](https://github.com/mkdocs/mkdocs/issues/588#issuecomment-341931422).


Considerations
--------------

ToDo
* Based on the ReadTheDocs theme build-into MkDocs
* Adds dropdown functionality to the sidebar (similar to ReadTheDocs)

For further discussion, see [this issue](https://github.com/mkdocs/mkdocs/issues/588#issuecomment-341931422).



Expand Down
5 changes: 4 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ site_name: ReadTheDocs Dropdown
site_description: 'Updated version of MkDocs ReadTheDocs theme'
site_author: 'Chad Sheets'

theme_dir: rtd_dropdown
theme:
name: rtd-dropdown
# Default settings
collapse_by_default: false

repo_url: https://github.com/cjsheets/readthedocs-dropdown

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#git+http://github.com/cjsheets/mkdocs.git@dev#egg=mkdocs
mkdocs
#mkdocs
9 changes: 3 additions & 6 deletions rtd_dropdown/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,9 @@
</div>

<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
{%- block site_nav %}
{% set navlevel = 1 %}
{% for nav_item in nav %}
{% include 'nav.html' %}
{% endfor %}
{%- endblock %}
{%- block site_nav %}
{% include 'nav.html' %}
{%- endblock %}
</div>
&nbsp;
</nav>
Expand Down
5 changes: 3 additions & 2 deletions rtd_dropdown/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ $( document ).ready(function() {
$('table').addClass('docutils');

toggleCurrent = function (elem) {
console.log('toggle');
var parent_li = elem.closest('li');
parent_li.siblings('li.current').removeClass('current');
parent_li.siblings().find('li.current').removeClass('current');
Expand All @@ -53,11 +52,13 @@ $( document ).ready(function() {
var link = $(this);
expand = $('<span class="toctree-expand"></span>');
expand.on('click', function (ev) {
console.log('click');
toggleCurrent(link);
ev.stopPropagation();
return false;
});
link.on('click', function (ev) {
toggleCurrent(link);
});
link.prepend(expand);
});
});
Expand Down
21 changes: 21 additions & 0 deletions rtd_dropdown/nav-item.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{%- set navlevel = navlevel + 1%}
<li class="{% if nav_item.active%}current{%endif%} toctree-l{{navlevel}}">
<a href="{{ nav_item.url }}" title="{{ nav_item.title }}"
class="{% if nav_item.active%}current{%endif%}">
{{ nav_item.title }}
</a>

{#| Children are only added to the currently selected root item |#}
{% if nav_item.active %}
{% if nav_item.children %}
<ul class="{% if nav_item.active%}current{%endif%} subnav">
{% for nav_item in nav_item.children %}
{% include "nav-item.html" %}
{% endfor %}
</ul>
{% endif %}
{% if not nav_item.children %}
{% include "toc.html" %}
{% endif %}
{% endif %}
</li>
112 changes: 55 additions & 57 deletions rtd_dropdown/nav.html
Original file line number Diff line number Diff line change
@@ -1,65 +1,63 @@
{%- set child_url = '' %} {#| Target of the current link |#}


{%- if nav_item.children %}
{%- if nav_item.children[0].input_path %}
{%- set urlList = nav_item.children[0].input_path.split('.') %}
{%- else %}
{%- if nav_item.children[0].children[0].input_path %}
{%- set urlList = nav_item.children[0].children[0].input_path.split('.') %}
{#| Loop over the major, root-level groups |#}
{% for nav_item in nav %}

{#| Determine the full path of the root-level link |#}
{%- set nav_item_children = nav_item.children %}
{%- set nav_ns = namespace(url_list=false) %}

{%- if nav_item.children is defined %}
{% for _ in range(1, 6) %}
{%- if nav_item_children is defined %}
{%- if nav_item_children[0].input_path is defined %}
{%- set nav_ns.url_list = nav_item_children[0].input_path.split('.') %}
{%- else %}
{%- set nav_item_children = nav_item_children[0].children %}
{%- endif %}
{%- endif %}
{% endfor %}
{%- if nav_ns.url_list %}
{%- set fileName = nav_ns.url_list.pop() %}
{%- set child_url = '.'.join(nav_ns.url_list) %}
{%- endif %}
{%- endif %}
{%- set fileName = urlList.pop() %}
{%- set child_url = '.'.join(urlList) %}
{%- endif %}


{%- if navlevel == 1 and child_url == '' %}
<ul class="{% if nav_item.active%}current{%endif%}" href="{{ nav_item.url }}">
<li class="toctree-l{{ navlevel }}{% if nav_item.active %} current{%endif%}">
{%- endif %}
{%- if child_url is not defined %}
{#| There are no children, only a root-level item |#}
{%- set child_url = nav_item.abs_url %}
{%- endif %}

{%- if navlevel == 1 and child_url != '' %}
{%- set navlevel = 0 %}
{% if nav_item.children %}
<p class="caption">{{ nav_item.title }}</p>
{%- elif child_url == '' %}
<a class="{% if nav_item.active%}current{%endif%}" href="{{ nav_item.url }}">{{ nav_item.title }}</a>
{%- else %}
<a class="{% if nav_item.active%}current{%endif%}" href="/{{ child_url }}">{{ nav_item.title }}</a>
{%- endif %}

{% endif %}

{%- if navlevel == 1 and child_url != '' %}
<ul class="{% if nav_item.active%}current{%endif%}">
{%- if nav_item == page %}
{% include 'toc.html' %}
{%- endif %}
{%- if nav_item.children %}
{%- for nav_item in nav_item.children %}
<li class="toctree-l1{% if nav_item.active%} current{%endif%}">
{%- set navlevel = navlevel + 1%}
{% include 'nav.html' %}
{%- set navlevel = navlevel - 1%}
</li>
{%- endfor %}
{%- endif %}
</ul>
{% elif nav_item.active and (nav_item == page or nav_item.children) %}
<ul class="subnav">
{%- if nav_item == page %}
{% include 'toc.html' %}
{%- endif %}
{%- if nav_item.children %}
{%- set navlevel = navlevel + 1%}
{%- for nav_item in nav_item.children %}
<li class="toctree-l2{% if nav_item.active%} current{%endif%} 1">
{% include 'nav.html' %}
</li>
{%- endfor %}
{%- set navlevel = navlevel - 1%}
<ul class="{% if nav_item.active%}current{%endif%}" href="{{ child_url }}">
{% if nav_item.children %}
{% for nav_item in nav_item.children %}
{% include "nav-item.html" %}
{% endfor %}
{%- else %}
{#| Rendering toc directly for root-level items prevents double-title |#}
{% if nav_item.active %}
<li class="{% if nav_item.active%}current{%endif%} toctree-l1">
<a class="{% if nav_item.active%}current{%endif%}" href="{{ child_url }}">{{ nav_item.title }}</a>
{%- set navlevel = navlevel + 1 %}
{% include "toc.html" %}
</li>
{%- else %}
<li class="{% if nav_item.active%}current{%endif%} toctree-l1">
<a class="{% if nav_item.active%}current{%endif%}" href="{{ child_url }}">{{ nav_item.title }}</a>
</li>
{%- endif %}
</ul>
{%- endif %}
{%- endif %}
</ul>

<!--
| This is a hacky way to pass setting from the template generator to the
| javascript that drives the dropdown functionality
-->
<div style="width: 1px; height: 1px; visibility: none;">

</div>

{%- if navlevel == 1 and child_url == '' %}
</li></ul>
{%- endif %}
{% endfor %}
27 changes: 27 additions & 0 deletions rtd_dropdown/toc-item.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{%- set toclevel = toclevel + 1 %}

{#| Support collapse-by-default setting |#}
{% if toc_item.active and (toc_ns.top_level_headings == 1 or not
(config.theme is defined and config.theme.collapse_by_default)) %}
{%- set class_is_active = 'current' %}
{% endif %}

{% if toc_item.children is defined and toc_item.children | length > 0 and toclevel < 2 %}
<li class="{{class_is_active}} toctree-l{{navlevel + 1}}">
{% if toc_ns.top_level_headings is defined and toc_ns.top_level_headings > 1 %}
<a href="{{ toc_item.url }}" title="{{ nav_item.title }}"
class="{{class_is_active}}">
{{ toc_item.title }}
</a>
{% endif %}
<ul class="{% if toc_item.active%}current{%endif%} subnav">
{% for toc_item in toc_item.children %}
{% include "toc-item.html" %}
{% endfor %}
</ul>
</li>
{% else %}
<li class="toctree-l{{navlevel + 1}} toc-item">
<a href="{{ toc_item.url }}" title="{{ nav_item.title }}">{{ toc_item.title }}</a>
</li>
{% endif %}
28 changes: 13 additions & 15 deletions rtd_dropdown/toc.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{% for toc_item in page.toc %}
<li class="toctree-l2 {% if toc_item.active%}current{%endif%}">
{% if nav_item.title != toc_item.title %}
<a class="{% if toc_item.active%}current{%endif%}" href="{{ toc_item.url }}">{{ toc_item.title }}</a>
{% endif %}
{% if toc_item.children %}
<ul class="{% if not toc_item.active%} submenu-toc{%endif%}">
{% for toc__item in toc_item.children %}
<li class="toctree-l3{% if navlevel > 1%} toc-item{%endif%}" >
<a class="toctree-l3" href="{{ toc__item.url }}">{{ toc__item.title }}</a>
</li>
{% if page.toc %}

{%- set toc_ns = namespace(top_level_headings=0) %}
{% for toc_item in page.toc %}
{%- set toc_ns.top_level_headings = toc_ns.top_level_headings + 1 %}
{% endfor %}

{%- set toclevel = 0 %}
<ul class="{% if nav_item.active%}current{%endif%} subnav">
{% for toc_item in page.toc %}
{% include "toc-item.html" %}
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = '0.0.9'
VERSION = '0.0.10'

with open("requirements.txt") as data:
install_requires = [
Expand Down

0 comments on commit 9053d4f

Please sign in to comment.