unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [REJECT] view: use <ul>/<li> for threading instead of tables
@ 2015-12-30  1:42 Eric Wong
  2015-12-30 21:44 ` [PATCH] view: thread using <ul> instead of <table> Eric Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Wong @ 2015-12-30  1:42 UTC (permalink / raw)
  To: meta

Rejecting this for now since it eats precious horizontal
whitespace on browsers that can render indentation properly;
and this still doesn't render thread levels properly on lynx.
---
 lib/PublicInbox/View.pm | 53 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 35 insertions(+), 18 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index ad90eb3..be92e9f 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,16 +176,20 @@ sub emit_thread_html {
 		seen => $seen,
 		root_anchor => anchor_for($mid),
 		anchor_idx => 0,
+		max_level => 0,
 	};
 
 	require PublicInbox::Git;
 	my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
 	if ($flat) {
 		pre_anchor_entry($seen, $_) for (@$msgs);
-		__thread_entry(\$cb, $git, $state, $_, 0) for (@$msgs);
+		__thread_entry(\$cb, $git, $state, $_, -1) for (@$msgs);
 	} else {
 		my $th = thread_results($msgs);
 		thread_entry(\$cb, $git, $state, $_, 0) for $th->rootset;
+		my $max = $state->{max_level};
+		$cb->write('</ul></li>' x $max) if $max;
+		$cb->write('</ul>');
 	}
 	$git = undef;
 	Email::Address->purge_cache;
@@ -608,7 +607,7 @@ sub anchor_for {
 }
 
 sub thread_html_head {
-	my ($cb, $header, $state) = @_;
+	my ($cb, $header, $state, $level) = @_;
 	$$cb = $$cb->([200, ['Content-Type'=> 'text/html; charset=UTF-8']]);
 
 	my $s = PublicInbox::Hval->new_oneline($header->header('Subject'));
@@ -617,7 +616,7 @@ sub thread_html_head {
 		qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
 		qq!href="../t.atom"\ntype="application/atom+xml"/>! .
 		PublicInbox::Hval::STYLE .
-		"</head><body>");
+		'</head><body>' . ($level >= 0 ? '<ul>' : ''));
 }
 
 sub pre_anchor_entry {
@@ -637,12 +636,26 @@ 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
+
+	if ($level > $state->{max_level}) {
+		$state->{max_level} = $level;
+		$$cb->write('<li><ul><li>');
+	} else {
+		$$cb->write('<li>');
+	}
+}
+
+sub __thread_ghost {
+	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,16 +668,20 @@ 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));
+			__thread_ghost($cb, $state, '../../', @$g);
 		}
 	}
+	__thread_adj_level($cb, $state, $level);
+
 	index_entry($$cb, $mime, $level, $state);
+	$$cb->write('</li>');
+
 	1;
 }
 
-- 
EW


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-12-31  8:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-30  1:42 [REJECT] view: use <ul>/<li> for threading instead of tables Eric Wong
2015-12-30 21:44 ` [PATCH] view: thread using <ul> instead of <table> Eric Wong
2015-12-31  8:22   ` [PATCH] view: fixup indentation nesting in search Eric Wong

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).