$def with (a, b) $var title: $_("Diff on %s", a.key) $putctx("robots", "noindex,nofollow")
$:macros.databarDiff() $if a.type.key in ["/type/edition", "/type/work", "/type/page"]: $ title = a.title or a.key $elif a.type.key in ["/type/author"]: $ title = a.name or a.key $else: $ title = a.key

$title → Diff

$_("Added")
$_("Modified")
$_("Removed")
$_("Not changed")
$def display_revision(page):
$_("Revision %d", page.revision) $ v = get_version(page.key, page.revision) $if v.author: $_('by') $v.author.displayname $datestr(v.created) $else: $_('by Anonymous') $datestr(v.created)
$def diff_covers(p, a, b): $if a[p] != b[p]: $p $for img in a[p]: $for img in b[p]: $def listdiff(name, a, b): $ diffresults = better_diff(a or [], b or []) $name $for key, ai, a, bi, b in diffresults:
$ai $:diff_display(name, a) $bi $:diff_display(name, b)
$def diff_display(name, value): $if isinstance(value, basestring): $value $elif isinstance(value, dict): $value $else: $if name == "links": $value.title $value.url $elif name == "excerpts": $value.excerpt $elif value.key: $(value.name or value.title or value.key) $value.key $else: $ value = value.dict() $value
$code: def find_diff(a, b, p): label = p # quick hack to display images in diff if p in ["covers", "photos"]: return diff_covers(p, a, b) elif p == "table_of_contents": return thingdiff("/type/text", "table_of_contents", a.get_toc_text(), b.get_toc_text()) elif p == "title_prefix": return thingdiff("/type/string", "title_prefix", a[p].strip(), b[p].strip()) elif p == "authors": label = "authors" t = "/type/author" ap = a.get_authors() bp = b.get_authors() else: ap = a[p] bp = b[p] t = get_expected_type(a, p) if isinstance(ap, list) or isinstance(bp, list): if ap == bp: return "" else: return listdiff(label, ap, bp) elif t == "/type/string": if is_thing(ap): ap = ap.dict() if is_thing(bp): bp = bp.dict() return thingdiff(t, label, ap, bp) $ diff_count = 0 $for p in set(a.keys() + b.keys()): $ diff = find_diff(a, b, p) $if not isinstance(diff, (str, unicode)) and hasattr(diff, "next"): $ diff = u"".join(text for _x, text in diff) $if isinstance(diff, (str, unicode)): $ diff = diff and diff.strip() $if diff: $:diff $ diff_count += 1 $if diff_count == 0:
$:display_revision(a) $:display_revision(b)
$_("Both the revisions are identical.")