当前位置: 首页>>代码示例>>Python>>正文


Python jinja2.FunctionLoader方法代码示例

本文整理汇总了Python中jinja2.FunctionLoader方法的典型用法代码示例。如果您正苦于以下问题:Python jinja2.FunctionLoader方法的具体用法?Python jinja2.FunctionLoader怎么用?Python jinja2.FunctionLoader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jinja2的用法示例。


在下文中一共展示了jinja2.FunctionLoader方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render_from_string

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import FunctionLoader [as 别名]
def render_from_string(
        self,
        input_string=None,
        context=None,
        template_name=None,
        input_dictionary=None
    ):
        if template_name is None:
            template_name = 'input.md'
        if input_dictionary is None:
            input_dictionary = {}
        if input_string is not None:
            input_dictionary[template_name] = input_string
        if context is None:
            context = {}

        def load_string(template_name):
            return input_dictionary[template_name]

        loaders = [FunctionLoader(load_string)]

        return render_template_to_string(template_name, context, loaders=loaders) 
开发者ID:innolitics,项目名称:rdm,代码行数:24,代码来源:render_test.py

示例2: _create_jinja_environment

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import FunctionLoader [as 别名]
def _create_jinja_environment(runfiles, site_root, link_ext):
  def _Load(path):
    loc = runfiles.Rlocation(posixpath.join(WORKSPACE_DIR, TEMPLATE_PATH, path))
    if loc:
      with open(loc, "rb") as f:
        return f.read().decode("utf-8")
    return None

  env = jinja2.Environment(
      loader=jinja2.FunctionLoader(_Load),
      keep_trailing_newline=True,
      line_statement_prefix='%')
  env.filters['markdown'] = lambda text: jinja2.Markup(mistune.markdown(text))
  env.filters['doc_link'] = (
      lambda fname: site_root + '/' + fname + '.' + link_ext)
  env.filters['link'] = lambda fname: site_root + '/' + fname
  return env


# TODO(dzc): Remove this workaround once we switch to a self-contained Python
# binary format such as PEX. 
开发者ID:bazelbuild,项目名称:skydoc,代码行数:23,代码来源:main.py

示例3: __init__

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import FunctionLoader [as 别名]
def __init__(self, *args, sql=None, executor=None, **kwargs):

        if not executor:
            executor = DebugSQLExecutor()
        elif isinstance(executor, str):
            executor = SQLExecutor.for_kind(executor)()
        elif issubclass(executor, SQLExecutor):
            executor = executor()

        MutableMeasureProvider.__init__(self, *args, **kwargs)
        self._base_sql = textwrap.dedent(sql).strip() if sql else None
        self.executor = executor
        self.dialect = DIALECTS[executor.dialect]

        self.add_measure('count', shared=True, distribution='count', default=0)

        self._template_environment = jinja2.Environment(loader=jinja2.FunctionLoader(lambda x: x), undefined=jinja2.StrictUndefined)
        self._template_environment.filters.update({
            'col': self._col,
            'val': self._val
        }) 
开发者ID:matthewwardrop,项目名称:mensor,代码行数:23,代码来源:sql.py

示例4: __init__

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import FunctionLoader [as 别名]
def __init__(self, *args, **kwds):
    super(Template, self).__init__(*args, **kwds)
    self.jinja = jinja2.Environment(
        loader=jinja2.FunctionLoader(self._get_subtemplate), autoescape=True) 
开发者ID:google,项目名称:loaner,代码行数:6,代码来源:template_model.py

示例5: prepare

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import FunctionLoader [as 别名]
def prepare(self, filters=None, tests=None, globals={}, **kwargs):
        from jinja2 import Environment, FunctionLoader
        if 'prefix' in kwargs: # TODO: to be removed after a while
            raise RuntimeError('The keyword argument `prefix` has been removed. '
                'Use the full jinja2 environment name line_statement_prefix instead.')
        self.env = Environment(loader=FunctionLoader(self.loader), **kwargs)
        if filters: self.env.filters.update(filters)
        if tests: self.env.tests.update(tests)
        if globals: self.env.globals.update(globals)
        if self.source:
            self.tpl = self.env.from_string(self.source)
        else:
            self.tpl = self.env.get_template(self.filename) 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:15,代码来源:__init__.py

