[Checkins] SVN: z3c.schemadiff/trunk/ Added method to field-diff interface such that diff classes can output HTML directly.
Malthe Borch
mborch at gmail.com
Wed Jul 29 08:30:46 EDT 2009
Log message for revision 102364:
Added method to field-diff interface such that diff classes can output HTML directly.
Changed:
U z3c.schemadiff/trunk/CHANGES.txt
U z3c.schemadiff/trunk/src/z3c/schemadiff/browser.py
U z3c.schemadiff/trunk/src/z3c/schemadiff/interfaces.py
U z3c.schemadiff/trunk/src/z3c/schemadiff/schema.py
-=-
Modified: z3c.schemadiff/trunk/CHANGES.txt
===================================================================
--- z3c.schemadiff/trunk/CHANGES.txt 2009-07-29 11:28:51 UTC (rev 102363)
+++ z3c.schemadiff/trunk/CHANGES.txt 2009-07-29 12:30:46 UTC (rev 102364)
@@ -3,6 +3,10 @@
In next release:
+- The ``IFieldDiff`` interface now allows for a ``html_diff`` method
+ which will be used if the ``lines`` method is unavailable. This can
+ be used to implement a diff which outputs directly to HTML. [malthe]
+
- Bind schema field to source context to provide a context to the
field diff instance. [malthe]
Modified: z3c.schemadiff/trunk/src/z3c/schemadiff/browser.py
===================================================================
--- z3c.schemadiff/trunk/src/z3c/schemadiff/browser.py 2009-07-29 11:28:51 UTC (rev 102363)
+++ z3c.schemadiff/trunk/src/z3c/schemadiff/browser.py 2009-07-29 12:30:46 UTC (rev 102364)
@@ -15,12 +15,21 @@
def __call__(self, *interfaces):
results = diff(self.source, self.target, *interfaces)
-
- tables = [{'name': field.__name__,
- 'title': field.title,
- 'html': self.htmldiff.make_table(a, b, context=True)} for \
- (field, (a, b)) in results.items()]
+ tables = []
+ for field, result in results.items():
+ try:
+ a, b = result
+ except ValueError:
+ html = result
+ else:
+ html = self.htmldiff.make_table(a, b, context=True)
+
+ tables.append({
+ 'name': field.__name__,
+ 'title': field.title,
+ 'html': html})
+
return self.template(tables=tables)
Modified: z3c.schemadiff/trunk/src/z3c/schemadiff/interfaces.py
===================================================================
--- z3c.schemadiff/trunk/src/z3c/schemadiff/interfaces.py 2009-07-29 11:28:51 UTC (rev 102363)
+++ z3c.schemadiff/trunk/src/z3c/schemadiff/interfaces.py 2009-07-29 12:30:46 UTC (rev 102364)
@@ -1,5 +1,9 @@
from zope import interface
class IFieldDiff(interface.Interface):
+ def html_diff(a, b):
+ """Return an HTML diff."""
+
def lines(value):
"""Return a text string lines representation."""
+
Modified: z3c.schemadiff/trunk/src/z3c/schemadiff/schema.py
===================================================================
--- z3c.schemadiff/trunk/src/z3c/schemadiff/schema.py 2009-07-29 11:28:51 UTC (rev 102363)
+++ z3c.schemadiff/trunk/src/z3c/schemadiff/schema.py 2009-07-29 12:30:46 UTC (rev 102364)
@@ -23,11 +23,13 @@
if source_value is None or target_value is None:
continue
-
- a = diff.lines(source_value)
- b = diff.lines(target_value)
+
+ if diff.lines is not None:
+ result = diff.lines(source_value), diff.lines(target_value)
+ else:
+ result = diff.html_diff(source_value, target_value)
- results[field] = (a, b)
+ results[field] = result
return results
More information about the Checkins
mailing list