From 4b13669a3d18750cd7a6592a19ae9357cdeb92f3 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 27 Oct 2013 14:43:35 -0400 Subject: [PATCH] - farm out everthing to do with rtd out to the sqlalchemy.org site --- doc/build/builder/mako.py | 52 +++------ doc/build/templates/genindex.mako | 2 +- doc/build/templates/layout.mako | 17 ++- doc/build/templates/page.mako | 2 +- doc/build/templates/rtd_layout.mako | 164 ---------------------------- doc/build/templates/search.mako | 2 +- 6 files changed, 33 insertions(+), 206 deletions(-) delete mode 100644 doc/build/templates/rtd_layout.mako diff --git a/doc/build/builder/mako.py b/doc/build/builder/mako.py index 8003ed4177..0367bf0186 100644 --- a/doc/build/builder/mako.py +++ b/doc/build/builder/mako.py @@ -23,49 +23,31 @@ class MakoBridge(TemplateBridge): ) if rtd: + # RTD layout, imported from sqlalchemy.org import urllib2 - template_url = builder.config['site_base'] + "/docs_base.mako" - template = urllib2.urlopen(template_url).read() - self.lookup.put_string("/rtd_base.mako", template) + template = urllib2.urlopen(builder.config['site_base'] + "/docs_adapter.mako").read() + self.lookup.put_string("docs_adapter.mako", template) + + setup_ctx = urllib2.urlopen(builder.config['site_base'] + "/docs_adapter.py").read() + lcls = {} + exec(setup_ctx, lcls) + self.setup_ctx = lcls['setup_context'] + + def setup_ctx(self, context): + pass def render(self, template, context): template = template.replace(".html", ".mako") context['prevtopic'] = context.pop('prev', None) context['nexttopic'] = context.pop('next', None) - # RTD layout - if rtd: - # add variables if not present, such - # as if local test of READTHEDOCS variable - if 'MEDIA_URL' not in context: - context['MEDIA_URL'] = "http://media.readthedocs.org/" - if 'slug' not in context: - context['slug'] = context['project'].lower() - if 'url' not in context: - context['url'] = "/some/test/url" - if 'current_version' not in context: - context['current_version'] = "latest" - - if 'name' not in context: - context['name'] = context['project'].lower() - - context['rtd'] = True - context['toolbar'] = True - context['layout'] = "rtd_layout.mako" - context['base'] = "rtd_base.mako" - - context['pdf_url'] = "%spdf/%s/%s/%s.pdf" % ( - context['MEDIA_URL'], - context['slug'], - context['current_version'], - context['slug'] - ) # local docs layout - else: - context['rtd'] = False - context['toolbar'] = False - context['layout'] = "layout.mako" - context['base'] = "static_base.mako" + context['rtd'] = False + context['toolbar'] = False + context['base'] = "static_base.mako" + + # 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/templates/genindex.mako b/doc/build/templates/genindex.mako index 0a25b6724b..9ea6795bc5 100644 --- a/doc/build/templates/genindex.mako +++ b/doc/build/templates/genindex.mako @@ -1,4 +1,4 @@ -<%inherit file="${context['layout']}"/> +<%inherit file="layout.mako"/> <%block name="show_title" filter="util.striptags"> ${_('Index')} diff --git a/doc/build/templates/layout.mako b/doc/build/templates/layout.mako index ba3e81c010..50f1d5de65 100644 --- a/doc/build/templates/layout.mako +++ b/doc/build/templates/layout.mako @@ -6,9 +6,9 @@ <%doc> Structural elements are all prefixed with "docs-" - to prevent conflicts when the structure is integrated into the + to prevent conflicts when the structure is integrated into the main site. - + docs-container -> docs-header -> docs-search @@ -31,7 +31,7 @@ withsidebar = bool(toc) and current_page_name != 'index' <%block name="head_title"> % if current_page_name != 'index': - ${capture(self.show_title) | util.striptags} — + ${capture(self.show_title) | util.striptags} — % endif ${docstitle|h} @@ -39,6 +39,9 @@ withsidebar = bool(toc) and current_page_name != 'index'
<%block name="headers"> + ${parent.headers()} + + @@ -50,9 +53,13 @@ withsidebar = bool(toc) and current_page_name != 'index' FILE_SUFFIX: '${file_suffix}' }; + + % for scriptfile in script_files + self.attr.local_script_files: % endfor + + % if hasdoc('about'): @@ -72,6 +79,8 @@ withsidebar = bool(toc) and current_page_name != 'index' % if prevtopic: % endif + +
@@ -129,7 +138,7 @@ withsidebar = bool(toc) and current_page_name != 'index' % endfor % endif % if current_page_name != 'index': - » ${self.show_title()} + » ${self.show_title()} % endif

diff --git a/doc/build/templates/page.mako b/doc/build/templates/page.mako index 61cf9a05ed..e0f98cf648 100644 --- a/doc/build/templates/page.mako +++ b/doc/build/templates/page.mako @@ -1,2 +1,2 @@ -<%inherit file="${context['layout']}"/> +<%inherit file="layout.mako"/> ${body| util.strip_toplevel_anchors} \ No newline at end of file diff --git a/doc/build/templates/rtd_layout.mako b/doc/build/templates/rtd_layout.mako deleted file mode 100644 index a3083bd7ba..0000000000 --- a/doc/build/templates/rtd_layout.mako +++ /dev/null @@ -1,164 +0,0 @@ -<%inherit file="/layout.mako"/> - -<% - newscript = [] - # strip out script files that RTD wants to provide - for script in script_files: - for token in ("jquery.js", "underscore.js", "doctools.js"): - if token in script: - break - else: - newscript.append(script) - script_files[:] = newscript -%> - -<%block name="headers"> - - - - - - - - ${parent.headers()} - - -${next.body()} - -<%block name="footer"> -${parent.footer()} - -## Keep this here, so that the RTD logo doesn't stomp on the bottom of the theme. -
-
-
- - - - - - -% if analytics_code: - - -% endif - - diff --git a/doc/build/templates/search.mako b/doc/build/templates/search.mako index 68e3fb991a..83a3fcd84a 100644 --- a/doc/build/templates/search.mako +++ b/doc/build/templates/search.mako @@ -1,4 +1,4 @@ -<%inherit file="${context['layout']}"/> +<%inherit file="layout.mako"/> <%! local_script_files = ['_static/searchtools.js'] -- 2.47.2