def template_from_config(self, logger): config = self.config template_cfg = {} if isinstance(config.rinoh_template, str): tmpl_path = path.join(self.confdir, config.rinoh_template) if path.isfile(tmpl_path): base = TemplateConfigurationFile(config.rinoh_template, source=self) template_cfg['base'] = base template_cls = template_cfg['base'].template else: template_cls = DocumentTemplate.from_string( config.rinoh_template) elif isinstance(config.rinoh_template, TemplateConfiguration): template_cfg['base'] = config.rinoh_template template_cls = config.rinoh_template.template else: template_cls = config.rinoh_template language = config.language if language: try: template_cfg['language'] = Language.from_string(language) except KeyError: logger.warning( "The language '{}' is not supported by rinohtype.".format( language)) sphinx_config = template_cls.Configuration('Sphinx conf.py options', **template_cfg) return sphinx_config
def template_from_config(config, confdir, warn): template_cfg = {} if isinstance(config.rinoh_template, str): tmpl_path = path.join(confdir, config.rinoh_template) if path.isfile(tmpl_path): template_cfg['base'] = TemplateConfigurationFile(tmpl_path) template_cls = template_cfg['base'].template else: template_cls = DocumentTemplate.from_string(config.rinoh_template) elif isinstance(config.rinoh_template, TemplateConfiguration): template_cfg['base'] = config.rinoh_template template_cls = config.rinoh_template.template else: template_cls = config.rinoh_template if isinstance(config.rinoh_stylesheet, str): stylesheet_path = path.join(confdir, config.rinoh_stylesheet) stylesheet = StyleSheet.from_string(stylesheet_path if path.isfile( stylesheet_path) else config.rinoh_stylesheet) else: stylesheet = config.rinoh_stylesheet if config.pygments_style is not None: if stylesheet is not None: base = stylesheet elif 'base' in template_cfg: base = template_cfg['base']['stylesheet'] else: base = template_cls.stylesheet.default_value stylesheet = pygments_style_to_stylesheet(config.pygments_style, base) if stylesheet is not None: template_cfg['stylesheet'] = stylesheet language = config.language if language: try: template_cfg['language'] = Language.from_string(language) except KeyError: warn('The language "{}" is not supported by rinohtype.'.format( language)) variables = {} if config.rinoh_paper_size: variables['paper_size'] = config.rinoh_paper_size sphinx_config = template_cls.Configuration('Sphinx conf.py options', **template_cfg) sphinx_config.variables.update(variables) return sphinx_config
def template_from_config(config, confdir, warn): template_cfg = {} if isinstance(config.rinoh_template, str): tmpl_path = path.join(confdir, config.rinoh_template) if path.isfile(tmpl_path): template_cfg['base'] = TemplateConfigurationFile(tmpl_path) template_cls = template_cfg['base'].template else: template_cls = DocumentTemplate.from_string(config.rinoh_template) elif isinstance(config.rinoh_template, TemplateConfiguration): template_cfg['base'] = config.rinoh_template template_cls = config.rinoh_template.template else: template_cls = config.rinoh_template if isinstance(config.rinoh_stylesheet, str): stylesheet_path = path.join(confdir, config.rinoh_stylesheet) stylesheet = StyleSheet.from_string(stylesheet_path if path.isfile(stylesheet_path) else config.rinoh_stylesheet) else: stylesheet = config.rinoh_stylesheet if config.pygments_style is not None: if stylesheet is not None: base = stylesheet elif 'base' in template_cfg: base = template_cfg['base']['stylesheet'] else: base = template_cls.stylesheet.default_value stylesheet = pygments_style_to_stylesheet(config.pygments_style, base) if stylesheet is not None: template_cfg['stylesheet'] = stylesheet language = config.language if language: try: template_cfg['language'] = Language.from_string(language) except KeyError: warn('The language "{}" is not supported by rinohtype.') variables = {} if config.rinoh_paper_size: variables['paper_size'] = config.rinoh_paper_size sphinx_config = template_cls.Configuration('Sphinx conf.py options', **template_cfg) sphinx_config.variables.update(variables) return sphinx_config