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


Python FileSystemLoader.get_source方法代码示例

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


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

示例1: templated_file_contents

# 需要导入模块: from jinja2 import FileSystemLoader [as 别名]
# 或者: from jinja2.FileSystemLoader import get_source [as 别名]
def templated_file_contents(options, configfile):
    paths = options["searchpath"].split(",") # CSV of PATHs
    if os.path.isdir(paths[0]):
        loader = FileSystemLoader(paths)
    else:
        loader = URLloader(paths)
    env = Environment(loader=loader)
    contents, config_full_path, _a_lambda_ = loader.get_source(env, configfile)
    template = env.from_string(contents, globals=options)
    return template.render(options)
开发者ID:sglebs,项目名称:ndeploy,代码行数:12,代码来源:ndeploy.py

示例2: _get_nereid_template_messages_from_file

# 需要导入模块: from jinja2 import FileSystemLoader [as 别名]
# 或者: from jinja2.FileSystemLoader import get_source [as 别名]
 def _get_nereid_template_messages_from_file(self, template_dir, template):
     """
     Same generator as _get_nereid_template_messages, but for specific files.
     """
     extract_options = self._get_nereid_template_extract_options()
     loader = FileSystemLoader(template_dir)
     file_obj = open(loader.get_source({}, template)[1])
     for message_tuple in babel_extract(
             file_obj, GETTEXT_FUNCTIONS,
             ['trans:'], extract_options):
         yield (template,) + message_tuple
开发者ID:priyankajain18,项目名称:nereid,代码行数:13,代码来源:translation.py

示例3: to_html

# 需要导入模块: from jinja2 import FileSystemLoader [as 别名]
# 或者: from jinja2.FileSystemLoader import get_source [as 别名]
 def to_html(self, embed_css=True):
     import os
     from jinja2 import Environment, FileSystemLoader
     loader = FileSystemLoader(
         os.path.join(os.path.dirname(os.path.abspath(__file__)), 'html'))
     env = Environment(loader=loader)
     template = env.get_template('template.html')
     return template.render(rulesets=self.rulesets,
         lines=self.lines,
         text=self.text,
         css=loader.get_source(env, 'style.css')[0] if embed_css else None)
开发者ID:bhattisatish,项目名称:WritingSmellDetector,代码行数:13,代码来源:wsd.py

示例4: TemplateService

# 需要导入模块: from jinja2 import FileSystemLoader [as 别名]
# 或者: from jinja2.FileSystemLoader import get_source [as 别名]
class TemplateService(EngineService):
    endpoint_methods = None
    published_members = ['render', 'get_base_templates', 'render_from_string', 'get_source']
    name = 'template'
    # Project's base path
    __base_path = os.path.dirname(os.path.realpath(__file__))
    # User's application base path
    __app_base_path = None
    __app_base_templates_dir = None
    # Our internal jinja2 template env
    __template_env = None
    __fs_loader = None

    def __init__(self, engine):

        super(TemplateService, self).__init__(engine)

        self.__app_base_path = self.engine.get('csettings', 'all')()['templates_root']
        self.__app_base_templates_dir = self.engine.get('csettings', 'all')()['base_templates_dir']

        self.__fs_loader = FileSystemLoader(
            # Search path gets saved as a list in jinja2 internally, so we could
            # add to it if necessary.
            searchpath=[self.__base_path + '/templates', self.__app_base_path],
            encoding='utf-8',
        )
        self.__template_env = Environment(loader=self.__fs_loader, trim_blocks=True)

    def render(self, template_name, context):
        """
        Context must be a dictionary right now, but could also be **kwargs
        """
        # Add the global corus settings from engine to the context
        context['csettings'] = self.engine.get('csettings', 'all')()
        return self.__template_env.get_template(template_name).render(context)

    def render_from_string(self, s, context):
        # TODO we should probably make a new loader for getting stuff out of NDB
        return self.__template_env.from_string(s).render(context)

    def get_base_templates(self):
        # The call to FS loader list_templates is a sorted set, so just append, return
        bts = []
        for t in self.__fs_loader.list_templates():
            if t.startswith(self.__app_base_templates_dir):
                bts.append(t)
        return bts

    def get_source(self, template_name):
        source, filename, uptodate = self.__fs_loader.get_source(self.__template_env, template_name)
        return source
