Viewing file: diff_div.html (12.13 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) | {# Copyright (C) 2006-2021 Edgewall Software
This software is licensed as described in the file COPYING, which
you should have received as part of this distribution. The terms
are also available at https://trac.edgewall.org/wiki/TracLicense.
This software consists of voluntary contributions made by many
individuals. For the exact contribution history, see the revision
history and logs, available at https://trac.edgewall.org/.
#}
{#
Arguments:
- changes -- a list of diff items, each being a dict containing
information about changes for one file:
.href - link for the title (optional)
.title - tooltip for the title link (optional)
.comments - annotation for the change (optional)
.new and .old - information about the files being diffed
.path - path of the file
.rev - rev of the file (for 'sidebyside')
.shortrev - abbreviated form of rev of the file (for 'inline')
.href - link to the full file (optional)
.props - a list of property changes
.name - name of the property
.diff - rendered difference
.old - old value of the property
.new - new value for the property
(both .old and .new have .name, .value and .rendered properties)
.diffs - a sequence of list of blocks
Each block being a dict:
.type - one of 'unmod', 'add', 'rem' or 'mod'
.base and .changed - information about lines from old and new content
.lines - the lines
.offset - position within the file
.diffs_title - a sequence of titles for the list of blocks
Note: integrate this into .diffs for 0.12 or 1.0.
- diff -- dict specifying diff style and options
.style - can be 'sidebyside' (4 columns) or 'inline' (3 columns)
.options - contexlines, various ignore...
- longcol -- "long" column header; e.g. 'Revision' or 'File' or ''
(for 'sidebyside')
- shortcol -- "short" column header: e.g. 'r' or '' (for 'inline')
- no_id -- skip generation of id attributes in h2 headings
#}
# if changes|selectattr('diffs') or changes|selectattr('props'):
# for item in changes:
# set old = item.old
# set new = item.new
# if item and (item.diffs or item.props or 'comments' in item):
-
# set comments = item.get('comments')
# if new.path:
${new.path}
# else:
# endif
# if comments:
${comments}
# endif
# macro prop_name(name, attrs)
${name}
# endmacro
# macro render_property(prop)
# if prop.rendered:
${prop.rendered.content}
# elif istext(prop.value):
${prop.value}
# else:
${prop.value}
# endif
# endmacro
# if item.props:
# for prop in item.props:
# if prop.diff:
${prop.diff}
# endif
# set one = prop.old or prop.new
# set both = prop.old and prop.new
# if one:
-
# set name_attrs = one.rendered and one.rendered.name_attributes
# set name = one.rendered.name if one.rendered else prop.name
# if both:
# trans name = prop_name(name, name_attrs), old = render_property(prop.old), new = render_property(prop.new)
Property ${name} changed from ${old} to ${new}
# endtrans
# elif not prop.old:
# trans name = prop_name(name, name_attrs), value = render_property(prop.new)
Property ${name} set to ${value}
# endtrans
# else:
# trans name = prop_name(name, name_attrs)
Property ${name} deleted
# endtrans
# endif
# endif
# endfor
# endif
# if item.diffs and item.diffs[0]:
# with
# set fromline = item.diffs[0][0].base.offset+1
# set toline = item.diffs[0][0].changed.offset+1
# if diff.style == 'sidebyside':
|
# if 'href' in old:
${longcol} ${old.rev}
# else:
${longcol} ${old.rev}
# endif
|
# if 'href' in new:
${longcol} ${new.rev}
# else:
${longcol} ${new.rev}
# endif
|
# elif diff.style == 'inline':
|
# if 'href' in old:
${shortcol}${old.shortrev}
# else:
${shortcol}${old.shortrev}
# endif
|
# if 'href' in new:
${shortcol}${new.shortrev}
# else:
${shortcol}${new.shortrev}
# endif
|
# if 'diffs_title' in item:
${item.diffs_title[0]}
# endif
|
# endif
# endwith
# for blocks in item.diffs:
# for block in blocks:
# if block.type == 'unmod':
## Show identical lines on both "sides"
# for line in block.base.lines:
# set from_n = block.base.offset + loop.index
# set to_n = block.changed.offset + loop.index
# set clines = block.changed.lines
# if diff.style == 'sidebyside':
| ${from_n} | ${line} |
${to_n} | ${
clines[loop.index0] if loop.index0 is lessthan(len(clines))
} |
# elif diff.style == 'inline':
${from_n} | ${to_n} | ${line} |
# endif
# endfor
# elif block.type == 'add':
## Show only added lines, on the "right side"
# for line in block.changed.lines:
# set to_n = block.changed.offset + loop.index
# if diff.style == 'sidebyside':
| | |
${to_n} | ${line} |
# elif diff.style == 'inline':
| ${to_n} | ${line} |
# endif
# endfor
# elif block.type == 'rem':
## Show only deleted lines, on the "left side"
# for line in block.base.lines:
# set from_n = block.base.offset + loop.index
# if diff.style == 'sidebyside':
| ${from_n} | ${line} |
| |
# elif diff.style == 'inline':
${from_n} | | {#
#}${line} |
# endif
# endfor
# elif 'mod':
## Show edited lines, on both "sides"
# if diff.style == 'sidebyside':
# if len(block.base.lines) >= len(block.changed.lines):
# for line in block.base.lines:
| ${block.base.offset + loop.index} |
${line} |
# set within_change = loop.index0 is lessthan(len(block.changed.lines))
${block.changed.offset + loop.index if within_change else
' '|safe} |
{%
if within_change %}${block.changed.lines[loop.index0]}{%
endif %} |
# endfor
# else:
## ## there are more changed lines than original lines
# for line in block.changed.lines:
# set within_change = loop.index0 is lessthan(len(block.base.lines))
| ${block.base.offset + loop.index if within_change else
' '|safe} |
{% if within_change
%}${block.base.lines[loop.index0]}{% endif %} |
${block.changed.offset + loop.index} |
${line} |
# endfor
# endif
# elif diff.style == 'inline':
## First show the "old" lines
# for line in block.base.lines:
| ${block.base.offset + loop.index} | | {#
#}${line} |
# endfor
## Then show the "new" lines
# for line in block.changed.lines:
| | ${block.changed.offset + loop.index} | {#
#}${line} |
# endfor
# endif
# endif
# endfor
# if loop.index is lessthan(len(item.diffs)):
# with
# set fromline = item.diffs[loop.index][0].base.offset + 1
# set toline = item.diffs[loop.index][0].changed.offset + 1
# if diff.style == 'sidebyside':
| … | {#
#} |
… | {#
#} |
# elif diff.style == 'inline':
| … |
… |
# if 'diffs_title' in item:
${item.diffs_title[loop.index]}
# endif
|
# endif
# endwith
# endif
# endfor
## jinjacheck: "thead colgroup thead" OK
# endif
# endif
# endfor
# endif
|