From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [REJECT] view: use <ul>/<li> for threading instead of tables
Date: Wed, 30 Dec 2015 01:42:26 +0000 [thread overview]
Message-ID: <20151230014226.27351-1-e@80x24.org> (raw)
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: <<a\nhref="$upfx$href/">$html</a>>]};
}
-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
next reply other threads:[~2015-12-30 1:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-30 1:42 Eric Wong [this message]
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
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=20151230014226.27351-1-e@80x24.org \
--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).