Skip to content

Commit

Permalink
SupportingMatter improvements
Browse files Browse the repository at this point in the history
- identify a supporting-matter Container by name(s) instead of ID
  (the ID contains the document name in a Sphinx project; in the test
   case one supporting-matter container was moved to test this)
- do not register the ID of a SetSupportingMatter's ID
  (so the ID is free for use elsewhere)
- inherit from GroupedFlowables to make it more generally usable
  • Loading branch information
brechtm committed Nov 3, 2020
1 parent 3503289 commit bbebef0
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 20 deletions.
8 changes: 5 additions & 3 deletions src/rinoh/flowable.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,14 @@ def build_document(self, flowable_target):


class SetSupportingMatter(DummyFlowable):
def __init__(self, flowables, parent=None):
super().__init__(id=id, parent=parent)
def __init__(self, names, flowables, parent=None):
super().__init__(parent=parent)
self.names = names
self.flowables = flowables

def build_document(self, flowable_target):
flowable_target.document.supporting_matter[self.id] = self.flowables
for name in self.names:
flowable_target.document.supporting_matter[name] = self.flowables


# grouping flowables
Expand Down
10 changes: 8 additions & 2 deletions src/rinoh/frontend/rst/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,16 +748,22 @@ def build_flowable(self):


class Container(DocutilsGroupingNode):
@property
def set_id(self):
return 'supporting-matter' not in self['classes']

def build_flowable(self, style=None, **kwargs):
classes = self.get('classes')
if 'literal-block-wrapper' in classes:
return rt.CodeBlockWithCaption(self.children_flowables(),
style=style or self.style, **kwargs)
if 'supporting-matter' in classes:
if not self._ids:
names = self['names']
if not names:
raise MissingName('supporting-matter container is missing a'
' :name: to reference it by')
return rt.SetSupportingMatter(self.children_flowables(), **kwargs)
return rt.SetSupportingMatter(names, self.children_flowables(),
**kwargs)
return super().build_flowable(style, **kwargs)


Expand Down
10 changes: 6 additions & 4 deletions src/rinoh/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,12 @@ def render(self, container, descender, state, **kwargs):
return width, 0, 0


class SupportingMatter(SectionBase):
def __init__(self, id, align=None, width=None, style=None, parent=None):
super().__init__(id=id, align=align, width=width, style=style,
class SupportingMatter(GroupedFlowables):
def __init__(self, name, align=None, width=None, id=None, style=None,
parent=None):
super().__init__(align=align, width=width, id=id, style=style,
parent=parent)
self.name = name

def flowables(self, container):
return container.document.supporting_matter[self.id]
return container.document.supporting_matter[self.name]
8 changes: 0 additions & 8 deletions tests_regression/roots/test-supportingmatter/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ Supporting Matter
For mommy


.. container:: supporting-matter
:name: epigraph

| Gloomy eventide
| before evil symantics writes
| into the despair

.. toctree::
:maxdepth: 2
:caption: Contents:
Expand Down
8 changes: 8 additions & 0 deletions tests_regression/roots/test-supportingmatter/intro.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
Introduction
============

.. container:: supporting-matter
:name: epigraph

| Gloomy eventide
| before evil symantics writes
| into the despair

This is the introduction.
4 changes: 4 additions & 0 deletions tests_regression/roots/test-supportingmatter/stylesheet.rts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ base = sphinx_base14
[title page date : Paragraph('title page date')]
hide = true

[dedication section : Section(id='dedication')]
show_in_toc = false
page_break = right

[table of contents section]
page_break = right

Expand Down
8 changes: 5 additions & 3 deletions tests_regression/roots/test-supportingmatter/template.rtt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ template = book
page_number_format = lowercase roman
end_at_page = left
flowables = [
SupportingMatter('dedication'),
Section([Heading(SingleStyledText('Dedication'),
style='unnumbered'),
SupportingMatter('dedication')],
id='dedication'),
TableOfContentsSection(),
ListOfFiguresSection(),
ListOfTablesSection(),
SupportingMatter('epigraph'),
Section([SupportingMatter('epigraph')]),
]

0 comments on commit bbebef0

Please sign in to comment.