Commit 59d09fd4 authored by Stefan Behnel's avatar Stefan Behnel

tweak templating in annotated code writer some more

parent f2336b61
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import os import os
import re import re
import codecs import codecs
import textwrap
from xml.sax.saxutils import escape as html_escape from xml.sax.saxutils import escape as html_escape
from StringIO import StringIO from StringIO import StringIO
...@@ -62,28 +63,28 @@ class AnnotationCCodeWriter(CCodeWriter): ...@@ -62,28 +63,28 @@ class AnnotationCCodeWriter(CCodeWriter):
if (theDiv.style.display != 'block') theDiv.style.display = 'block'; if (theDiv.style.display != 'block') theDiv.style.display = 'block';
else theDiv.style.display = 'none'; else theDiv.style.display = 'none';
} }
""" """.strip()
_css_template = """ _css_template = textwrap.dedent("""
body.cython { font-family: courier; font-size: 12; } body.cython { font-family: courier; font-size: 12; }
.cython.tag { } .cython.tag { }
.cython.line { margin: 0em } .cython.line { margin: 0em }
.cython.code { font-size: 9; color: #444444; display: none; margin-left: 20px; } .cython.code { font-size: 9; color: #444444; display: none; margin-left: 20px; }
.cython.code .py_c_api { color: red; } .cython.code .py_c_api { color: red; }
.cython.code .py_macro_api { color: #FF7000; } .cython.code .py_macro_api { color: #FF7000; }
.cython.code .pyx_c_api { color: #FF3000; } .cython.code .pyx_c_api { color: #FF3000; }
.cython.code .pyx_macro_api { color: #FF7000; } .cython.code .pyx_macro_api { color: #FF7000; }
.cython.code .refnanny { color: #FFA000; } .cython.code .refnanny { color: #FFA000; }
.cython.code .error_goto { color: #FFA000; } .cython.code .error_goto { color: #FFA000; }
.cython.code .coerce { color: #008000; border: 1px dotted #008000 } .cython.code .coerce { color: #008000; border: 1px dotted #008000 }
.cython.code .py_attr { color: #FF0000; font-weight: bold; } .cython.code .py_attr { color: #FF0000; font-weight: bold; }
.cython.code .c_attr { color: #0000FF; } .cython.code .c_attr { color: #0000FF; }
.cython.code .py_call { color: #FF0000; font-weight: bold; } .cython.code .py_call { color: #FF0000; font-weight: bold; }
.cython.code .c_call { color: #0000FF; } .cython.code .c_call { color: #0000FF; }
""" """)
def save_annotation(self, source_filename, target_filename): def save_annotation(self, source_filename, target_filename):
with Utils.open_source_file(source_filename) as f: with Utils.open_source_file(source_filename) as f:
...@@ -92,14 +93,15 @@ body.cython { font-family: courier; font-size: 12; } ...@@ -92,14 +93,15 @@ body.cython { font-family: courier; font-size: 12; }
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(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 = [u''' outlist = [
<!DOCTYPE html> textwrap.dedent(u'''\
<!-- Generated by Cython {watermark} --> <!DOCTYPE html>
<html> <!-- Generated by Cython {watermark} -->
<head> <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"> <style type="text/css">
{css} {css}
...@@ -107,10 +109,11 @@ body.cython { font-family: courier; font-size: 12; } ...@@ -107,10 +109,11 @@ body.cython { font-family: courier; font-size: 12; }
<script> <script>
{js} {js}
</script> </script>
</head> </head>
<body class="cython"> <body class="cython">
<p>Generated by Cython {watermark}</p>\n'''.format( <p>Generated by Cython {watermark}</p>
css=self._css(), js=self._js, watermark=Version.watermark)] ''').format(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
...@@ -127,11 +130,11 @@ body.cython { font-family: courier; font-size: 12; } ...@@ -127,11 +130,11 @@ body.cython { font-family: courier; font-size: 12; }
""" """
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))
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):
outlist = [] outlist = []
pos_comment_marker = u'/* \N{HORIZONTAL ELLIPSIS} */\n' pos_comment_marker = u'/* \N{HORIZONTAL ELLIPSIS} */\n'
new_calls_map = dict( new_calls_map = dict(
......
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