當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。