Commit 62d77b27 authored by Stefan Behnel's avatar Stefan Behnel

simplify HTML templating in annotated file writer

parent 02322340
......@@ -101,13 +101,12 @@ body { font-family: courier; font-size: 12; }
out_buffer.write(self._save_annotation(lines, code_source_file , c_file))
def _save_annotation_header(self, c_file):
outlist = []
outlist.append(u'<!DOCTYPE html>\n')
outlist.append(u'<!-- Generated by Cython %s -->\n' % Version.watermark)
outlist.append(u'<html>\n')
outlist.append(u"""
outlist = [u'''
<!DOCTYPE html>
<!-- Generated by Cython {watermark} -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
{css}
</style>
......@@ -115,33 +114,30 @@ body { font-family: courier; font-size: 12; }
{js}
</script>
</head>
""".format(css=self._css(), js=self._js))
outlist.append(u'<body>\n')
outlist.append(u'<p>Generated by Cython %s</p>\n' % Version.watermark)
if c_file :
<body>
<p>Generated by Cython {watermark}</p>\n'''.format(
css=self._css(), js=self._js, watermark=Version.watermark)]
if c_file:
outlist.append(u'<p>Raw output: <a href="%s">%s</a></p>\n' % (c_file, c_file))
return outlist
def _save_annotation_footer(self):
return (u'</body></html>\n',)
def _save_annotation(self, lines, code_source_file , c_file=None):
def _save_annotation(self, lines, code_source_file, c_file=None):
"""
lines : original cython source code split by lines
code_source_file : generated c code keyed by line number in original file
target filename : name of the file in which to store the generated html
c_file : filename in which the c_code has been written
"""
outlist = []
outlist.extend(self._save_annotation_header(c_file))
outlist.extend(self._save_annotation_body(lines, code_source_file , c_file=None))
outlist.extend(self._save_annotation_body(lines, code_source_file, c_file=None))
outlist.extend(self._save_annotation_footer())
return ''.join(outlist)
def _save_annotation_body(self, lines, code_source_file , c_file=None):
def _save_annotation_body(self, lines, code_source_file, c_file=None):
outlist=[]
pos_comment_marker = u'/* \N{HORIZONTAL ELLIPSIS} */\n'
zero_calls = dict((name, 0) for name in
......@@ -172,7 +168,7 @@ body { font-family: courier; font-size: 12; }
score = (5 * calls['py_c_api'] + 2 * calls['pyx_c_api'] +
calls['py_macro_api'] + calls['pyx_macro_api'])
outlist.append(u"<pre class='cython line score-%s' onclick='toggleDiv(this)'>" % (score))
outlist.append(u"<pre class='cython line score-%s' onclick='toggleDiv(this)'>" % score)
outlist.append(u" %d: " % k)
outlist.append(line.rstrip())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment