[PATCH v4 1/4] nmbug-status: Color threads in HTML output
authorW. Trevor King <wking@tremily.us>
Fri, 14 Feb 2014 16:48:52 +0000 (08:48 +1600)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:00:01 +0000 (10:00 -0800)
3e/c7d003187a99d6f3ce476a5cc7587ad9d33438 [new file with mode: 0644]

diff --git a/3e/c7d003187a99d6f3ce476a5cc7587ad9d33438 b/3e/c7d003187a99d6f3ce476a5cc7587ad9d33438
new file mode 100644 (file)
index 0000000..ec70a45
--- /dev/null
@@ -0,0 +1,188 @@
+Return-Path: <wking@tremily.us>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 1F1AB431FC2\r
+       for <notmuch@notmuchmail.org>; Fri, 14 Feb 2014 08:52:21 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id Xw4i8B8aHNuj for <notmuch@notmuchmail.org>;\r
+       Fri, 14 Feb 2014 08:52:13 -0800 (PST)\r
+Received: from qmta08.westchester.pa.mail.comcast.net\r
+       (qmta08.westchester.pa.mail.comcast.net [76.96.62.80])\r
+       by olra.theworths.org (Postfix) with ESMTP id 573A2431FBC\r
+       for <notmuch@notmuchmail.org>; Fri, 14 Feb 2014 08:52:13 -0800 (PST)\r
+Received: from omta14.westchester.pa.mail.comcast.net ([76.96.62.60])\r
+       by qmta08.westchester.pa.mail.comcast.net with comcast\r
+       id SEvt1n0061HzFnQ58GsCoN; Fri, 14 Feb 2014 16:52:13 +0000\r
+Received: from odin.tremily.us ([24.18.63.50])\r
+       by omta14.westchester.pa.mail.comcast.net with comcast\r
+       id SGqB1n00R152l3L3aGqCfR; Fri, 14 Feb 2014 16:50:13 +0000\r
+Received: from mjolnir.tremily.us (unknown [192.168.0.140])\r
+       by odin.tremily.us (Postfix) with ESMTPS id 6290B103A9A0;\r
+       Fri, 14 Feb 2014 08:50:11 -0800 (PST)\r
+Received: (nullmailer pid 18383 invoked by uid 1000);\r
+       Fri, 14 Feb 2014 16:48:57 -0000\r
+From: "W. Trevor King" <wking@tremily.us>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 1/4] nmbug-status: Color threads in HTML output\r
+Date: Fri, 14 Feb 2014 08:48:52 -0800\r
+Message-Id:\r
+ <f829c967cab11ae99ddb877490ccdd4fc43311dc.1392395932.git.wking@tremily.us>\r
+X-Mailer: git-send-email 1.8.5.2.8.g0f6c0d1\r
+In-Reply-To: <cover.1392395932.git.wking@tremily.us>\r
+References: <cover.1392395932.git.wking@tremily.us>\r
+In-Reply-To: <cover.1392395932.git.wking@tremily.us>\r
+References: <cover.1392395932.git.wking@tremily.us>\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net;\r
+       s=q20121106; t=1392396733;\r
+       bh=38zNAfzgI9JTABLqHGVuexbLAvczTWS39FsLjXEa3u4=;\r
+       h=Received:Received:Received:Received:From:To:Subject:Date:\r
+       Message-Id;\r
+       b=HcyF61ppZL1JIUhYGoG8dFN1HyoHtIzyhHLq+fXjdTeoBazmq6IJAiHPT/AnLbSRn\r
+       tiwcCGWfY2fDwRxLURvX1lRrsDBNRGJPClGB0DeQMws6gI4ikCt3ucf3Umg7pn48VD\r
+       Saiz+KdevkNEGZyYiVNHLEnYT1juINgzf9rKMb/mKw0jbsWjn99WrrM6IRdrZKsVyQ\r
+       XNHiJ5k9Xbc0HbQOesHUba5ETCE1fS4OT5ZWLpeSRthCQT6qLT8P03grdEhcCA+m7k\r
+       U/ZxIgYgYlry2F1y5lTsCd+29zJb+Ya7+OzALSRg4hpTDbKZoRPFskC3DrQ/0adsO6\r
+       Jx8aU6A+fZXMg==\r
+Cc: Tomi Ollila <tomi.ollila@iki.fi>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 14 Feb 2014 16:52:21 -0000\r
+\r
+Add tbody sections so we don't have to color every row.  Multiple\r
+tbody sections are allowed [1].  Use CSS 3's nth-child to handle\r
+even/odd coloring (skipping the spacer rows) [2], which is supported\r
+on the major browsers [3].\r
+\r
+border-spacing is from CCS 2.1 [4,5].  I'm using it to avoid\r
+whitespace between td cells.\r
+\r
+border-radius is from CCS 3 [6,7].  I'm using it to make the colored\r
+sections a bit less harsh.  I tried adding rounded borders to the\r
+tbody itself doesn't work, but I couldn't get that to work without\r
+setting the tbody's display to 'block'.  That rounded the corners, but\r
+collapsed the cell spacing (e.g. columns were no longer aligned).\r
+This commit's by-corner-td approach is not particularly elegant, but\r
+it works.  The td padding entries just ensure that the cell body is\r
+suitably far from the edges that it doesn't fall outside of the\r
+rounded corners.\r
+\r
+The doubled-braces are escapes from Python's str.format.\r
+\r
+[1]: http://www.w3.org/TR/html5/tabular-data.html#the-table-element\r
+[2]: http://www.w3.org/TR/css3-selectors/#nth-child-pseudo\r
+[3]: https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child#Browser_compatibility\r
+[4]: http://www.w3.org/TR/CSS2/tables.html#propdef-border-spacing\r
+[5]: https://developer.mozilla.org/en-US/docs/Web/CSS/border-spacing#Browser_compatibility\r
+[6]: http://www.w3.org/TR/css3-background/#the-border-radius\r
+[7]: https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius#Browser_compatibility\r
+---\r
+ devel/nmbug/nmbug-status | 55 +++++++++++++++++++++++++++++++++++++-----------\r
+ 1 file changed, 43 insertions(+), 12 deletions(-)\r
+\r
+diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status\r
+index 1c390e6..a8bacab 100755\r
+--- a/devel/nmbug/nmbug-status\r
++++ b/devel/nmbug/nmbug-status\r
+@@ -205,19 +205,22 @@ class HtmlPage (Page):\r
+             return\r
+         stream.write('<table>\n')\r
+         for thread in threads:\r
++            stream.write('  <tbody>\n')\r
+             for message_display_data in thread:\r
+                 stream.write((\r
+-                    '<tr>\n'\r
+-                    '  <td>{date}</td>\n'\r
+-                    '  <td><code>{message-id-term}</code></td>\n'\r
+-                    '</tr>\n'\r
+-                    '<tr>\n'\r
+-                    '  <td>{from}</td>\n'\r
+-                    '  <td>{subject}</td>\n'\r
+-                    '</tr>\n'\r
++                    '    <tr>\n'\r
++                    '      <td>{date}</td>\n'\r
++                    '      <td><code>{message-id-term}</code></td>\n'\r
++                    '    </tr>\n'\r
++                    '    <tr>\n'\r
++                    '      <td>{from}</td>\n'\r
++                    '      <td>{subject}</td>\n'\r
++                    '    </tr>\n'\r
+                     ).format(**message_display_data))\r
++            stream.write('  </tbody>\n')\r
+             if thread != threads[-1]:\r
+-                stream.write('<tr><td colspan="2"><br /></td></tr>\n')\r
++                stream.write(\r
++                    '  <tbody><tr><td colspan="2"><br /></td></tr></tbody>\n')\r
+         stream.write('</table>\n')\r
\r
+     def _message_display_data(self, *args, **kwargs):\r
+@@ -246,8 +249,35 @@ _PAGES['html'] = HtmlPage(\r
+     header='''<!DOCTYPE html>\r
+ <html lang="en">\r
+ <head>\r
+-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r
+-<title>Notmuch Patches</title>\r
++  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r
++  <title>Notmuch Patches</title>\r
++  <style media="screen" type="text/css">\r
++    table {{\r
++      border-spacing: 0;\r
++    }}\r
++    td {{\r
++      padding-left: {border_radius};\r
++      padding-right: {border_radius};\r
++    }}\r
++    tr:first-child td:first-child {{\r
++      border-top-left-radius: {border_radius};\r
++    }}\r
++    tr:first-child td:last-child {{\r
++      border-top-right-radius: {border_radius};\r
++    }}\r
++    tr:last-child td:first-child {{\r
++      border-bottom-left-radius: {border_radius};\r
++    }}\r
++    tr:last-child td:last-child {{\r
++      border-bottom-right-radius: {border_radius};\r
++    }}\r
++    tbody:nth-child(4n+1) tr td {{\r
++      background-color: #ffd96e;\r
++    }}\r
++    tbody:nth-child(4n+3) tr td {{\r
++      background-color: #bce;\r
++    }}\r
++  </style>\r
+ </head>\r
+ <body>\r
+ <h2>Notmuch Patches</h2>\r
+@@ -256,7 +286,8 @@ Generated: {date}<br />\r
+ For more infomation see <a href="http://notmuchmail.org/nmbug">nmbug</a>\r
+ </p>\r
+ <h3>Views</h3>\r
+-'''.format(date=datetime.datetime.utcnow().date()),\r
++'''.format(date=datetime.datetime.utcnow().date(),\r
++           border_radius='0.5em'),\r
+     footer='</body>\n</html>\n',\r
+     )\r
\r
+-- \r
+1.8.5.2.8.g0f6c0d1\r
+\r