本文整理汇总了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)