170 lines
6.5 KiB
Python

import codecs
import os
import config.env as env
css_md_content = ""
with codecs.open(env.css_md_path, encoding=env.encoding, mode="r") as css:
css_md_content = css.read()
css_index_content = ""
with codecs.open(env.css_index_path, encoding=env.encoding, mode="r") as css:
css_index_content = css.read()
html_header = (
"""
<html>
<head>
<style type='text/css'>
<!--
"""
+ css_md_content
+ """
//-->
</style>
</head>
<body>
<div class='markdown-body'>
"""
)
html_footer = """
</div>
</body>
</html>
"""
style_basic = """
@media (prefers-color-scheme: dark) {
/* this is the github markdown dark background */
html { background-color: #0d1117; }
}
body {
width: 92%; max-width: 40em; margin: auto;
font-size: 1.2rem; line-height: 1.5; padding-bottom: 3em;}
code { font-family: "DejaVu Sans Mono", Consolas, monospace; }
pre { overflow: auto; }
math, .LaTeX { font-size: 1.1em; }
div.figure .caption { padding: 0em 1em 1em; font-size: 0.8em; }
ul li { list-style-type: disc; }
li p { margin: 0.5em 0; }
#TOC { border: 1px solid lightgray; padding: 0.5em; margin-bottom: 1em;}
#TOC li { list-style: circle; }
#TOC > ul { margin-bottom: 0px }
@media (min-width: 102em) {
body { position: relative; }
#TOC { display: block; position: absolute; left: -50%; top: 5em; max-width: 46%; width: 45%; }
}
"""
style_document_add = """
@media (max-width: 101em) {
#TOC { display: none; }
}
.topmenu { font-size: 1em; color: lightgrey; }
.topmenu a { color: lightgrey; }
"""
style_index = """
ul.file-listing a { text-decoration: none; }
ul.file-listing ul.file-listing { padding-left: 1.5em; }
ul li.dir-entry {
list-style-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAApElEQVQ4je3UsQqBYRTG8Z9SMpjsrsAdYMI1WNyDhdnKriiD1U3YXML3SWE3uAgDX+lF8iqlPPX01qnn/55OncMvqYMUSeA1KjHAFKUH9S7GMcDkSb2Jk/vOQ2/QhzKq2F/fd52/ftzCBKZYYRnhA2ohcIb6m+PJdJv9A//AT4GND4BZtp0BBxgiFwG8zY7QgyIWLsv96gCE3uKIHeYoRDT1ZZ0BsR1JIXdX8A8AAAAASUVORK5CYII=');
}
ul li.file-entry{
list-style-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAA00lEQVQ4jcXUQUqCURSG4Qc0bKaUiKsIhEbazMBhOHILES3EUYIGtpBwlDODhhFCTqQdtIYGf5H+eOVeFP4P3ul7L4fzHbZziQme9jDEqYhU8IkervbwjecYaRPziIeXuIuRNvESKRQjjRV+4f6XN8xQPkQ4wO0Ga9QPEeazKER4gi6uA3T9zy1KeCZb8McAY1RThCkpRtjAh2yJd/EuG0txPzy68BxT4RM2RS1FWEZH+IS1UUoRpuQ1JPw7sDfCDcnTx0rWrJ1pYSTckDwPuNgU/ADJ7ku1B60bXwAAAABJRU5ErkJggg==');
}
@media (prefers-color-scheme: dark) {
ul li.dir-entry {
list-style-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAmklEQVR42mMYOuD////hQHwViK+g4SNALEeygVDDeLGIxwBxJzkGXsEh7gzEb0DyBPA1IC4BaRAGYh0gvgOiycAsUItdgHgKiDEdiPcC8Qoy8F0gtkY3cAYQ25ARj3C9VDJw1MBRA20pMNAWynaFGVgKxPVAzEi6gQi9QNwBxPkgQU4gng/N3FdIxDeA+AUQ3wbi2UDMzjDoAQBZ7/p98kNklQAAAABJRU5ErkJggg==');
}
ul li.file-entry{
list-style-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAwElEQVR42tzUAQbCUBzH8UebAsqadI0I1ICNAAl0haSDBIo2toMkUEARIBkF6QZdYX0R/ug9m0kMH/zhy+/hqSzLpD5CJAZLNKC+kUcdN4zgGbyw1UXl0cUBygQp5iJqDO5zBpWMlg0+sfg4YwerTHCKmfCAWzyod/xL0IaPQMOHVSToIESksUFTBCvwhh1ckWpc4FRrchsxEo0YrSJBC0N4GgPUfjX5BNf0wY4R5DTBHbYMSj2sEeW0wnt6yGYAAAiM90EeJ53sAAAAAElFTkSuQmCC');
}
}
"""
#markdown_css_link= """<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.1.0/github-markdown.css">"""
def show_nested_files(files):
subdirectory_files = files[1]
text = ''
for nested in subdirectory_files:
if type(nested) is str:
text += f'<li class="file-entry"><a href="/view/{nested}">{os.path.basename(nested)}</a>'
reportable_dirs = [item + '\\' for item in [env.test_cases_dir, env.test_suites_dir]]
if any([directory in nested for directory in reportable_dirs]):
text += f' <small><a href="/report/{nested}">[report]</a></small>'
text += '</li>'
elif type(nested) is tuple:
path = nested[0]
text += '<li class="dir-entry">' + os.path.basename(path) + '</li>'
text += show_nested_files(nested)
text = '<ul class="file-listing">' + text + '</ul>'
return text
def index(files):
text = ""
text += "<html><head><title>Server Index</title>"
text += '<style type="text/css">{}</style>'.format(style_basic + style_index)
text += """<style type='text/css'>
<!--
""" + css_index_content + """
//-->
</style>""".format(style_basic + style_index)
text += "</head><body class='markdown-body' style='max-width: 600px; margin: auto; margin-top: 80px'>"
text += '<h1>Testing documentation for Dipal:</h1>'
text += "<h3>Directory contents</h3>"
text += show_nested_files(files)
text += '</body></html>'
return text
def render_file_entry(nested):
filename = os.path.basename(nested)
link = f'<a href="/view/{nested}">{filename}</a>'
report_link = f' <small><a href="/report/{nested}">[report]</a></small>' if 'compiled\\' in nested else ''
return f'<li class="file-entry">{link}{report_link}</li>'
def render_directory_entry(nested):
dirname = os.path.basename(nested[0])
nested_files = nested[1]
return f'<li class="dir-entry">{dirname}{show_nested_files(nested_files[0])}</li>'
def show_nested_files2(files):
print(1, files)
nested_items = files[1]
nested_items_rendered = ''
for nested in nested_items:
if isinstance(nested, str):
nested_items_rendered += render_file_entry(nested)
elif isinstance(nested, tuple):
nested_items_rendered += render_directory_entry(nested)
return f'<ul class="file-listing">{nested_items_rendered}</ul>'
def index2(files):
style = style_basic + style_index
markdown_css = markdown_css_link
content = show_nested_files(files)
return f"""
<html>
<head>
<title>Server Index</title>
<style type="text/css">{style}</style>
{markdown_css}
</head>
<body class="markdown-body" style="max-width: 600px; margin: auto; margin-top: 80px">
<h1>Testing documentation for Dipal:</h1>
<h3>Directory contents</h3>
{content}
</body>
</html>
"""
def to_html(body):
return html_header + body + html_footer