开发者ID:wrunk,项目名称:corus,代码行数:53,代码来源:template.py

示例5: _get_nereid_template_messages

# 需要导入模块: from jinja2 import FileSystemLoader [as 别名]
# 或者: from jinja2.FileSystemLoader import get_source [as 别名]
    def _get_nereid_template_messages(cls):
        """
        Extract localizable strings from the templates of installed modules.

        For every string found this function yields a
        `(module, template, lineno, function, message)` tuple, where:

        * module is the name of the module in which the template is found
        * template is the name of the template in which message was found
        * lineno is the number of the line on which the string was found,
        * function is the name of the gettext function used (if the string
          was extracted from embedded Python code), and
        * message is the string itself (a unicode object, or a tuple of
          unicode objects for functions with multiple string arguments).
        * comments List of Translation comments if any. Comments in the code
          should have a prefix `trans:`. Example::

              {{ _(Welcome) }} {# trans: In the top banner #}
        """
        extract_options = cls._get_nereid_template_extract_options()
        logger = logging.getLogger('nereid.translation')

        for module, directory in cls._get_installed_module_directories():
            template_dir = os.path.join(directory, 'templates')
            if not os.path.isdir(template_dir):
                # The template directory does not exist. Just continue
                continue

            logger.info(
                'Found template directory for module %s at %s' % (
                    module, template_dir
                )
            )
            # now that there is a template directory, load the templates
            # using a simple filesystem loader and load all the
            # translations from it.
            loader = FileSystemLoader(template_dir)
            env = Environment(loader=loader)
            extensions = '.html,.jinja'
            for template in env.list_templates(extensions=extensions):
                logger.info('Loading from: %s:%s' % (module, template))
                file_obj = open(loader.get_source({}, template)[1])
                for message_tuple in babel_extract(
                        file_obj, GETTEXT_FUNCTIONS,
                        ['trans:'], extract_options):
                    yield (module, template) + message_tuple
开发者ID:priyankajain18,项目名称:nereid,代码行数:48,代码来源:translation.py

示例6: get_source

# 需要导入模块: from jinja2 import FileSystemLoader [as 别名]
# 或者: from jinja2.FileSystemLoader import get_source [as 别名]
    def get_source(self, environment, template):
        if LOCAL:
            # during local development, templates are files and we want "uptodate" feature
            return FileSystemLoader.get_source(self, environment, template)

        # on production server template may come from zip file
        for searchpath in self.searchpath:
            filename = os.path.join(searchpath, template)
            contents = universal_read(filename)
            if contents is None:
                continue
            contents = contents.decode(self.encoding)

            def uptodate():
                return True

            return contents, filename, uptodate
        raise TemplateNotFound(template)
开发者ID:binaryage,项目名称:drydrop,代码行数:20,代码来源:jinja_loaders.py

示例7: to_html

# 需要导入模块: from jinja2 import FileSystemLoader [as 别名]
# 或者: from jinja2.FileSystemLoader import get_source [as 别名]
    def to_html(self, embed_css=True, include_empty=False):
        '''
        Convert results into HTML.
        
        Args:
            embed_css: A boolean indicating whether css should be
                embedded into the HTML code.
            include_empty: A boolean indicating whether empty rulesets,
                rules and patterns should be returned.

        Returns:
            A string of HTML code representing the results.
        '''
        from jinja2 import Environment, FileSystemLoader
        loader = FileSystemLoader(
            os.path.join(os.path.dirname(os.path.abspath(__file__)), 'html'))
        env = Environment(loader=loader)
        template = env.get_template('template.html')
        return template.render(rulesets=self.rulesets,
            lines=self.lines,
            text=self.text,
            css=loader.get_source(env, 'style.css')[0] if embed_css else None,
            include_empty=include_empty)
开发者ID:utapyngo,项目名称:WritingSmellDetector,代码行数:25,代码来源:wsd.py

示例8: get_source

# 需要导入模块: from jinja2 import FileSystemLoader [as 别名]
# 或者: from jinja2.FileSystemLoader import get_source [as 别名]
 def get_source(self, environment, template):
     source, path, validator = FileSystemLoader.get_source(self, environment, template)
     if len(source) > 0 and source[0] != "\n":
         source = "\n" + source
     return source, path, validator
开发者ID:isqua-test,项目名称:point-core,代码行数:7,代码来源:template.py


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