Skip to content

Commit

Permalink
Fix toctree handling with single-file builder (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyergler committed Apr 19, 2015
1 parent e0fdfde commit b6bda50
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/hieroglyph/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ class SingleFileSlideBuilder(AbstractSlideBuilder, SingleFileHTMLBuilder):

name = 'singlefile-slides'

def init_translator_class(self):
self.translator_class = writer.SingleFileSlideTranslator


class AbstractInlineSlideBuilder(object):

Expand Down
5 changes: 2 additions & 3 deletions src/hieroglyph/tests/singlefile/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
some text


Slide 2
=======
.. slide:: Slide 2

TESTING_SENTINEL
TESTING_SENTINEL

.. toctree::

Expand Down
18 changes: 18 additions & 0 deletions src/hieroglyph/tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,21 @@ def test_adjusts_section_levels_to_account_for_toctree(self, app, *args):
contents = tree.find_all('article')

self.assertEqual(len(contents), 4)

@with_app(
buildername='singlefile-slides',
srcdir=util.test_root.parent/'singlefile',
)
def test_slide_directive_closes_correctly_at_end_of_source_file(self, app, *args):
app.build()

with open(app.builddir/'singlefile-slides'/'index.html') as html_file:
tree = BeautifulSoup(html_file.read())

# test to see that all the slides are siblings
slides = [
s for s in tree.section.children
if s.name == 'article'
]

self.assertEqual(len(slides), 4)
11 changes: 11 additions & 0 deletions src/hieroglyph/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,14 @@ def visit_start_of_file(self, node):
self.section_level -= 1

BaseSlideTranslator.visit_start_of_file(self, node)


class SingleFileSlideTranslator(SlideTranslator):

def visit_compound(self, node):
if not 'toctree-wrapper' in node['classes']:
SlideTranslator.visit_compound(self, node)

def depart_compound(self, node):
if not 'toctree-wrapper' in node['classes']:
SlideTranslator.depart_compound(self, node)

0 comments on commit b6bda50

Please sign in to comment.