Commit b48ad915 authored by Stefan Behnel's avatar Stefan Behnel

add intro text and title to annotated HTML code file to make it more user friendly

parent 1f24710e
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
from __future__ import absolute_import from __future__ import absolute_import
import os import os
import os.path
import re import re
import codecs import codecs
import textwrap import textwrap
...@@ -99,9 +100,9 @@ class AnnotationCCodeWriter(CCodeWriter): ...@@ -99,9 +100,9 @@ class AnnotationCCodeWriter(CCodeWriter):
c_file = Utils.decode_filename(os.path.basename(target_filename)) c_file = Utils.decode_filename(os.path.basename(target_filename))
html_filename = os.path.splitext(target_filename)[0] + ".html" html_filename = os.path.splitext(target_filename)[0] + ".html"
with codecs.open(html_filename, "w", encoding="UTF-8") as out_buffer: with codecs.open(html_filename, "w", encoding="UTF-8") as out_buffer:
out_buffer.write(self._save_annotation(code, generated_code, c_file)) out_buffer.write(self._save_annotation(code, generated_code, c_file, source_filename))
def _save_annotation_header(self, c_file): def _save_annotation_header(self, c_file, source_filename):
outlist = [ outlist = [
textwrap.dedent(u'''\ textwrap.dedent(u'''\
<!DOCTYPE html> <!DOCTYPE html>
...@@ -109,6 +110,7 @@ class AnnotationCCodeWriter(CCodeWriter): ...@@ -109,6 +110,7 @@ class AnnotationCCodeWriter(CCodeWriter):
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cython: {filename}</title>
<style type="text/css"> <style type="text/css">
{css} {css}
</style> </style>
...@@ -117,8 +119,13 @@ class AnnotationCCodeWriter(CCodeWriter): ...@@ -117,8 +119,13 @@ class AnnotationCCodeWriter(CCodeWriter):
</script> </script>
</head> </head>
<body class="cython"> <body class="cython">
<p>Generated by Cython {watermark}</p> <p><span style="border-bottom: solid 1px grey;">Generated by Cython {watermark}</span></p>
''').format(css=self._css(), js=self._js, watermark=Version.watermark) <p>
<span style="background-color: #FFFF00">Yellow lines</span> hint at Python interaction.<br />
Click on a line that starts with a "<code>+</code>" to see the C code that Cython generated for it.
</p>
''').format(css=self._css(), js=self._js, watermark=Version.watermark,
filename=os.path.basename(source_filename) if source_filename else '')
] ]
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))
...@@ -127,7 +134,7 @@ class AnnotationCCodeWriter(CCodeWriter): ...@@ -127,7 +134,7 @@ class AnnotationCCodeWriter(CCodeWriter):
def _save_annotation_footer(self): def _save_annotation_footer(self):
return (u'</body></html>\n',) return (u'</body></html>\n',)
def _save_annotation(self, code, generated_code, c_file=None): def _save_annotation(self, code, generated_code, c_file=None, source_filename=None):
""" """
lines : original cython source code split by lines lines : original cython source code split by lines
generated_code : generated c code keyed by line number in original file generated_code : generated c code keyed by line number in original file
...@@ -135,7 +142,7 @@ class AnnotationCCodeWriter(CCodeWriter): ...@@ -135,7 +142,7 @@ class AnnotationCCodeWriter(CCodeWriter):
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, source_filename))
outlist.extend(self._save_annotation_body(code, generated_code)) outlist.extend(self._save_annotation_body(code, generated_code))
outlist.extend(self._save_annotation_footer()) outlist.extend(self._save_annotation_footer())
return ''.join(outlist) return ''.join(outlist)
......
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