mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Store stylesheets as an instance variable of HTML builder
So far, CSS files are stored as a class variable of HTML builder. Not to have status globally, this changes it to an instance varable.
This commit is contained in:
parent
c5d6942b88
commit
99fbd44e20
@ -1036,7 +1036,6 @@ class Sphinx(object):
|
||||
Allows keyword arguments as attributes of link tag.
|
||||
"""
|
||||
logger.debug('[app] adding stylesheet: %r', filename)
|
||||
from sphinx.builders.html import StandaloneHTMLBuilder, Stylesheet
|
||||
if '://' not in filename:
|
||||
filename = posixpath.join('_static', filename)
|
||||
if kwargs.pop('alternate', None):
|
||||
@ -1044,8 +1043,7 @@ class Sphinx(object):
|
||||
'Please use rel="alternate stylesheet" option instead.',
|
||||
RemovedInSphinx30Warning)
|
||||
kwargs['rel'] = 'alternate stylesheet'
|
||||
css = Stylesheet(filename, **kwargs)
|
||||
StandaloneHTMLBuilder.css_files.append(css)
|
||||
self.registry.add_css_files(filename, **kwargs)
|
||||
|
||||
def add_latex_package(self, packagename, options=None):
|
||||
# type: (unicode, unicode) -> None
|
||||
|
@ -248,8 +248,6 @@ class StandaloneHTMLBuilder(Builder):
|
||||
# This is a class attribute because it is mutated by Sphinx.add_javascript.
|
||||
script_files = ['_static/jquery.js', '_static/underscore.js',
|
||||
'_static/doctools.js'] # type: List[unicode]
|
||||
# Ditto for this one (Sphinx.add_stylesheet).
|
||||
css_files = CSSContainer() # type: List[Dict[unicode, unicode]]
|
||||
|
||||
imgpath = None # type: unicode
|
||||
domain_indices = [] # type: List[Tuple[unicode, Type[Index], List[Tuple[unicode, List[List[Union[unicode, int]]]]], bool]] # NOQA
|
||||
@ -257,6 +255,13 @@ class StandaloneHTMLBuilder(Builder):
|
||||
# cached publisher object for snippets
|
||||
_publisher = None
|
||||
|
||||
def __init__(self, app):
|
||||
# type: (Sphinx) -> None
|
||||
super(StandaloneHTMLBuilder, self).__init__(app)
|
||||
|
||||
# CSS files
|
||||
self.css_files = CSSContainer() # type: List[Dict[unicode, unicode]]
|
||||
|
||||
def init(self):
|
||||
# type: () -> None
|
||||
self.build_info = self.create_build_info()
|
||||
@ -269,6 +274,7 @@ class StandaloneHTMLBuilder(Builder):
|
||||
|
||||
self.init_templates()
|
||||
self.init_highlighter()
|
||||
self.init_css_files()
|
||||
if self.config.html_file_suffix is not None:
|
||||
self.out_suffix = self.config.html_file_suffix
|
||||
|
||||
@ -331,6 +337,11 @@ class StandaloneHTMLBuilder(Builder):
|
||||
self.highlighter = PygmentsBridge('html', style,
|
||||
self.config.trim_doctest_flags)
|
||||
|
||||
def init_css_files(self):
|
||||
# type: () -> None
|
||||
for filename, attrs in self.app.registry.css_files:
|
||||
self.css_files.append(Stylesheet(filename, **attrs)) # type: ignore
|
||||
|
||||
@property
|
||||
def default_translator_class(self):
|
||||
# type: () -> nodes.NodeVisitor
|
||||
@ -1332,6 +1343,7 @@ class SerializingHTMLBuilder(StandaloneHTMLBuilder):
|
||||
self.templates = None # no template bridge necessary
|
||||
self.init_templates()
|
||||
self.init_highlighter()
|
||||
self.init_css_files()
|
||||
self.use_index = self.get_builder_config('use_index', 'html')
|
||||
|
||||
def get_target_uri(self, docname, typ=None):
|
||||
|
@ -65,6 +65,9 @@ class SphinxComponentRegistry(object):
|
||||
#: autodoc documenters; a dict of documenter name -> documenter class
|
||||
self.documenters = {} # type: Dict[unicode, Type[Documenter]]
|
||||
|
||||
#: css_files; a list of tuple of filename and attributes
|
||||
self.css_files = [] # type: List[Tuple[unicode, Dict[unicode, unicode]]]
|
||||
|
||||
#: domains; a dict of domain name -> domain class
|
||||
self.domains = {} # type: Dict[unicode, Type[Domain]]
|
||||
|
||||
@ -412,6 +415,9 @@ class SphinxComponentRegistry(object):
|
||||
# type: (Type, Callable[[Any, unicode, Any], Any]) -> None
|
||||
self.autodoc_attrgettrs[typ] = attrgetter
|
||||
|
||||
def add_css_files(self, filename, **attributes):
|
||||
self.css_files.append((filename, attributes))
|
||||
|
||||
def add_latex_package(self, name, options):
|
||||
# type: (unicode, unicode) -> None
|
||||
logger.debug('[app] adding latex package: %r', name)
|
||||
|
Loading…
Reference in New Issue
Block a user