From 2b4410e13a5a4fd920ec640c053dd78eae20de65 Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Tue, 7 Apr 2015 22:01:54 -0700 Subject: [PATCH] Initial implementation of singlefile-slides builder. (#96) --- NEWS.txt | 7 +++++++ src/hieroglyph/__init__.py | 1 + src/hieroglyph/builder.py | 14 ++++++++++++++ src/hieroglyph/tests/test_builder.py | 16 ++++++++++++++++ src/hieroglyph/writer.py | 2 +- 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/NEWS.txt b/NEWS.txt index a8c2da2..5d74540 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,6 +1,13 @@ News ==== +0.8 +--- + +*Release date: UNRELEASED* + +* Add `singlefile-slides` builder + 0.7.1 ----- diff --git a/src/hieroglyph/__init__.py b/src/hieroglyph/__init__.py index bf6a909..1aa5e76 100644 --- a/src/hieroglyph/__init__.py +++ b/src/hieroglyph/__init__.py @@ -19,6 +19,7 @@ def setup(app): # Register Builders app.add_builder(builder.SlideBuilder) app.add_builder(builder.DirectorySlideBuilder) + app.add_builder(builder.SingleFileSlideBuilder) app.add_builder(builder.InlineSlideBuilder) app.add_builder(builder.DirectoryInlineSlideBuilder) diff --git a/src/hieroglyph/builder.py b/src/hieroglyph/builder.py index 254bf17..7f076b5 100644 --- a/src/hieroglyph/builder.py +++ b/src/hieroglyph/builder.py @@ -6,6 +6,7 @@ from docutils import nodes from sphinx.theming import Theme from sphinx.builders.html import ( + SingleFileHTMLBuilder, StandaloneHTMLBuilder, DirectoryHTMLBuilder, ) @@ -197,6 +198,19 @@ class SlideBuilder(AbstractSlideBuilder, StandaloneHTMLBuilder): name = 'slides' +class SingleFileSlideBuilder(AbstractSlideBuilder, SingleFileHTMLBuilder): + """This is the single file Slide HTML builder. + + Its output is a directory with a single HTML file, along with the + needed style sheets and JavaScript. + + Its name is ``singlefile-slides``. + + """ + + name = 'singlefile-slides' + + class AbstractInlineSlideBuilder(object): name = 'inlineslides' diff --git a/src/hieroglyph/tests/test_builder.py b/src/hieroglyph/tests/test_builder.py index 7004f70..5275821 100644 --- a/src/hieroglyph/tests/test_builder.py +++ b/src/hieroglyph/tests/test_builder.py @@ -1,3 +1,4 @@ +import glob from unittest import TestCase from sphinx_testing import ( @@ -106,3 +107,18 @@ def test_docstitle_fallback_to_html_title(self, app, status, warning): builder.globalcontext['docstitle'], builder.config.html_title, ) + + +class SingleFileBuilderTests(TestCase): + + @with_app( + buildername='singlefile-slides', + ) + def test_builds_single_file(self, app, *args): + + app.build() + + self.assertEqual( + len(glob.glob(app.builddir/'singlefile-slides'/'*.html')), + 1, + ) diff --git a/src/hieroglyph/writer.py b/src/hieroglyph/writer.py index 044c177..f5f7ac9 100644 --- a/src/hieroglyph/writer.py +++ b/src/hieroglyph/writer.py @@ -206,7 +206,7 @@ def visit_slide(self, node): def depart_slide(self, node): - if not getattr(node, 'closed', False): + if self.current_slide and not getattr(node, 'closed', False): # mark the slide closed node.closed = True