about summary refs log tree commit homepage
path: root/lib/PublicInbox/View.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-07-07 01:39:37 +0000
committerEric Wong <e@80x24.org>2016-07-07 01:44:10 +0000
commita380c9b55b39a4db6a21131332a2a5629428dded (patch)
tree9a279e2b0809cda1ff978a3f584c5da7b4ac8608 /lib/PublicInbox/View.pm
parent8e85257577ee4d7d49e59f048852d9d4ac6f8172 (diff)
downloadpublic-inbox-a380c9b55b39a4db6a21131332a2a5629428dded.tar.gz
We now generate all of our HTML using WwwStream which
forces us to have consistent headers and footers in
the HTML itself.

This also makes the search-capable vs search-less installs
go to the new.html endpoint to maintain consistency
(in case an admin decides to enable Xapian).
Diffstat (limited to 'lib/PublicInbox/View.pm')
-rw-r--r--lib/PublicInbox/View.pm47
1 files changed, 37 insertions, 10 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 7ff3b403..09035507 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -24,7 +24,7 @@ sub th_pfx ($) { $_[0] == 0 ? '' : TCHILD };
 
 # public functions: (unstable)
 sub msg_html {
-        my ($ctx, $mime, $footer) = @_;
+        my ($ctx, $mime) = @_;
         my $hdr = $mime->header_obj;
         my $tip = _msg_html_prepare($hdr, $ctx);
         PublicInbox::WwwStream->response($ctx, 200, sub {
@@ -853,13 +853,15 @@ sub add_topic {
         }
 }
 
-sub emit_topics {
+sub topics {
         my ($ctx) = @_;
         my $order = $ctx->{order};
         my $subjs = $ctx->{subjs};
         my $latest = $ctx->{latest};
-        my $fh = $ctx->{fh};
-        return $fh->write("\n[No topics in range]</pre>") unless scalar @$order;
+        if (!@$order) {
+                $ctx->{-html_tip} = '<pre>[No topics in range]</pre>';
+                return 404;
+        }
         my $pfx;
         my $prev = 0;
         my $prev_attr = '';
@@ -903,13 +905,38 @@ sub emit_topics {
         }
         push @recent, $cur if $cur;
         @recent = map { $_->[1] } sort { $b->[0] <=> $a->[0] } @recent;
-        $fh->write(join('', @recent) . '</pre>');
+        $ctx->{-html_tip} = join('', '<pre>', @recent, '</pre>');
+        200;
 }
 
-sub emit_index_topics {
+sub index_nav { # callback for WwwStream
+        my (undef, $ctx) = @_;
+        delete $ctx->{qp} or return;
+        my ($next, $prev);
+        $next = $prev = '    ';
+        my $latest = '';
+
+        my $next_o = $ctx->{-next_o};
+        if ($next_o) {
+                $next = qq!<a\nhref="?o=$next_o"\nrel=next>next</a>!;
+        }
+        if (my $cur_o = $ctx->{-cur_o}) {
+                $latest = qq! <a\nhref=.>latest</a>!;
+
+                my $o = $cur_o - ($next_o - $cur_o);
+                if ($o > 0) {
+                        $prev = qq!<a\nhref="?o=$o"\nrel=prev>prev</a>!;
+                } elsif ($o == 0) {
+                        $prev = qq!<a\nhref=.\nrel=prev>prev</a>!;
+                }
+        }
+        "<hr><pre>page: $next $prev$latest</pre>";
+}
+
+sub index_topics {
         my ($ctx) = @_;
         my ($off) = (($ctx->{qp}->{o} || '0') =~ /(\d+)/);
-        $ctx->{order} = [];
+        my $order = $ctx->{order} = [];
         $ctx->{subjs} = {};
         $ctx->{latest} = {};
         my $max = 25;
@@ -921,9 +948,9 @@ sub emit_index_topics {
                 walk_thread(thread_results($sres), $ctx, *add_topic);
                 $opts{offset} += $nr;
         }
-
-        emit_topics($ctx);
-        $opts{offset};
+        $ctx->{-next_o} = $opts{offset};
+        $ctx->{-cur_o} = $off;
+        PublicInbox::WwwStream->response($ctx, topics($ctx), *index_nav);
 }
 
 sub thread_adj_level {