mason/dhandler: Pass arguments to the subcomponent.
[tgal] / mason / dhandler
index bf700a8..ca5dad2 100755 (executable)
@@ -82,6 +82,16 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
            urlencode "$SCRIPTURL/$uplink";
        }
        (my $nosl = $path) =~ s!/$!!;
+
+       my %tn;
+       for my $f (@$ff)
+         { $tn{$f} = TrivGal::Image->new($path . $f->name); }
+       for my $d (@$dd) {
+         my ($ddd, $fff, $iii) = listdir $real . "/" . $d->name;
+         $tn{$d} = $iii ?
+           TrivGal::Image->new(join_paths $path, $d->name, $iii->name) :
+           undef;
+       }
 </%perl>
 %
 <&| .html, title => "Folder " . $m->interp->apply_escapes($nosl || "[top]", "h"),
@@ -97,28 +107,28 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 %
 % if (@$dd) {
 <h2>Subfolders</h2>
-<div class=gallery>
-%   for my $d (@$dd) {
-%     my ($ddd, $fff, $iii) = listdir $real . "/" . $d->name;
-%     my $tn;
-%     if ($iii) { $tn = join_paths $path, $d->name, $iii->name; }
-%     else { $tn = undef; }
-  <& .thumbnail, target => $d->name . "/", img => $tn,
-                caption => $m->interp->apply_escapes($d->name, "h"),
-                comment => $d->comment &>\
-%   }
+%   for my $size (qw{medthumb}) {
+<div class="gallery <% $size %>">
+%     for my $d (@$dd) {
+  <& .thumbnail, target => $d->name . "/", comment => $d->comment,
+                img => $tn{$d}, size => $size,
+                caption => $m->interp->apply_escapes($d->name, "h") &>\
+%     }
 </div>
+%   }
 % }
 %
 % if (@$ff) {
 <h2>Images</h2>
-<div class=gallery>
-%   for my $f (@$ff) {
-  <& .thumbnail, target => $f->name, img => $path . $f->name,
-                caption => $m->interp->apply_escapes($f->name, "h"),
-                comment => $f->comment &>\
-%   }
+%   for my $size (qw{medthumb}) {
+<div class="gallery <% $size %>">
+%     for my $f (@$ff) {
+  <& .thumbnail, target => $f->name, comment => $f->comment,
+                img => $tn{$f}, size => "bigthumb",
+                caption => $m->interp->apply_escapes($f->name, "h") &>\
+%     }
 </div>
+%   }
 % }
 %
 <div class=fill></div>
@@ -139,7 +149,7 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
        my $realdir = join_paths $IMGROOT, $dir;
        my $urldir = join_paths $SCRIPTURL, $dir;
        my ($dd, $ff, $ii) = listdir $realdir;
-       my $vw = scaled "view", $path;
+       my $vw = TrivGal::Image->new($path)->scale("view");
 
        my $fi = undef;
        FILE: for (my $i = 0; $i < @$ff; $i++)
@@ -189,13 +199,16 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 % }
 </div>
 %
-<div class=thumbstrip>
-% for my $f (@$ff) {
-  <& .thumbnail, target => $f->name, img => $dir . "/" . $f->name,
+% my %img = map { $_ => TrivGal::Image->new($dir . "/" . $_->name) } @$ff;
+% for my $size (qw{smallthumb medthumb bigthumb}) {
+<div class="thumbstrip <% $size %>">
+%   for my $f (@$ff) {
+  <& .thumbnail, target => $f->name, img => $img{$f}, size => $size,
                 caption => $m->interp->apply_escapes($f->name, "h"),
                 focus => $f->name eq "$base$ext" &>\
-% }
+%   }
 </div>
+% }
 <& .footer, path => $dir &>
 </&>
 %
@@ -235,16 +248,16 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 %###-------------------------------------------------------------------------
 <%def .thumbnail>\
 % my $tn;
-% if (defined $img) { $tn = scaled "thumb", $img; }
+% if (defined $img) { $tn = $img->scale($size); }
 % else { $tn = "$STATICURL/folder.svg"; }
 % if ($focus) {
-  <figure class=thumb id=focusthumb>
-    <img class=thumb load=lazy src="<% $tn |u %>">
+  <figure class="thumb focusthumb <% $size %>">
+    <img class="thumb <% $size %>" load=lazy src="<% $tn |u %>">
     <figcaption><span class=name><% $caption %></span></figcaption>
 % } else {
-  <figure class=thumb>
+  <figure class="thumb <% $size %>">
     <a class=thumb href="<% $target |u %>">
-      <img class=thumb load=lazy src="<% $tn |u %>">
+      <img class="thumb <% $size %>" load=lazy src="<% $tn |u %>">
       <figcaption>
        <span class=name><% $caption %></span>
 % if (defined $comment) {
@@ -258,6 +271,7 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 <%args>
        $target
        $img
+       $size
        $caption
        $comment => undef
        $focus => 0
@@ -274,10 +288,9 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
     Trivial Gallery, copyright &copy; 2021 Mark Wooding.
     Free software: you can modify it and/or redistribute it under the
     terms of the
-    <a href="https://www.gnu.org/licenses/agpl-3.0.en.html">GNU Affero
+    <a rel=license href="https://www.gnu.org/licenses/agpl-3.0.en.html">GNU Affero
     General Public License version 3</a>.
-    Browse or download
-    the <a href="https://git.distorted.org.uk/~mdw/tgal/">source code</a>.
+    Browse or download the <a href="<% $SRCURL %>">source code</a>.
   </div>
 % my $user =
 %   find_covering_file $IMGROOT, $path, ".tgal-footer.html";
@@ -295,7 +308,6 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 %###-------------------------------------------------------------------------
 <%once>
        use autodie;
-use Data::Dumper;
        use File::stat;
 
        use TrivGal;
@@ -311,7 +323,8 @@ use Data::Dumper;
        elsif (-d $st) { $comp = ".contact"; }
        elsif (-f $st) { $comp = ".image"; }
        else { $comp = ".not-found"; }
-       $m->comp($comp, path => $path);
+        $r->header_out("X-AGPL-Source" => $SRCURL);
+       $m->comp($comp, path => $path, %ARGS);
 </%init>
 %
 %###----- That's all, folks -------------------------------------------------