changeset 202:9ffa82e550ba

highlight view: move dom conversion code to Item method
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 30 Apr 2011 16:06:18 +0200
parents 159473d3b7e7
children 1d416427b7be
files MoinMoin/apps/frontend/views.py MoinMoin/items/__init__.py
diffstat 2 files changed, 34 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Sat Apr 30 14:31:22 2011 +0200
+++ b/MoinMoin/apps/frontend/views.py	Sat Apr 30 16:06:18 2011 +0200
@@ -166,6 +166,19 @@
     return Response(content, status, mimetype='text/xml')
 
 
+@frontend.route('/+highlight/<int:rev>/<itemname:item_name>')
+@frontend.route('/+highlight/<itemname:item_name>', defaults=dict(rev=-1))
+def highlight_item(item_name, rev):
+    try:
+        item = Item.create(item_name, rev_no=rev)
+    except AccessDeniedError:
+        abort(403)
+    return render_template('highlight.html',
+                           item=item, item_name=item.name,
+                           data_text=Markup(item._render_data_highlight()),
+                          )
+
+
 @frontend.route('/+meta/<itemname:item_name>', defaults=dict(rev=-1))
 @frontend.route('/+meta/<int:rev>/<itemname:item_name>')
 def show_item_meta(item_name, rev):
@@ -230,40 +243,6 @@
         abort(403)
     return converted_item._convert(item.internal_representation())
 
-@frontend.route('/+highlight/<int:rev>/<itemname:item_name>')
-@frontend.route('/+highlight/<itemname:item_name>', defaults=dict(rev=-1))
-def highlight_item(item_name, rev):
-    from MoinMoin.items import Text, NonExistent
-    from MoinMoin.util.tree import html
-    try:
-        item = Item.create(item_name, rev_no=rev)
-    except AccessDeniedError:
-        abort(403)
-    if isinstance(item, Text):
-        from MoinMoin.converter import default_registry as reg
-        from MoinMoin.util.mime import Type, type_moin_document
-        data_text = item.data_storage_to_internal(item.data)
-        # TODO: use registry as soon as it is in there
-        from MoinMoin.converter.pygments_in import Converter as PygmentsConverter
-        pygments_conv = PygmentsConverter(mimetype=item.mimetype)
-        doc = pygments_conv(data_text.split(u'\n'))
-        # TODO: Real output format
-        html_conv = reg.get(type_moin_document, Type('application/x-xhtml-moin-page'))
-        doc = html_conv(doc)
-        from array import array
-        out = array('u')
-        doc.write(out.fromunicode, namespaces={html.namespace: ''}, method='xml')
-        content = Markup(out.tounicode())
-    elif isinstance(item, NonExistent):
-        return redirect(url_for('frontend.show_item', item_name=item_name))
-    else:
-        content = u"highlighting not supported"
-    return render_template('highlight.html',
-                           item=item, item_name=item.name,
-                           data_text=content,
-                          )
-
-
 @frontend.route('/+modify/<itemname:item_name>', methods=['GET', 'POST'])
 def modify_item(item_name):
     """Modify the wiki item item_name.
--- a/MoinMoin/items/__init__.py	Sat Apr 30 14:31:22 2011 +0200
+++ b/MoinMoin/items/__init__.py	Sat Apr 30 16:06:18 2011 +0200
@@ -261,6 +261,10 @@
                   method='xml')
         return out.tounicode()
 
+    def _render_data_highlight(self):
+        # override this in child classes
+        return ''
+
     def _do_modify_show_templates(self):
         # call this if the item is still empty
         rev_nos = []
@@ -1033,6 +1037,23 @@
         difflines = diff_text.diff(oldlines, newlines)
         return '\n'.join(difflines)
 
+    def _render_data_highlight(self):
+        from MoinMoin.converter import default_registry as reg
+        from MoinMoin.util.mime import Type, type_moin_document
+        from MoinMoin.util.tree import html
+        data_text = self.data_storage_to_internal(self.data)
+        # TODO: use registry as soon as it is in there
+        from MoinMoin.converter.pygments_in import Converter as PygmentsConverter
+        pygments_conv = PygmentsConverter(mimetype=self.mimetype)
+        doc = pygments_conv(data_text.split(u'\n'))
+        # TODO: Real output format
+        html_conv = reg.get(type_moin_document, Type('application/x-xhtml-moin-page'))
+        doc = html_conv(doc)
+        from array import array
+        out = array('u')
+        doc.write(out.fromunicode, namespaces={html.namespace: ''}, method='xml')
+        return out.tounicode()
+
     def do_modify(self, template_name):
         form = TextChaizedForm.from_defaults()
         TextCha(form).amend_form()