示例6: prepare

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import FunctionLoader [as 别名]
def prepare(self, filters=None, tests=None, **kwargs):
        from jinja2 import Environment, FunctionLoader
        if 'prefix' in kwargs: # TODO: to be removed after a while
            raise RuntimeError('The keyword argument `prefix` has been removed. '
                'Use the full jinja2 environment name line_statement_prefix instead.')
        self.env = Environment(loader=FunctionLoader(self.loader), **kwargs)
        if filters: self.env.filters.update(filters)
        if tests: self.env.tests.update(tests)
        if self.source:
            self.tpl = self.env.from_string(self.source)
        else:
            self.tpl = self.env.get_template(self.filename) 
开发者ID:exiahuang,项目名称:SalesforceXyTools,代码行数:14,代码来源:bottle.py

示例7: prepare

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import FunctionLoader [as 别名]
def prepare(self, filters=None, tests=None, globals={}, **kwargs):
        from jinja2 import Environment, FunctionLoader
        self.env = Environment(loader=FunctionLoader(self.loader), **kwargs)
        if filters: self.env.filters.update(filters)
        if tests: self.env.tests.update(tests)
        if globals: self.env.globals.update(globals)
        if self.source:
            self.tpl = self.env.from_string(self.source)
        else:
            self.tpl = self.env.get_template(self.name) 
开发者ID:brycesub,项目名称:silvia-pi,代码行数:12,代码来源:bottle.py

示例8: prepare

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import FunctionLoader [as 别名]
def prepare(self, prefix='#', filters=None, tests=None):
        from jinja2 import Environment, FunctionLoader
        self.env = Environment(line_statement_prefix=prefix,
                               loader=FunctionLoader(self.loader))
        if filters: self.env.filters.update(filters)
        if tests: self.env.tests.update(tests)
        if self.source:
            self.tpl = self.env.from_string(self.source)
        else:
            self.tpl = self.env.get_template(self.filename) 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:12,代码来源:bottle2.py

示例9: prepare

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import FunctionLoader [as 别名]
def prepare(self, filters=None, tests=None, globals={}, **kwargs):
        from jinja2 import Environment, FunctionLoader
        self.env = Environment(loader=FunctionLoader(self.loader), **kwargs)
        if filters: self.env.filters.update(filters)
        if tests: self.env.tests.update(tests)
        if globals: self.env.globals.update(globals)
        if self.source:
            self.tpl = self.env.from_string(self.source)
        else:
            self.tpl = self.env.get_template(self.filename) 
开发者ID:warriorframework,项目名称:warriorframework,代码行数:12,代码来源:bottle.py

示例10: _RenderTemplate

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import FunctionLoader [as 别名]
def _RenderTemplate(template_subdir, template_name, **context):
  """Loads a template file and renders it to unicode.

  Args:
    template_subdir: The subdirectory in gae/templates containing the template
        file.
    template_name: The name of the template file.
    **context: Optional key/value pairs to render into the template.

  Returns:
    The given template file rendered with the given context as a unicode string.

  Raises:
    jinja2.TemplateNotFound: if the given template file doesn't exist.
  """
  # Create a partial loading function, which will return the contents of the
  # template given just the template name.
  loading_func = functools.partial(_LoadTemplate, template_subdir)

  # Construct an Environment and retrieve the Template.
  env = jinja2.Environment(
      loader=jinja2.FunctionLoader(loading_func),
      autoescape=True,
      extensions=['jinja2.ext.autoescape'],
      finalize=lambda value: value or '',
      variable_start_string='[[',
      variable_end_string=']]',
      undefined=jinja2.StrictUndefined)
  template = env.get_template(template_name)

  # Render the template with the provided context.
  return template.render(**context) 
开发者ID:google,项目名称:upvote,代码行数:34,代码来源:template_utils.py


注:本文中的jinja2.FunctionLoader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。