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.
|
Allows keyword arguments as attributes of link tag.
|
||||||
"""
|
"""
|
||||||
logger.debug('[app] adding stylesheet: %r', filename)
|
logger.debug('[app] adding stylesheet: %r', filename)
|
||||||
from sphinx.builders.html import StandaloneHTMLBuilder, Stylesheet
|
|
||||||
if '://' not in filename:
|
if '://' not in filename:
|
||||||
filename = posixpath.join('_static', filename)
|
filename = posixpath.join('_static', filename)
|
||||||
if kwargs.pop('alternate', None):
|
if kwargs.pop('alternate', None):
|
||||||
@ -1044,8 +1043,7 @@ class Sphinx(object):
|
|||||||
'Please use rel="alternate stylesheet" option instead.',
|
'Please use rel="alternate stylesheet" option instead.',
|
||||||
RemovedInSphinx30Warning)
|
RemovedInSphinx30Warning)
|
||||||
kwargs['rel'] = 'alternate stylesheet'
|
kwargs['rel'] = 'alternate stylesheet'
|
||||||
css = Stylesheet(filename, **kwargs)
|
self.registry.add_css_files(filename, **kwargs)
|
||||||
StandaloneHTMLBuilder.css_files.append(css)
|
|
||||||
|
|
||||||
def add_latex_package(self, packagename, options=None):
|
def add_latex_package(self, packagename, options=None):
|
||||||
# type: (unicode, unicode) -> 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.
|
# This is a class attribute because it is mutated by Sphinx.add_javascript.
|
||||||
script_files = ['_static/jquery.js', '_static/underscore.js',
|
script_files = ['_static/jquery.js', '_static/underscore.js',
|
||||||
'_static/doctools.js'] # type: List[unicode]
|
'_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
|
imgpath = None # type: unicode
|
||||||
domain_indices = [] # type: List[Tuple[unicode, Type[Index], List[Tuple[unicode, List[List[Union[unicode, int]]]]], bool]] # NOQA
|
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
|
# cached publisher object for snippets
|
||||||
_publisher = None
|
_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):
|
def init(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.build_info = self.create_build_info()
|
self.build_info = self.create_build_info()
|
||||||
@ -269,6 +274,7 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
|
|
||||||
self.init_templates()
|
self.init_templates()
|
||||||
self.init_highlighter()
|
self.init_highlighter()
|
||||||
|
self.init_css_files()
|
||||||
if self.config.html_file_suffix is not None:
|
if self.config.html_file_suffix is not None:
|
||||||
self.out_suffix = self.config.html_file_suffix
|
self.out_suffix = self.config.html_file_suffix
|
||||||
|
|
||||||
@ -331,6 +337,11 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
self.highlighter = PygmentsBridge('html', style,
|
self.highlighter = PygmentsBridge('html', style,
|
||||||
self.config.trim_doctest_flags)
|
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
|
@property
|
||||||
def default_translator_class(self):
|
def default_translator_class(self):
|
||||||
# type: () -> nodes.NodeVisitor
|
# type: () -> nodes.NodeVisitor
|
||||||
@ -1332,6 +1343,7 @@ class SerializingHTMLBuilder(StandaloneHTMLBuilder):
|
|||||||
self.templates = None # no template bridge necessary
|
self.templates = None # no template bridge necessary
|
||||||
self.init_templates()
|
self.init_templates()
|
||||||
self.init_highlighter()
|
self.init_highlighter()
|
||||||
|
self.init_css_files()
|
||||||
self.use_index = self.get_builder_config('use_index', 'html')
|
self.use_index = self.get_builder_config('use_index', 'html')
|
||||||
|
|
||||||
def get_target_uri(self, docname, typ=None):
|
def get_target_uri(self, docname, typ=None):
|
||||||
|
@ -65,6 +65,9 @@ class SphinxComponentRegistry(object):
|
|||||||
#: autodoc documenters; a dict of documenter name -> documenter class
|
#: autodoc documenters; a dict of documenter name -> documenter class
|
||||||
self.documenters = {} # type: Dict[unicode, Type[Documenter]]
|
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
|
#: domains; a dict of domain name -> domain class
|
||||||
self.domains = {} # type: Dict[unicode, Type[Domain]]
|
self.domains = {} # type: Dict[unicode, Type[Domain]]
|
||||||
|
|
||||||
@ -412,6 +415,9 @@ class SphinxComponentRegistry(object):
|
|||||||
# type: (Type, Callable[[Any, unicode, Any], Any]) -> None
|
# type: (Type, Callable[[Any, unicode, Any], Any]) -> None
|
||||||
self.autodoc_attrgettrs[typ] = attrgetter
|
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):
|
def add_latex_package(self, name, options):
|
||||||
# type: (unicode, unicode) -> None
|
# type: (unicode, unicode) -> None
|
||||||
logger.debug('[app] adding latex package: %r', name)
|
logger.debug('[app] adding latex package: %r', name)
|
||||||
|
Loading…
Reference in New Issue
Block a user