def __init__(self, confdir: str, templates_paths: List[str], system_templates_paths: List[str]) -> None: self.loaders = [] self.sysloaders = [] for templates_path in templates_paths: loader = SphinxFileSystemLoader(path.join(confdir, templates_path)) self.loaders.append(loader) for templates_path in system_templates_paths: loader = SphinxFileSystemLoader(templates_path) self.loaders.append(loader) self.sysloaders.append(loader)
def handle_builderinit(kb_app: kb, sphinx_app): """ Load the resources, types, etc. from the registry We can get resources etc. from 3 location: classes in kaybee itself, classes in the doc project, and YAML "typedef" files in the doc project. """ # Add the root of this theme, plus macros template_bridge = sphinx_app.builder.templates t = os.path.join(os.path.dirname(inspect.getfile(kaybee_bulma)), 'templates') template_bridge.loaders.append(SphinxFileSystemLoader(t)) m = os.path.join(os.path.dirname(inspect.getfile(kaybee_bulma)), 'templates/macros') template_bridge.loaders.append(SphinxFileSystemLoader(m))
def builder_inited(app): """Update the Sphinx builder. :param sphinx.application.Sphinx app: Sphinx application object. """ # Add this extension's _templates directory to Sphinx. templates_dir = os.path.join(os.path.dirname(__file__), '_templates') app.builder.templates.pathchain.insert(0, templates_dir) app.builder.templates.loaders.insert( 0, SphinxFileSystemLoader(templates_dir)) app.builder.templates.templatepathlen += 1 # Add versions.html to sidebar. if '**' not in app.config.html_sidebars: # default_sidebars was deprecated in Sphinx 1.6+, so only use it if possible (to maintain # backwards compatibility), else don't use it. try: app.config.html_sidebars[ '**'] = StandaloneHTMLBuilder.default_sidebars + [ 'versions.html' ] except AttributeError: app.config.html_sidebars['**'] = ['versions.html'] elif 'versions.html' not in app.config.html_sidebars['**']: app.config.html_sidebars['**'].append('versions.html')
def __init__(self, search_path: Union[str, List[str]]) -> None: if isinstance(search_path, str): search_path = [search_path] else: # filter "None" paths search_path = list(filter(None, search_path)) loader = SphinxFileSystemLoader(search_path) super().__init__(loader)
def builder_inited(app_): if app_.builder.name != 'html': return extdir = os.path.dirname(os.path.abspath(__file__)) templatedir = os.path.join(extdir, 'templates') jsdir = os.path.join(extdir, 'static') loader = app_.builder.templates loader.pathchain.insert(0, templatedir) loader.loaders.insert(0, SphinxFileSystemLoader(templatedir)) loader.templatepathlen += 1 app_.builder.config.html_static_path.append(jsdir) if 'version_info' in dir(sphinx) and sphinx.version_info >= (1, 8): app_.add_js_file('tiny_segmenter.js') else: app_.add_javascript('tiny_segmenter.js')
def builder_inited(app): # adding a new loader to the template system puts our searchbox.html # template in front of the others, it overrides whatever searchbox.html # the current theme is using. # it's still up to the theme to actually _use_ a file called searchbox.html # somewhere in its layout. but the base theme and pretty much everything # else that inherits from it uses this filename. app.builder.templates.loaders.insert( 0, SphinxFileSystemLoader(dirname(__file__))) # adds the variable to the context used when rendering the searchbox.html app.config.html_context.update({ 'lunrsearch_highlight': json.dumps(bool(app.config.lunrsearch_highlight)) })
def register_template_directory( kb_app: kb, sphinx_app: Sphinx, sphinx_env: BuildEnvironment, docnames=List[str], ): """ Add this resource's templates dir to template paths """ template_bridge = sphinx_app.builder.templates actions = ResourceAction.get_callbacks(kb_app) for action in actions: f = os.path.dirname(inspect.getfile(action)) template_bridge.loaders.append(SphinxFileSystemLoader(f))
def add_custom_source_link(app): if app.builder.name in supported_builders: template_index = None index = None for template_set in app.builder.templates.loaders: if index is None: index = 0 else: index = +1 if 'sourcelink.html' in template_set.list_templates(): template_index = index break if index is not None: app.builder.templates.loaders.insert( template_index, SphinxFileSystemLoader(os.path.dirname(__file__)))
def builder_inited(app): """Update the Sphinx builder. :param sphinx.application.Sphinx app: Sphinx application object. """ # Add this extension's _templates directory to Sphinx. templates_dir = os.path.join(os.path.dirname(__file__), '_templates') app.builder.templates.pathchain.insert(0, templates_dir) app.builder.templates.loaders.insert(0, SphinxFileSystemLoader(templates_dir)) app.builder.templates.templatepathlen += 1 # Add versions.html to sidebar. if '**' not in app.config.html_sidebars: app.config.html_sidebars['**'] = StandaloneHTMLBuilder.default_sidebars + ['versions.html'] elif 'versions.html' not in app.config.html_sidebars['**']: app.config.html_sidebars['**'].append('versions.html')
def __init__(self, search_path): # type: (unicode) -> None loader = SphinxFileSystemLoader(search_path) super(FileRenderer, self).__init__(loader)
def inspect_config(app): """Inspect the Sphinx configuration and update for slide-linking. If links from HTML to slides are enabled, make sure the sidebar configuration includes the template and add the necessary theme directory as a loader so the sidebar template can be located. If the sidebar configuration already includes ``slidelink.html`` (in any key), the configuration will not be changed. If the configuration is not specified, we'll attempt to emulate what Sphinx does by default. """ # avoid import cycles :/ from hieroglyph import writer # only reconfigure Sphinx if we're generating HTML if app.builder.name not in HTML_BUILDERS: return if app.config.slide_link_html_to_slides: # add the slide theme dir as a Loader app.builder.templates.loaders.append( SphinxFileSystemLoader( os.path.join( os.path.dirname(__file__), 'themes', 'slides', ) ) ) # add the "show slides" sidebar template if not app.config.html_sidebars: # no sidebars explicitly defined, mimic the old style # behavior + slide links app.config.html_sidebars = { '**': [ 'localtoc.html', 'relations.html', 'sourcelink.html', SLIDELINK_TEMPLATE, 'searchbox.html', ], } else: # sidebars defined, add the template if needed included = False for glob, templates in app.config.html_sidebars: if SLIDELINK_TEMPLATE in templates: included = True break if not included: # the slidelink template was not included; append it # to the list of sidebars for all templates app.config.html_sidebars.setdefault('**', []).append( SLIDELINK_TEMPLATE, ) if app.config.slide_link_html_sections_to_slides: # fix up the HTML Translator if sphinx.version_info >= (1, 6, 0): override_translator = type( 'SlideLinkTranslator', (app.builder.get_translator_class(), object), { 'depart_title': writer.depart_title, }, ) app.set_translator(app.builder, override_translator) else: app.builder.translator_class = type( 'SlideLinkTranslator', (app.builder.translator_class, object), { 'depart_title': writer.depart_title, }, )
def __init__(self, search_path): # type: (str) -> None loader = SphinxFileSystemLoader(search_path) super().__init__(loader)
def handle_beforereaddocs(kb_app: kb, sphinx_app: Sphinx, sphinx_env: BuildEnvironment, docnames: List[str]): confdir = os.path.join(sphinx_app.confdir, '_templates') template_bridge = sphinx_app.builder.templates template_bridge.loaders.insert(0, SphinxFileSystemLoader(confdir))
def __init__(self, search_path): loader = SphinxFileSystemLoader(search_path) super(FileRenderer, self).__init__(loader)