Skip to content

Commit

Permalink
start updading the section rendering methods
Browse files Browse the repository at this point in the history
  • Loading branch information
itziakos committed Oct 17, 2014
1 parent 312c7db commit 9593657
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
17 changes: 13 additions & 4 deletions refactordoc/sections/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
# Copyright (c) 2011, Enthought, Inc.
# All rights reserved.
# -----------------------------------------------------------------------------
from refactordoc.items.argument_item import ArgumentItem
from refactordoc.items import DefinitionItem
from refactordoc.renderers.argument import Argument


def arguments(doc, header):
def arguments(doc, header, renderer=None, item_class=DefinitionItem):
""" Refactor the argument section to sphinx friendly format.
Arguments
Expand All @@ -20,9 +21,17 @@ def arguments(doc, header):
header : string
This parameter is ignored in this method.
renderer : Renderer
A renderer instance to render the items.
item_class : type
The item parser class to use. Default is :class:`~.DefinitionItem`.
"""
items = doc.extract_items(item_class=ArgumentItem)
items = doc.extract_items(item_class=item_class)
lines = []
renderer = Argument if renderer is None else renderer
for item in items:
lines += item.to_rst()
renderer.item = item
lines += renderer.to_rst()
return lines
10 changes: 6 additions & 4 deletions refactordoc/sections/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
# Copyright (c) 2011-14, Enthought, Inc.
# All rights reserved.
# -----------------------------------------------------------------------------
from refactordoc.items import AttributeItem
from refactordoc.items import DefinitionItem
from refctordoc.renderers import Attribute


def attributes(doc, header):
def attributes(doc, header, renderer=None, item_class=DefinitionItem):
"""Refactor the attributes section to sphinx friendly format.
"""
items = doc.extract_items(AttributeItem)

items = doc.extract_items(item_class=DefinitionItem)
lines = []
for item in items:
lines += item.to_rst()
lines += renderer(item).to_rst()
return lines
19 changes: 14 additions & 5 deletions refactordoc/sections/item_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
# All rights reserved.
# -----------------------------------------------------------------------------
from refactordoc.util import add_indent
from refactordoc.items.list_item import ListItem
from refactordoc.items import DefinitionItem
from refactordoc.renderers import ListItem


def item_list(doc, header):
""" Refactor the a section to sphinx friendly item list.
def item_list(doc, header, renderer=None, item_class=DefinitionItem):
""" Refactor the section to sphinx friendly item list.
Arguments
---------
Expand All @@ -22,10 +23,18 @@ def item_list(doc, header):
header : str
The header name that is used for the fields (i.e. ``:<header>:``).
renderer : Renderer
A renderer instance to render the items.
item_class : type
The item parser class to use. Default is :class:`~.DefinitionItem`.
"""
items = doc.extract_items(item_class=ListItem)
items = doc.extract_items(item_class=item_class)
lines = [':{0}:'.format(header.lower())]
prefix = None if len(items) == 1 else '-'
renderer = ListItem if renderer is None else renderer
for item in items:
lines += add_indent(item.to_rst(prefix))
renderer.item = item
lines += add_indent(renderer.to_rst(prefix))
return lines
4 changes: 3 additions & 1 deletion refactordoc/sections/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# -----------------------------------------------------------------------------
from refactordoc.items import MethodItem
from refactordoc.sections.util import get_column_lengths
from refactordoc.renderers import Method


def methods_table(doc, header):
Expand All @@ -24,8 +25,9 @@ def methods_table(doc, header):
lines += [border]
lines += [heading]
lines += [border]
renderer = Method()
for items in items:
lines += items.to_rst(columns)
lines += renderer.to_rst(columns)
lines += [border]
lines += ['']
lines = [line.rstrip() for line in lines]
Expand Down

0 comments on commit 9593657

Please sign in to comment.