unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] view: thread using <ul> instead of <table>
Date: Wed, 30 Dec 2015 21:44:26 +0000	[thread overview]
Message-ID: <20151230214426.GA2860@dcvr.yhbt.net> (raw)
In-Reply-To: <20151230014226.27351-1-e@80x24.org>

On second viewing, this does render small cues which makes the
output more pleasant for lynx users.  We avoid injecting the
root (level=0) message into a list since it still wastes
precious horizontal whitespace on small displays.

This also results in small reductions in bandwidth usage as
it takes fewer tags/whitespace to render unordered lists.
---
 lib/PublicInbox/View.pm | 52 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 34 insertions(+), 18 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index ad90eb3..bcd2ebc 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -103,11 +103,7 @@ sub index_entry {
 	}
 
 	my $ts = _msg_date($mime);
-	my $rv = "<table\nsummary=l$level><tr>";
-	if ($level) {
-		$rv .= '<td><pre>' . (INDENT x $level) . '</pre></td>';
-	}
-	$rv .= "<td\nid=s$midx><pre>";
+	my $rv = "<pre\nid=s$midx>";
 	$rv .= "<b\nid=$id>$subj</b>\n";
 	$rv .= "- $from @ $ts UTC - ";
 	$rv .= "<a\nhref=\"#s$next\">next</a>";
@@ -155,8 +151,7 @@ sub index_entry {
 				"<a\nhref=\"${path}$href/T/#u\">flat</a>]";
 		}
 	}
-
-	$fh->write($rv .= '</pre></td></tr></table>');
+	$fh->write($rv .= '</pre>');
 }
 
 sub thread_html {
@@ -181,6 +176,7 @@ sub emit_thread_html {
 		seen => $seen,
 		root_anchor => anchor_for($mid),
 		anchor_idx => 0,
+		max_level => 0,
 	};
 
 	require PublicInbox::Git;
@@ -191,6 +187,10 @@ sub emit_thread_html {
 	} else {
 		my $th = thread_results($msgs);
 		thread_entry(\$cb, $git, $state, $_, 0) for $th->rootset;
+		if (my $max = $state->{max_level}) {
+			my $x = $max > 1 ? ('</ul></li>' x ($max-1)) : '';
+			$cb->write($x . '</ul>');
+		}
 	}
 	$git = undef;
 	Email::Address->purge_cache;
@@ -637,12 +637,25 @@ sub ghost_parent {
 	qq{[parent not found: &lt;<a\nhref="$upfx$href/">$html</a>&gt;]};
 }
 
-sub ghost_table {
-	my ($upfx, $mid, $level) = @_;
-	"<table\nsummary=ghost><tr><td>" .
-		(INDENT x $level) . '</td><td><pre>' .
-		ghost_parent($upfx, $mid) .
-		'</pre></td></table>';
+sub __thread_adj_level {
+	my ($cb, $state, $level) = @_;
+
+	return if $level <= 0; # flat output
+	my $max = $state->{max_level};
+	if ($level > $max) {
+		$state->{max_level} = $level;
+		$$cb->write(($max ? '<li>' : ''). '<ul><li>');
+	} else {
+		$$cb->write('<li>');
+	}
+}
+
+sub __ghost_flush {
+	my ($cb, $state, $upfx, $mid, $level) = @_;
+
+	__thread_adj_level($cb, $state, $level);
+	$$cb->write('<pre>'. ghost_parent($upfx, $mid) .  '</pre>' .
+			($level > 0 ? '</li>' : ''));
 }
 
 sub __thread_entry {
@@ -655,20 +668,23 @@ sub __thread_entry {
 	} or return;
 
 	if ($state->{anchor_idx} == 0) {
-		thread_html_head($cb, $mime, $state);
+		thread_html_head($cb, $mime, $state, $level);
 	}
 
 	if (my $ghost = delete $state->{ghost}) {
 		# n.b. ghost messages may only be parents, not children
 		foreach my $g (@$ghost) {
-			$$cb->write(ghost_table('../../', @$g));
+			__ghost_flush($cb, $state, '../../', @$g);
 		}
 	}
+	__thread_adj_level($cb, $state, $level);
 	index_entry($$cb, $mime, $level, $state);
+	$$cb->write('</li>') if $level > 0;
+
 	1;
 }
 
-sub __ghost_entry {
+sub __ghost_prepare {
 	my ($state, $node, $level) = @_;
 	my $ghost = $state->{ghost} ||= [];
 	push @$ghost, [ $node->messageid, $level ];
@@ -679,10 +695,10 @@ sub thread_entry {
 	return unless $node;
 	if (my $mime = $node->message) {
 		unless (__thread_entry($cb, $git, $state, $mime, $level)) {
-			__ghost_entry($state, $node, $level);
+			__ghost_prepare($state, $node, $level);
 		}
 	} else {
-		__ghost_entry($state, $node, $level);
+		__ghost_prepare($state, $node, $level);
 	}
 
 	thread_entry($cb, $git, $state, $node->child, $level + 1);
-- 
EW


  reply	other threads:[~2015-12-30 21:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-30  1:42 [REJECT] view: use <ul>/<li> for threading instead of tables Eric Wong
2015-12-30 21:44 ` Eric Wong [this message]
2015-12-31  8:22   ` [PATCH] view: fixup indentation nesting in search Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151230214426.GA2860@dcvr.yhbt.net \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).