Exemple #1
0
class MakoBridge(TemplateBridge):
    def init(self, builder, *args, **kw):
        self.jinja2_fallback = BuiltinTemplateLoader()
        self.jinja2_fallback.init(builder, *args, **kw)

        builder.config.html_context['site_base'] = builder.config['site_base']

        self.lookup = TemplateLookup(
            directories=builder.config.templates_path,
            imports=[
                "from builder import util"
            ],
            #format_exceptions=True,
        )

    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'] = "mako-test-slug"
            if 'url' not in context:
                context['url'] = "/some/test/url"
            if 'current_version' not in context:
                context['current_version'] = "some_version"
            if 'versions' not in context:
                context['versions'] = [('default', '/default/')]

            context['docs_base'] = "http://readthedocs.org"
            context['toolbar'] = True
            context['layout'] = "rtd_layout.mako"
            context['pdf_url'] = "%spdf/%s/%s/%s.pdf" % (
                    context['MEDIA_URL'],
                    context['slug'],
                    context['current_version'],
                    context['slug']
            )
        # local docs layout
        else:
            context['toolbar'] = False
            context['docs_base'] = "/"
            context['layout'] = "layout.mako"

        context.setdefault('_', lambda x:x)
        return self.lookup.get_template(template).render_unicode(**context)

    def render_string(self, template, context):
        # this is used for  .js, .css etc. and we don't have
        # local copies of that stuff here so use the jinja render.
        return self.jinja2_fallback.render_string(template, context)
Exemple #2
0
class ChocoBridge(TemplateBridge):
    def init(self, builder, *args, **kw):
        self.jinja2_fallback = BuiltinTemplateLoader()
        self.jinja2_fallback.init(builder, *args, **kw)

        builder.config.html_context['site_base'] = builder.config['site_base']

        self.lookup = TemplateLookup(
            directories=builder.config.templates_path,
            imports=["from builder import util"],
            #format_errors=True,
        )

    def render(self, template, context):
        template = template.replace(".html", ".choco")
        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'] = "choco-test-slug"
            if 'url' not in context:
                context['url'] = "/some/test/url"
            if 'current_version' not in context:
                context['current_version'] = "some_version"
            if 'versions' not in context:
                context['versions'] = [('default', '/default/')]

            context['docs_base'] = "http://readthedocs.org"
            context['toolbar'] = True
            context['layout'] = "rtd_layout.choco"
            context['pdf_url'] = "%spdf/%s/%s/%s.pdf" % (
                context['MEDIA_URL'], context['slug'],
                context['current_version'], context['slug'])
        # local docs layout
        else:
            context['toolbar'] = False
            context['docs_base'] = "/"
            context['layout'] = "layout.choco"

        context.setdefault('_', lambda x: x)
        return self.lookup.get_template(template).render_unicode(**context)

    def render_string(self, template, context):
        # this is used for  .js, .css etc. and we don't have
        # local copies of that stuff here so use the jinja render.
        return self.jinja2_fallback.render_string(template, context)
Exemple #3
0
class MakoBridge(TemplateBridge):
    def init(self, builder, *args, **kw):
        self.jinja2_fallback = BuiltinTemplateLoader()
        self.jinja2_fallback.init(builder, *args, **kw)

        builder.config.html_context['release_date'] = builder.config['release_date']
        builder.config.html_context['site_base'] = builder.config['site_base']

        self.lookup = TemplateLookup(directories=builder.config.templates_path,
            #format_exceptions=True,
            imports=[
                "from builder import util"
            ]
        )

        if rtd:
            # RTD layout, imported from sqlalchemy.org
            import urllib2
            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)

        # local docs layout
        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)

    def render_string(self, template, context):
        # this is used for  .js, .css etc. and we don't have
        # local copies of that stuff here so use the jinja render.
        return self.jinja2_fallback.render_string(template, context)
