[diffoscope] 01/02: Don't show +/- controls for differences with no children

Ximin Luo infinity0 at debian.org
Tue May 30 19:06:22 CEST 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch experimental
in repository diffoscope.

commit b0e034d360294c6541d51659a7b5a711568aee77
Author: Ximin Luo <infinity0 at debian.org>
Date:   Tue May 30 18:53:37 2017 +0200

    Don't show +/- controls for differences with no children
---
 diffoscope/difference.py                | 6 ++++++
 diffoscope/presenters/html/html.py      | 5 +++--
 diffoscope/presenters/html/templates.py | 3 ++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/diffoscope/difference.py b/diffoscope/difference.py
index d4acd6d..ca45041 100644
--- a/diffoscope/difference.py
+++ b/diffoscope/difference.py
@@ -121,6 +121,12 @@ class Difference(object):
                 sum(v.size() for v in self._visuals))
         return self._size_cache
 
+    def has_children(self):
+        """Whether there are children.
+
+        Useful for e.g. choosing whether to display [+]/[-] controls."""
+        return self._unified_diff is not None or self._details or self._visuals
+
     @staticmethod
     def from_feeder(feeder1, feeder2, path1, path2, source=None, comment=None, **kwargs):
         try:
diff --git a/diffoscope/presenters/html/html.py b/diffoscope/presenters/html/html.py
index cf41b09..7832cf9 100644
--- a/diffoscope/presenters/html/html.py
+++ b/diffoscope/presenters/html/html.py
@@ -486,12 +486,13 @@ def output_difference(difference, print_func, css_url, directory, parents):
     print_func(u'<div class="difference">')
     try:
         print_func(u'<div class="diffheader">')
+        diffcontrol = ("diffcontrol", u'[−]') if difference.has_children() else ("diffcontrol-nochildren", u'[∘]')
         if difference.source1 == difference.source2:
-            print_func(u'<div class="diffcontrol">[−]</div>')
+            print_func(u'<div class="%s">%s</div>' % diffcontrol)
             print_func(u'<div><span class="source">%s</span>'
                        % html.escape(difference.source1))
         else:
-            print_func(u'<div class="diffcontrol diffcontrol-double">[−]</div>')
+            print_func(u'<div class="%s diffcontrol-double">%s</div>' % diffcontrol)
             print_func(u'<div><span class="source">%s</span> vs.</div>'
                        % html.escape(difference.source1))
             print_func(u'<div><span class="source">%s</span>'
diff --git a/diffoscope/presenters/html/templates.py b/diffoscope/presenters/html/templates.py
index 10a2c84..0ee4ec2 100644
--- a/diffoscope/presenters/html/templates.py
+++ b/diffoscope/presenters/html/templates.py
@@ -119,7 +119,7 @@ HEADER = """<!DOCTYPE html>
       background: #faa;
       cursor: pointer;
     }
-    .diffoscope .diffcontrol {
+    .diffoscope .diffcontrol, .diffoscope .diffcontrol-nochildren {
       float: left;
       margin-right: 0.3em;
       cursor: pointer;
@@ -190,6 +190,7 @@ $(function() {
   });
   diffcontrols.attr('title','shift-click to show/hide all children too.');
   diffcontrols.show();
+  $(".diffcontrol-nochildren").show();
 });
 </script>
 """

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list