diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-12-14 18:32:45 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-12-14 18:32:45 -0500 |
commit | 66f22b6ac4af6240d42ecc328808d2c364bc37c8 (patch) | |
tree | 872328dcb5803b396f65422e0214a9e614d06bd8 | |
parent | d5f88ee9e51ceeaf4705d3b456b33b779cf25a5c (diff) | |
download | sqlalchemy-66f22b6ac4af6240d42ecc328808d2c364bc37c8.tar.gz |
- try to get a contextual TOC on the left side
-rw-r--r-- | doc/build/builder/mako.py | 11 | ||||
-rw-r--r-- | doc/build/builder/toc.py | 33 | ||||
-rw-r--r-- | doc/build/core/index.rst | 2 | ||||
-rw-r--r-- | doc/build/core/schema.rst | 1 | ||||
-rw-r--r-- | doc/build/orm/index.rst | 2 | ||||
-rw-r--r-- | doc/build/templates/layout.mako | 6 |
6 files changed, 49 insertions, 6 deletions
diff --git a/doc/build/builder/mako.py b/doc/build/builder/mako.py index 0367bf018..e264cf989 100644 --- a/doc/build/builder/mako.py +++ b/doc/build/builder/mako.py @@ -3,11 +3,12 @@ from __future__ import absolute_import from sphinx.application import TemplateBridge from sphinx.jinja2glue import BuiltinTemplateLoader from mako.lookup import TemplateLookup +from .toc import TOCMixin import os rtd = os.environ.get('READTHEDOCS', None) == 'True' -class MakoBridge(TemplateBridge): +class MakoBridge(TOCMixin, TemplateBridge): def init(self, builder, *args, **kw): self.jinja2_fallback = BuiltinTemplateLoader() self.jinja2_fallback.init(builder, *args, **kw) @@ -15,6 +16,8 @@ class MakoBridge(TemplateBridge): builder.config.html_context['release_date'] = builder.config['release_date'] builder.config.html_context['site_base'] = builder.config['site_base'] + self.app = builder.app + self.lookup = TemplateLookup(directories=builder.config.templates_path, #format_exceptions=True, imports=[ @@ -40,15 +43,15 @@ class MakoBridge(TemplateBridge): template = template.replace(".html", ".mako") context['prevtopic'] = context.pop('prev', None) context['nexttopic'] = context.pop('next', None) - + context['app'] = self.app # local docs layout context['rtd'] = False context['toolbar'] = False context['base'] = "static_base.mako" - + context['current_subtoc'] = lambda: self.get_current_subtoc( + context['current_page_name']) # override context attributes self.setup_ctx(context) - context.setdefault('_', lambda x: x) return self.lookup.get_template(template).render_unicode(**context) diff --git a/doc/build/builder/toc.py b/doc/build/builder/toc.py new file mode 100644 index 000000000..11ebdd420 --- /dev/null +++ b/doc/build/builder/toc.py @@ -0,0 +1,33 @@ +class TOCMixin(object): + def get_current_subtoc(self, current_page_name): + """Return an integrated table of contents for the current page. + + This yields a hierarchy of TOC items that are only local + or sub-nested to the current page, in a structure whereby the + items that are on the immediate page can be distinguished from + those that are on sub-pages. + + """ + + raw_tree = self.app.env.get_toc_for( + current_page_name, self.app.builder) + + stack = [raw_tree] + while stack: + elem = stack.pop(0) + +# !list(context['current_subtoc']()) +# context['app'].env.get_toctree_for(current_page_name, context['app'].builder, False) +# context['app'].env.get_toc_for(current_page_name, context['app'].builder) + + iscurrent = elem.attributes.get('iscurrent', False) + refuri = elem.attributes.get('refuri', None) + if refuri is not None: + name = elem.children[0].rawsource + remainders = elem.children[1:] + if iscurrent: + yield refuri, name + else: + remainders = elem.children + + stack.extend(remainders) diff --git a/doc/build/core/index.rst b/doc/build/core/index.rst index 210f28412..120155abd 100644 --- a/doc/build/core/index.rst +++ b/doc/build/core/index.rst @@ -9,7 +9,7 @@ In contrast to the ORM’s domain-centric mode of usage, the SQL Expression Language provides a schema-centric usage paradigm. .. toctree:: - :maxdepth: 3 + :maxdepth: 2 tutorial expression_api diff --git a/doc/build/core/schema.rst b/doc/build/core/schema.rst index aeb04be18..fe2812e85 100644 --- a/doc/build/core/schema.rst +++ b/doc/build/core/schema.rst @@ -34,6 +34,7 @@ in creating real schema generation scripts. .. toctree:: :maxdepth: 1 + :hidden: metadata reflection diff --git a/doc/build/orm/index.rst b/doc/build/orm/index.rst index 6c12ebd38..2dc3c4b65 100644 --- a/doc/build/orm/index.rst +++ b/doc/build/orm/index.rst @@ -9,7 +9,7 @@ as well as automated persistence of Python objects, proceed first to the tutorial. .. toctree:: - :maxdepth: 3 + :maxdepth: 2 tutorial mapper_config diff --git a/doc/build/templates/layout.mako b/doc/build/templates/layout.mako index 23e57129b..f07f56cf8 100644 --- a/doc/build/templates/layout.mako +++ b/doc/build/templates/layout.mako @@ -177,6 +177,12 @@ withsidebar = bool(toc) and current_page_name != 'index' ${title} </%block> </a></h3> + <% + if title == 'Schema Definition Language': + import pdb + pdb.set_trace() + %> + ${toctree()} ${toc} % if rtd: |