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


Python Renderer.loadTemplates方法代码示例

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


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

示例1: loadTemplates

# 需要导入模块: from plasTeX.Renderers.PageTemplate import Renderer [as 别名]
# 或者: from plasTeX.Renderers.PageTemplate.Renderer import loadTemplates [as 别名]
    def loadTemplates(self, document):
        """Load templates as in PageTemplate but also look for packages that
        want to override some templates and handles extra css and javascript."""

        try:
            import jinja2
        except ImportError:
            log.error('Jinja2 is not available, hence the HTML5 renderer cannot be used.')

        _Renderer.loadTemplates(self, document)
        rendererdata = document.rendererdata['html5'] = dict()
        config = document.config

        rendererDir = os.path.dirname(__file__)
        themeDir = os.path.join(rendererDir, 'Theme', self.loadedTheme)

        srcDir = document.userdata['working-dir']
        buildDir = os.getcwd()

        # Theme css has already been copied by PageTemplate.loadTemplates,
        # provided config['general']['copy-theme-extras'] is true
        # Still try to create styles directory is case it's false
        try:
            os.mkdir('styles')
        except OSError:
            # This should mean the directory already exists
            pass

        # Start building the css list for use by the layout template
        if config['html5']['use-theme-css'] and config['general']['copy-theme-extras']:
            rendererdata['css'] = ['theme-' + config['html5']['theme-css'] + '.css']
        else:
            rendererdata['css'] = []

        # Theme js has already been copied by PageTemplate.loadTemplates,
        # provided config['general']['copy-theme-extras'] is true
        # Still try to create js directory is case it's false
        try:
            os.mkdir('js')
        except OSError:
            pass

        # Start building the js list for use by the layout template
        if (config['html5']['use-theme-js'] and 
                config['general']['copy-theme-extras']):
            rendererdata['js'] = sorted(
                    os.listdir(os.path.join(themeDir, 'js')))
        else:
            rendererdata['js'] = []

        for resrc in document.packageResources:
            # Next line may load templates or change
            # document.rendererdata['html5'] or copy some files to buildDir
            resrc.alter(
                    renderer=self,
                    rendererName='html5',
                    document=document,
                    target=buildDir)

        # Last loaded files (hence overriding everything else) come from user
        # configuration
        cssBuildDir = os.path.join(buildDir, 'styles')
        for css in config['html5']['extra-css']:
            rendererdata['css'].append(css)
            shutil.copy(os.path.join(srcDir, css), cssBuildDir)

        jsBuildDir = os.path.join(buildDir, 'js')
        for js in config['html5']['extra-js']:
            rendererdata['js'].append(js)
            shutil.copy(os.path.join(srcDir, js), jsBuildDir)
开发者ID:PatrickMassot,项目名称:plastex,代码行数:72,代码来源:__init__.py


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