Skip to content

Commit

Permalink
Simplify RstContentCreator
Browse files Browse the repository at this point in the history
Import and use ViewList & textwrap directly instead of going through a
layer of indirection. I initially did stuff like this out of a belief
that it made it more testable as it was easy to mock out the stuff being
passed in. However I haven't written any tests and even if I did, I
wouldn't mock 'dedent'.

For #236
  • Loading branch information
Michael Jones committed Jan 15, 2016
1 parent 5b12a8b commit c215203
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 1 addition & 3 deletions breathe/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from .project import ProjectInfoFactory, ProjectError

from docutils.parsers.rst.directives import unchanged_required, unchanged, flag
from docutils.statemachine import ViewList
from sphinx.domains import cpp, c, python
from sphinx.writers.text import TextWriter
from sphinx.builders.text import TextBuilder
Expand All @@ -29,7 +28,6 @@
import os
import fnmatch
import re
import textwrap
import collections
import subprocess

Expand Down Expand Up @@ -867,7 +865,7 @@ def setup(app):
math_nodes.displaymath = sphinx.ext.mathbase.displaymath
node_factory = NodeFactory(docutils.nodes, sphinx.addnodes, math_nodes)

rst_content_creator = RstContentCreator(ViewList, textwrap.dedent)
rst_content_creator = RstContentCreator()
renderer_factory_creator_constructor = DoxygenToRstRendererFactoryCreatorConstructor(
node_factory,
parser_factory,
Expand Down
13 changes: 5 additions & 8 deletions breathe/renderer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@

import textwrap

from .base import Renderer
from . import index as indexrenderer
from . import compound as compoundrenderer

from docutils import nodes
import textwrap
from docutils.statemachine import ViewList


class RstContentCreator(object):

def __init__(self, list_type, dedent):

self.list_type = list_type
self.dedent = dedent

def __call__(self, text):

# Remove the first line which is "embed:rst[:leading-asterisk]"
text = "\n".join(text.split(u"\n")[1:])

# Remove starting whitespace
text = self.dedent(text)
text = textwrap.dedent(text)

# Inspired by autodoc.py in Sphinx
result = self.list_type()
result = ViewList()
for line in text.split("\n"):
result.append(line, "<breathe>")

Expand Down

0 comments on commit c215203

Please sign in to comment.