Skip to content

Commit

Permalink
Change "override" naming to be "readthedocs" specific
Browse files Browse the repository at this point in the history
Also adds Sphinx 1.6b3 testing
  • Loading branch information
agjohnson committed May 9, 2017
1 parent af02251 commit a2355c4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
6 changes: 3 additions & 3 deletions readthedocs_ext/comments/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def finalize_comment_media(app):

class CommentsBuilderMixin(BuilderMixin):

static_override_files = [
static_readthedocs_files = [
'sphinxweb.css',
'jquery.pageslide.css',
'jquery.pageslide.js',
]

def get_static_override_context(self):
ctx = super(CommentsBuilderMixin, self).get_static_override_context()
def get_static_readthedocs_context(self):
ctx = super(CommentsBuilderMixin, self).get_static_readthedocs_context()
ctx['websupport2_base_url'] = self.config.websupport2_base_url
ctx['websupport2_static_url'] = self.config.websupport2_static_url
return ctx
Expand Down
16 changes: 8 additions & 8 deletions readthedocs_ext/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ class BuilderMixin(object): # pylint: disable=old-style-class
new path.
"""

static_override_files = []
static_readthedocs_files = []

def get_static_override_context(self):
def get_static_readthedocs_context(self):
return self.globalcontext.copy()

def copy_static_override_files(self):
self.app.info(bold('copying static override files... '), nonl=True)
for filename in self.static_override_files:
def copy_static_readthedocs_files(self):
self.app.info(bold('copying readthedocs static files... '), nonl=True)
for filename in self.static_readthedocs_files:
path_dest = os.path.join(self.outdir, '_static')
path_src = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'_static',
filename
)
ctx = self.get_static_override_context()
ctx = self.get_static_readthedocs_context()
if sphinx.version_info < (1, 5):
copy_static_entry(
path_src,
Expand All @@ -51,10 +51,10 @@ def copy_static_override_files(self):
self.app.info('done')

def copy_static_files(self):
"""Copy override files after initial static pass
"""Copy Read the Docs specific files after initial static pass
This overrides the base builder ``copy_static_files`` method to inject
custom static files.
"""
super(BuilderMixin, self).copy_static_files()
self.copy_static_override_files()
self.copy_static_readthedocs_files()
12 changes: 6 additions & 6 deletions readthedocs_ext/readthedocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def rtd_render(self, template, render_context):

class HtmlBuilderMixin(BuilderMixin):

static_override_files = [
static_readthedocs_files = [
'readthedocs-dynamic-include.js_t',
'readthedocs-data.js_t',
# We patch searchtools and copy it with a special handler
Expand All @@ -132,14 +132,14 @@ class HtmlBuilderMixin(BuilderMixin):
(re.MULTILINE | re.VERBOSE)
)

def get_static_override_context(self):
ctx = super(HtmlBuilderMixin, self).get_static_override_context()
def get_static_readthedocs_context(self):
ctx = super(HtmlBuilderMixin, self).get_static_readthedocs_context()
if self.indexer is not None:
ctx.update(self.indexer.context_for_searchtool())
return ctx

def copy_static_override_files(self):
super(HtmlBuilderMixin, self).copy_static_override_files()
def copy_static_readthedocs_files(self):
super(HtmlBuilderMixin, self).copy_static_readthedocs_files()
self._copy_searchtools()

def _copy_searchtools(self, renderer=None):
Expand Down Expand Up @@ -171,7 +171,7 @@ def _copy_searchtools(self, renderer=None):
data = self.REPLACEMENT_PATTERN.sub(self.REPLACEMENT_TEXT, data)
h_dest.write(renderer.render_string(
data,
self.get_static_override_context()
self.get_static_readthedocs_context()
))
else:
self.app.warn('Missing searchtools.js_t')
Expand Down
12 changes: 6 additions & 6 deletions tests/test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@

class MixinTests(unittest.TestCase):

def test_html_builder_context_contains_overrides(self):
def test_html_builder_context_contains_additions(self):
with sphinx_build('pyexample', 'readthedocs') as app:
self.assertIn(
'search_scorer_tool',
app.builder.get_static_override_context(),
app.builder.get_static_readthedocs_context(),
)

def test_htmldir_builder_context_contains_overrides(self):
def test_htmldir_builder_context_contains_additions(self):
with sphinx_build('pyexample', 'readthedocsdirhtml') as app:
self.assertIn(
'search_scorer_tool',
app.builder.get_static_override_context(),
app.builder.get_static_readthedocs_context(),
)

def test_comments_builder_context_contains_overrides(self):
def test_comments_builder_context_contains_additions(self):
with sphinx_build('pyexample', 'readthedocs-comments') as app:
self.assertIn(
'websupport2_base_url',
app.builder.get_static_override_context(),
app.builder.get_static_readthedocs_context(),
)
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py{27,35,36}-sphinx{13,14,15}
py{27,35,36}-sphinx{13,14,15,16}
lint

[testenv]
Expand All @@ -13,6 +13,7 @@ deps =
sphinx13: Sphinx<1.4
sphinx14: Sphinx<1.5
sphinx15: Sphinx<1.6
sphinx16: Sphinx<1.7
commands =
py.test {posargs}

Expand Down

0 comments on commit a2355c4

Please sign in to comment.