class MakoBridge(TemplateBridge):
    def init(self, builder, *args, **kw):
        self.jinja2_fallback = BuiltinTemplateLoader()
        self.jinja2_fallback.init(builder, *args, **kw)

        builder.config.html_context['release_date'] = builder.config[
            'release_date']
        builder.config.html_context['site_base'] = builder.config['site_base']

        self.lookup = TemplateLookup(
            directories=builder.config.templates_path,
            #format_exceptions=True,
            imports=["from builder import util"])

        if rtd:
            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)

    def render(self, template, context):
        template = template.replace(".html", ".mako")
        context['prevtopic'] = context.pop('prev', None)
        context['nexttopic'] = context.pop('next', None)
        version = context['version']
        pathto = context['pathto']

        # 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.setdefault('_', lambda x: x)
        return self.lookup.get_template(template).render_unicode(**context)

    def render_string(self, template, context):
        # this is used for  .js, .css etc. and we don't have
        # local copies of that stuff here so use the jinja render.
        return self.jinja2_fallback.render_string(template, context)
Exemple #5
0
class MakoBridge(TOCMixin, TemplateBridge):
    def init(self, builder, *args, **kw):
        self.jinja2_fallback = BuiltinTemplateLoader()
        self.jinja2_fallback.init(builder, *args, **kw)

        builder.config.html_context['release_date'] = \
            builder.config['release_date']
        protocol_agnostic = builder.config['site_base']
        protocol_agnostic = re.sub("^https?://", "//", protocol_agnostic)
        builder.config.html_context['site_base'] = protocol_agnostic

        self.app = builder.app

        package_dir = os.path.abspath(os.path.dirname(__file__))
        template_path = os.path.join(
            package_dir, 'themes', builder.config.html_theme)

        self.lookup = TemplateLookup(
            strict_undefined=True,
            directories=builder.config.templates_path + [
                template_path
            ],
            # format_exceptions=True,
            imports=[
                "from zzzeeksphinx import util"
            ]
        )

        if rtd and builder.config['site_base']:
            import urllib2
            if builder.config['site_adapter_template']:
                # remote site layout / startup files
                template_name = builder.config['site_adapter_template']

                template = urllib2.urlopen(
                    builder.config['site_base'] + "/" + template_name).read()
                self.lookup.put_string(template_name, template)

            py_name = builder.config['site_adapter_py']
            if py_name:
                setup_ctx = urllib2.urlopen(
                    builder.config['site_base'] + "/" + py_name).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)
        context['app'] = self.app
        # local docs layout
        context['rtd'] = False
        context['toolbar'] = False
        context['base'] = "static_base.mako"
        context['parent_toc'] = self.get_current_subtoc
        context['bridge'] = self
        context.setdefault('toc', None)
        context.setdefault('pdf_url', None)
        context.setdefault('metatags', None)
        context.setdefault("canonical_url", None)
        context.setdefault("single_version", None)
        context.setdefault("rtd_language", "en")

        # override context attributes
        self.setup_ctx(context)
        context.setdefault('_', lambda x: x)
        return self.lookup.get_template(template).render_unicode(**context)

    def render_string(self, template, context):
        # this is used for  .js, .css etc. and we don't have
        # local copies of that stuff here so use the jinja render.
        return self.jinja2_fallback.render_string(template, context)
Exemple #6
0
class MakoBridge(TemplateBridge):
    def init(self, builder, *args, **kw):
        self.jinja2_fallback = BuiltinTemplateLoader()
        self.jinja2_fallback.init(builder, *args, **kw)

        builder.config.html_context["release_date"] = builder.config["release_date"]
        builder.config.html_context["site_base"] = builder.config["site_base"]

        self.lookup = TemplateLookup(
            directories=builder.config.templates_path,
            # format_exceptions=True,
            imports=["from builder import util"],
        )

        if rtd:
            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)

    def render(self, template, context):
        template = template.replace(".html", ".mako")
        context["prevtopic"] = context.pop("prev", None)
        context["nexttopic"] = context.pop("next", None)
        version = context["version"]
        pathto = context["pathto"]

        # 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.setdefault("_", lambda x: x)
        return self.lookup.get_template(template).render_unicode(**context)

    def render_string(self, template, context):
        # this is used for  .js, .css etc. and we don't have
        # local copies of that stuff here so use the jinja render.
        return self.jinja2_fallback.render_string(template, context)
Exemple #7
0
class MakoBridge(TOCMixin, TemplateBridge):
    def init(self, builder, *args, **kw):
        self.jinja2_fallback = BuiltinTemplateLoader()
        self.jinja2_fallback.init(builder, *args, **kw)
        # for gettext builder
        self.environment = self.jinja2_fallback.environment

        builder.config.html_context["release_date"] = builder.config[
            "release_date"
        ]
        protocol_agnostic = builder.config["site_base"]
        protocol_agnostic = re.sub("^https?://", "//", protocol_agnostic)
        builder.config.html_context["site_base"] = protocol_agnostic

        self.app = builder.app

        package_dir = os.path.abspath(os.path.dirname(__file__))
        template_path = os.path.join(
            package_dir, "themes", builder.config.html_theme
        )

        # note: don't use strict_undefined.   it means that a variable
        # cannot even be used conditionally, or with any inheriting template
        # that attempts to override the %def/%block that would normally
        # call upon that variable.
        self.lookup = TemplateLookup(
            directories=[template_path]
            + (
                [
                    dir_
                    for dir_ in builder.theme.get_theme_dirs()
                    if "zzzeeksphinx" in dir_
                ]
                if hasattr(builder, "theme")
                else []
            ),
            # format_exceptions=True,
            imports=["from zzzeeksphinx import util"],
        )

        if rtd and builder.config["site_base"]:
            import requests

            if builder.config["site_adapter_template"]:
                # remote site layout / startup files
                template_name = builder.config["site_adapter_template"]

                template = requests.get(
                    builder.config["site_base"] + "/" + template_name
                ).content
                self.lookup.put_string(template_name, template)

            py_name = builder.config["site_adapter_py"]
            if py_name:
                setup_ctx = requests.get(
                    builder.config["site_base"] + "/" + py_name
                ).content
                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)
        context["app"] = self.app
        # local docs layout
        context["rtd"] = False
        context["toolbar"] = False
        context["base"] = "static_base.mako"
        context["parent_toc"] = self.get_current_subtoc
        context["local_toc"] = self.get_local_toc
        context["bridge"] = self
        context.setdefault("toc", None)
        context.setdefault("pdf_url", None)
        context.setdefault("metatags", None)
        context.setdefault("canonical_url", None)
        context.setdefault("single_version", None)
        context.setdefault("rtd_language", "en")
        context.setdefault("is_prerelease_version", False)
        context.setdefault("is_legacy_version", False)
        context.setdefault("is_current_version", False)
        # override context attributes
        self.setup_ctx(context)
        context.setdefault("_", lambda x: x)
        return self.lookup.get_template(template).render_unicode(**context)

    def render_string(self, template, context):
        # this is used for  .js, .css etc. and we don't have
        # local copies of that stuff here so use the jinja render.
        return self.jinja2_fallback.render_string(template, context)
Exemple #8
0
class MakoBridge(TemplateBridge):
    def init(self, builder, *args, **kw):
        self.jinja2_fallback = BuiltinTemplateLoader()
        self.jinja2_fallback.init(builder, *args, **kw)

        builder.config.html_context['release_date'] = builder.config['release_date']
        builder.config.html_context['site_base'] = builder.config['site_base']

        self.lookup = TemplateLookup(directories=builder.config.templates_path,
            #format_exceptions=True,
            imports=[
                "from builder import util"
            ]
        )

        if rtd:
            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)

    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"

            # pdf gen is just broken on RTD
            #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.setdefault('_', lambda x: x)
        return self.lookup.get_template(template).render_unicode(**context)

    def render_string(self, template, context):
        # this is used for  .js, .css etc. and we don't have
        # local copies of that stuff here so use the jinja render.
        return self.jinja2_fallback.render_string(template, context)