Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #8 from zopefoundation/no-default-css
Browse files Browse the repository at this point in the history
Stop forcing 'html_style = default.css'
  • Loading branch information
jamadden committed Jun 20, 2017
2 parents a834403 + 9a7469c commit cfd8f20
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
extensions, overriding the defaults set by this recipe, and
configuring a sphinx theme.

- Stop forcing a value of ``default.css`` for ``html_style`` even when
the ``default.css`` setting is configured to an empty value. This
makes it possible to use ``html_theme`` to set a sphinx theme, and
it properly lets the default Sphinx theme be used (by setting both
``default.css`` and ``layout.html`` to empty values).


1.0.0 (2013-02-23)
==================
Expand Down
21 changes: 15 additions & 6 deletions src/z3c/recipe/sphinxdoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
release = '%(release)s'
today_fmt = '%%B %%d, %%Y'
pygments_style = 'sphinx'
html_style = 'default.css'
%(html_style)s
html_static_path = ['%(staticDir)s']
html_last_updated_fmt = '%%b %%d, %%Y'
extensions = %(extensions)r
Expand Down Expand Up @@ -69,17 +69,21 @@ def _copy_static_file(self, installed, partDir, dirName, fileName):
os.mkdir(destDir)
installed.append(destDir)

usingFile = False

if fileName not in self.options:
recipeDir = dirname(__file__)
shutil.copy(join(recipeDir, fileName),
join(destDir, fileName))
installed.append(join(destDir, fileName))
usingFile = True
elif self.options[fileName]:
with self.openfile(self.options[fileName]) as f:
with open(join(destDir, fileName), 'w') as w:
w.write(f.read())
installed.append(join(destDir, fileName))
return destDir
usingFile = True
return destDir, usingFile


def install(self):
Expand Down Expand Up @@ -109,12 +113,14 @@ def install(self):
installed.append(partDir)

# create static directory
staticDir = self._copy_static_file(installed, partDir,
'.static', 'default.css')
staticDir, usingDefaultCss = self._copy_static_file(
installed, partDir,
'.static', 'default.css')

# create templates directory
templatesDir = self._copy_static_file(installed, partDir,
'.templates', 'layout.html')
templatesDir, _ = self._copy_static_file(
installed, partDir,
'.templates', 'layout.html')

metadata = dict(message_from_string('\n'.join(
doc._get_metadata('PKG-INFO'))).items())
Expand All @@ -129,6 +135,9 @@ def install(self):
release=metadata.get('Version', doc.version),
staticDir=staticDir,
templatesDir=templatesDir,
html_style=("html_style = 'default.css'"
if usingDefaultCss
else ''),
indexDoc=self.options.get('index-doc','index'),
extensions=self.options.get('extensions','').split(),
extra_conf=self.options.get('extra-conf', ''),
Expand Down
38 changes: 34 additions & 4 deletions src/z3c/recipe/sphinxdoc/tests/test_sphinxdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def templates_path(self):
def static_path(self):
return os.path.join(self.part_path, '.static')

@property
def default_css_path(self):
return os.path.join(self.static_path, 'default.css')

@property
def layout_html_path(self):
return os.path.join(self.templates_path, 'layout.html')

def _check_conf_py_can_be_evald(self):
args = [sys.executable,
'-c',
Expand Down Expand Up @@ -96,15 +104,16 @@ def test_basic_install(self):

self.assertIn(os.path.abspath(self.templates_path), conf)
self.assertIn(os.path.abspath(self.static_path), conf)
# We didn't override default.css so it was inserted by default
self.assertIn("html_style = 'default.css", conf)

script_path = os.path.join('bin', docs.name)
with open(script_path, 'r') as f:
script = f.read()
self.assertIn("sys.exit(z3c.recipe.sphinxdoc.main({'z3c.recipe.sphinxdoc':",
script)

# Go ahead and generate it, or at least try to, it shouldn't fail, even though there's no
# index.rst
# Go ahead and generate it
subprocess.check_call('bin/docs')

# likewise, we can directly try to do it and it doesn't raise an exception
Expand All @@ -121,16 +130,19 @@ def test_override_css(self):
docs, _ = self._makeOne(options={'default.css': EMPTY_FILE})
docs.install()

css_path = os.path.join(self.static_path, 'default.css')
css_path = self.default_css_path
with open(css_path, 'r') as f:
css = f.read()
self.assertEqual(css, '')

conf = self._read_conf_file()
self.assertIn("html_style = 'default.css'", conf)

def test_override_layout(self):
docs, _ = self._makeOne(options={'layout.html': EMPTY_FILE})
docs.install()

html_path = os.path.join(self.templates_path, 'layout.html')
html_path = self.layout_html_path
with open(html_path, 'r') as f:
html = f.read()
self.assertEqual(html, '')
Expand All @@ -154,3 +166,21 @@ def test_extra_conf(self):
self._check_conf_py_can_be_evald()
conf = self._read_conf_file()
self.assertIn('intersphinx_mapping', conf)


def test_no_default_css_not_included(self):
docs, _ = self._makeOne(options={'layout.html': '',
'default.css': '',
'extra-conf': "html_theme='classic'"})
docs.install()
self._check_conf_py_can_be_evald()
conf = self._read_conf_file()

# It was completely ommitted
self.assertNotIn('html_style', conf)

# Nothing was copied
self.assertFalse(os.path.exists(self.default_css_path), self.default_css_path)
self.assertFalse(os.path.exists(self.layout_html_path), self.layout_html_path)

subprocess.check_call('bin/docs')

0 comments on commit cfd8f20

Please sign in to comment.