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; } ...@@ -101,13 +101,12 @@ body { font-family: courier; font-size: 12; }
out_buffer.write(self._save_annotation(lines, code_source_file , c_file)) out_buffer.write(self._save_annotation(lines, code_source_file , c_file))
def _save_annotation_header(self, c_file): def _save_annotation_header(self, c_file):
outlist = [] outlist = [u'''
outlist.append(u'<!DOCTYPE html>\n') <!DOCTYPE html>
outlist.append(u'<!-- Generated by Cython %s -->\n' % Version.watermark) <!-- Generated by Cython {watermark} -->
outlist.append(u'<html>\n') <html>
outlist.append(u"""
<head> <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"> <style type="text/css">
{css} {css}
</style> </style>
...@@ -115,33 +114,30 @@ body { font-family: courier; font-size: 12; } ...@@ -115,33 +114,30 @@ body { font-family: courier; font-size: 12; }
{js} {js}
</script> </script>
</head> </head>
""".format(css=self._css(), js=self._js)) <body>
outlist.append(u'<body>\n') <p>Generated by Cython {watermark}</p>\n'''.format(
outlist.append(u'<p>Generated by Cython %s</p>\n' % Version.watermark) css=self._css(), js=self._js, watermark=Version.watermark)]
if c_file : if c_file:
outlist.append(u'<p>Raw output: <a href="%s">%s</a></p>\n' % (c_file, c_file)) outlist.append(u'<p>Raw output: <a href="%s">%s</a></p>\n' % (c_file, c_file))
return outlist return outlist
def _save_annotation_footer(self): def _save_annotation_footer(self):
return (u'</body></html>\n',) 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 lines : original cython source code split by lines
code_source_file : generated c code keyed by line number in original file 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 target filename : name of the file in which to store the generated html
c_file : filename in which the c_code has been written c_file : filename in which the c_code has been written
""" """
outlist = [] outlist = []
outlist.extend(self._save_annotation_header(c_file)) 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()) outlist.extend(self._save_annotation_footer())
return ''.join(outlist) 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=[] outlist=[]
pos_comment_marker = u'/* \N{HORIZONTAL ELLIPSIS} */\n' pos_comment_marker = u'/* \N{HORIZONTAL ELLIPSIS} */\n'
zero_calls = dict((name, 0) for name in zero_calls = dict((name, 0) for name in
...@@ -172,7 +168,7 @@ body { font-family: courier; font-size: 12; } ...@@ -172,7 +168,7 @@ body { font-family: courier; font-size: 12; }
score = (5 * calls['py_c_api'] + 2 * calls['pyx_c_api'] + score = (5 * calls['py_c_api'] + 2 * calls['pyx_c_api'] +
calls['py_macro_api'] + calls['pyx_macro_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(u" %d: " % k)
outlist.append(line.rstrip()) 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