本文整理汇总了Python中sphinx.jinja2glue.BuiltinTemplateLoader.render_string方法的典型用法代码示例。如果您正苦于以下问题:Python BuiltinTemplateLoader.render_string方法的具体用法?Python BuiltinTemplateLoader.render_string怎么用?Python BuiltinTemplateLoader.render_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sphinx.jinja2glue.BuiltinTemplateLoader
的用法示例。
在下文中一共展示了BuiltinTemplateLoader.render_string方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MakoBridge
# 需要导入模块: from sphinx.jinja2glue import BuiltinTemplateLoader [as 别名]
# 或者: from sphinx.jinja2glue.BuiltinTemplateLoader import render_string [as 别名]
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)
示例2: MakoBridge
# 需要导入模块: from sphinx.jinja2glue import BuiltinTemplateLoader [as 别名]
# 或者: from sphinx.jinja2glue.BuiltinTemplateLoader import render_string [as 别名]
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)
示例3: MakoBridge
# 需要导入模块: from sphinx.jinja2glue import BuiltinTemplateLoader [as 别名]
# 或者: from sphinx.jinja2glue.BuiltinTemplateLoader import render_string [as 别名]
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)
示例4: MakoBridge
# 需要导入模块: from sphinx.jinja2glue import BuiltinTemplateLoader [as 别名]
# 或者: from sphinx.jinja2glue.BuiltinTemplateLoader import render_string [as 别名]
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)