Skip to content

Commit

Permalink
Merge 520923c into 12db40e
Browse files Browse the repository at this point in the history
  • Loading branch information
nhartung committed Mar 17, 2020
2 parents 12db40e + 520923c commit 8c4c938
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 453 deletions.
2 changes: 2 additions & 0 deletions doorstop/core/files/assets/doorstop/sidebar.css
Expand Up @@ -10,6 +10,8 @@
padding-left: 20px;
margin-top: 20px;
margin-bottom: 20px;
width: 18em;
overflow: hidden;
}

/* all links */
Expand Down
118 changes: 0 additions & 118 deletions doorstop/core/files/doorstop.css

This file was deleted.

55 changes: 33 additions & 22 deletions doorstop/core/publisher.py
Expand Up @@ -30,7 +30,6 @@
alt='UML Diagram',
),
)
CSS = os.path.join(os.path.dirname(__file__), 'files', 'doorstop.css')
HTMLTEMPLATE = 'sidebar'
INDEX = 'index.html'

Expand Down Expand Up @@ -154,9 +153,8 @@ def _lines_index(filenames, charset='UTF-8', tree=None):
'<meta http-equiv="content-type" content="text/html; '
'charset={charset}">'.format(charset=charset)
)
yield '<style type="text/css">'
yield from _lines_css()
yield '</style>'
yield '<link rel="stylesheet" href="assets/doorstop/bootstrap.min.css" />'
yield '<link rel="stylesheet" href="assets/doorstop/general.css" />'
yield '</head>'
yield '<body>'
# Tree structure
Expand Down Expand Up @@ -189,14 +187,14 @@ def _lines_index(filenames, charset='UTF-8', tree=None):
# table
yield '<h3>Item Traceability:</h3>'
yield '<p>'
yield '<table>'
yield '<table class="table table-striped table-condensed">'
# header
for document in documents: # pylint: disable=not-an-iterable
yield '<col width="100">'
yield '<col width="140">'
yield '<tr>'
for document in documents: # pylint: disable=not-an-iterable
link = '<a href="{p}.html">{p}</a>'.format(p=document.prefix)
yield (' <th height="25" align="center"> {link} </th>'.format(link=link))
yield (' <th height="25" align="left"> {link} </th>'.format(link=link))
yield '</tr>'
# data
for index, row in enumerate(tree.get_traceability()):
Expand All @@ -208,8 +206,8 @@ def _lines_index(filenames, charset='UTF-8', tree=None):
if item is None:
link = ''
else:
link = _format_html_item_link(item)
yield ' <td height="25" align="center"> {} </td>'.format(link)
link = _format_html_item_link_index_table(item)
yield ' <td height="25" align="left"> {} </td>'.format(link)
yield '</tr>'
yield '</table>'
yield '</p>'
Expand All @@ -218,14 +216,6 @@ def _lines_index(filenames, charset='UTF-8', tree=None):
yield '</html>'


def _lines_css():
"""Yield lines of CSS to embedded in HTML."""
yield ''
for line in common.read_lines(CSS):
yield line.rstrip()
yield ''


def publish_lines(obj, ext='.txt', **kwargs):
"""Yield lines for a report in the specified format.
Expand Down Expand Up @@ -386,7 +376,7 @@ def _lines_markdown(obj, **kwargs):
yield "" # break before links
items2 = item.parent_items
if settings.PUBLISH_CHILD_LINKS:
label = "Parent links:"
label = "🡩 Parents:"
else:
label = "Links:"
links = _format_md_links(items2, linkify)
Expand All @@ -398,12 +388,13 @@ def _lines_markdown(obj, **kwargs):
items2 = item.find_child_items()
if items2:
yield "" # break before links
label = "Child links:"
label = "🡫 Children:"
links = _format_md_links(items2, linkify)
label_links = _format_md_label_links(label, links, linkify)
yield label_links

yield "" # break between items
yield "***" # horizontal rule between items


def _format_level(level):
Expand Down Expand Up @@ -530,16 +521,32 @@ def _format_html_item_link(item, linkify=True):
return str(item.uid) # if not `Item`, assume this is an `UnknownItem`


def _format_html_item_link_index_table(item, linkify=True):
"""Format an item link in HTML."""
if linkify and is_item(item):
if item.header:
link = '<a href="{p}.html#{u}">{u}</a><br/>{h}'.format(
u=item.uid, h=item.header, p=item.document.prefix
)
else:
link = '<a href="{p}.html#{u}">{u}</a>'.format(
u=item.uid, p=item.document.prefix
)
return link
else:
return str(item.uid) # if not `Item`, assume this is an `UnknownItem`


def _format_md_label_links(label, links, linkify):
"""Join a string of label and links with formatting."""
if linkify:
return "*{lb}* {ls}".format(lb=label, ls=links)
return "{lb} {ls}".format(lb=label, ls=links)
else:
return "*{lb} {ls}*".format(lb=label, ls=links)


def _table_of_contents_md(obj, linkify=None):
toc = '### Table of Contents\n\n'
toc = '**Contents**\n\n'

for item in iter_items(obj):
if item.depth == 1:
Expand All @@ -554,7 +561,10 @@ def _table_of_contents_md(obj, linkify=None):
elif item.header:
heading = "{h}".format(h=item.header)
else:
heading = item.uid
if settings.ENABLE_HEADERS and item.header:
heading = item.header
else:
heading = item.uid

if settings.PUBLISH_HEADING_LEVELS:
level = _format_level(item.level)
Expand Down Expand Up @@ -595,6 +605,7 @@ def _lines_html(

if toc:
toc_md = _table_of_contents_md(obj, True)
toc_md = '[🡨 Index](index.html) \n\n ' + toc_md # Add a link to index
toc_html = markdown.markdown(toc_md, extensions=extensions)
else:
toc_html = ''
Expand Down

0 comments on commit 8c4c938

Please sign in to comment.