blib/lib/PGXN/Site/Templates.pm untested

filter: Statementstmt 0.0% 0 / 1208 Branchbran 0.0% 0 / 102 Conditioncond 0.0% 0 / 40 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 22 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 1381 SCAR 37.4
CC
6
Cov
0%
BEGIN
20.0
_detailed_results
6.0
_dist_results
6.0
CRAP 42.0
1 package PGXN::Site::Templates;
2  
3 use 5.10.0;
4 use utf8;
5 use parent 'Template::Declare';
6 use PGXN::Site;
7 use PGXN::Site::Locale;
8 use Template::Declare::Tags;
9 use Software::License::PostgreSQL;
10 use Software::License::BSD;
11 use Software::License::MIT;
12 use List::Util qw(first);
13 use File::Basename qw(basename);
14 use SemVer;
15 use Gravatar::URL;
16 #use namespace::autoclean; # Do not use; breaks sort {}
17 our $VERSION = v0.22.1;
18  
19 my $l = PGXN::Site::Locale->get_handle('en');
20 sub T { $l->maketext(@_) }
21  
22 BEGIN { create_wrapper wrapper => sub {
23 my ($code, $req, $args) = @_;
24 $l = PGXN::Site::Locale->accept($req->env->{HTTP_ACCEPT_LANGUAGE});
25 my $v = PGXN::Site->version_string;
26 outs_raw '<!DOCTYPE html>';
27 html {
28 lang is 'en';
29 outs_raw( "\n", join "\n",
30 '<!--',
31 '____________________________________________________________',
32 '| |',
33 '| DESIGN + Pat Heard { https://fullahead.org } |',
34 '| DATE + 2006.03.19 |',
35 '| COPYRIGHT + Free use if this notice is left in place |',
36 '|____________________________________________________________|',
37 '-->'
38 );
39  
40 head {
41 meta {
42 name is 'viewport';
43 content is 'width=device-width, initial-scale=1.0';
44 };
45 title { $args->{title} };
46 for my $spec (
47 [ layout => 'screen, projection, tv' ],
48 [ print => 'print' ],
49 ) {
50 link {
51 rel is 'stylesheet';
52 type is 'text/css';
53 href is "/ui/css/$spec->[0].css?$v";
54 media is $spec->[1];
55 };
56 }
57 # https://evilmartians.com/chronicles/how-to-favicon-in-2021-six-files-that-fit-most-needs
58 # SVG covers majority of cases.
59 link {
60 rel is 'icon';
61 href is "/ui/img/icon.svg";
62 type is 'image/svg+xml';
63 };
64 # ICO covers most other cases. Generated from the 32px PNG in
65 # Preview.app by holding down option for additional export options.
66 link {
67 rel is 'icon';
68 href is "/ui/img/icon.ico";
69 };
70 # Include a couple PNGs to be safe.
71 for my $size (qw(256 32)) {
72 link {
73 rel is 'icon';
74 href is "/ui/img/icon-$size.png";
75 type is 'image/png';
76 sizes is "${size}x${size}";
77 };
78 }
79 # Special case for Apple touch devices.
80 link {
81 rel is 'apple-touch-icon';
82 href is "/ui/img/icon-180.png";
83 sizes is "180x180";
84 };
85 # Special case for Android devices.
86 link {
87 rel is 'manifest';
88 href is "/ui/manifest.json";
89 };
90  
91 # Metadata. Twitter and Facebook unfurls as described in
92 # https://medium.com/p/e64b4bb9254
93 my $desc = $args->{description} || T 'Search all indexed extensions, distributions, users, and tags on the PostgreSQL Extension Network.';
94 for my $spec (
95 [ name => 'generator', content => "PGXN::Site $v" ],
96 [ name => 'keywords', content => $args->{keywords} || 'PostgreSQL, extensions, PGXN, PostgreSQL Extension Network' ],
97 [ name => 'description', content => $desc ],
98 [ property => 'og:type', content => 'website' ],
99 [ property => 'og:url', content => $args->{base_url} . $req->path ],
100 [ property => 'og:title', content => $args->{title} ],
101 [ property => 'og:site_name', content => T 'hometitle' ],
102 [ property => 'og:description', content => $desc ],
103 [ property => 'og:image', content => "$args->{base_url}/ui/img/icon-512.png" ],
104 [ name => 'twitter:card', content => 'summary' ],
105 [ name => 'twitter:site', content => '@pgxn' ],
106 [ name => 'twitter:title', content => $args->{title} ],
107 [ name => 'twitter:description', content => $desc ],
108 [ name => 'twitter:image', content => "$args->{base_url}/ui/img/icon-512.png" ],
109 [ name => 'twitter:image:alt', content => 'PGXN gear logo' ],
110 ( $args->{user_twitter}
111 ? [ name => 'twitter:creator', content => '@' .$args->{user_twitter} ]
112 : ()
113 ),
114 ) {
115 meta { attr sub { @{ $spec } } }
116 }
117 }; # /head
118  
119 body {
120 # HEADER: Holds title, subtitle and header images -->
121 div {
122 id is 'all';
123 div {
124 id is 'header';
125 div {
126 id is 'title';
127 h1 { 'PGXN' };
128 h2 { T 'PostgreSQL Extension Network' };
129 };
130 a {
131 href is '/';
132 rel is 'home';
133 img {
134 src is '/ui/img/gear.png';
135 alt is T 'PGXN Gear';
136 class is 'gear';
137 };
138 img {
139 src is '/ui/img/pgxn.png';
140 alt is T 'PostgreSQL Extension Network';
141 class is 'right';
142 };
143 };
144 }; # /div#header
145 # CONTENT: Holds all site content except for the footer. This
146 # is what causes the footer to stick to the bottom
147 div {
148 id is 'content';
149 # MAIN MENU: Top horizontal menu of the site. Use
150 # class="here" to turn the current page tab on.
151 div {
152 id is 'mainMenu';
153 if (my $crumb = $args->{crumb}) {
154 ul {
155 id is 'crumb';
156 class is 'floatLeft';
157 $crumb->();
158 }
159 }
160 ul {
161 class is 'floatRight';
162 my $path = $req->uri->path;
163 for my $spec (
164 [ '/users/', 'PGXN Users', 'Users' ],
165 [ '/tags/', 'Release Tags', 'Tags' ],
166 [ '/recent/', 'Recent Releases', 'Recent' ],
167 ) {
168 li {
169 class is 'here' if $path eq $spec->[0];
170 a {
171 href is $spec->[0];
172 title is T $spec->[1];
173 T $spec->[2];
174 };
175 };
176 }
177 };
178 }; # /div#mainMenu
179  
180 # Content goes here!
181 $code->();
182  
183 }; # /div#content
184 }; # /div#all
185  
186 # FOOTER: Site footer for links, copyright, etc.
187 div {
188 id is 'footer';
189 div {
190 id is 'width';
191 span {
192 class is 'floatLeft';
193 a {
194 href is 'https://blog.pgxn.org/';
195 title is T 'PGXN Blog';
196 T 'Blog';
197 };
198 span { class is 'grey'; '|' };
199 a {
200 href is 'https://twitter.com/pgxn/';
201 title is T 'Follow PGXN on Twitter';
202 T 'Twitter';
203 };
204 span { class is 'grey'; '|' };
205 a {
206 href is 'https://manager.pgxn.org/';
207 title is T 'Release it on PGXN';
208 T 'Release It';
209 };
210 };
211 span {
212 class is 'floatRight';
213 a {
214 href is '/about/';
215 title is T 'About PGXN';
216 T 'About';
217 };
218 span { class is 'grey'; '|' };
219 a {
220 href is '/faq/';
221 title is T 'Frequently Asked Questions';
222 T 'FAQ';
223 };
224 span { class is 'grey'; '|' };
225 a {
226 href is '/mirroring/';
227 title is T 'Mirroring';
228 T 'Mirroring';
229 };
230 span { class is 'grey'; '|' };
231 a {
232 href is '/feedback/';
233 title is T 'Feedback';
234 T 'Feedback';
235 };
236 }; # /span.floatRight
237 }; # /div#width
238 }; # /div#footer
239 }; # /body
240 }; # /html
241 }; }
242  
243  
244 template home => sub {
245 my ($self, $req, $args) = @_;
246 wrapper {
247 div {
248 id is 'homepage';
249 div {
250 class is 'hsearch floatLeft';
251 show search_form => {
252 id => 'homesearch',
253 in => 'doc',
254 autofocus => 1,
255 };
256  
257 outs_raw $args->{cloud}->html;
258 }; # /div.hsearch floatLeft
259  
260 # 25 percent width column, aligned to the right.
261 div {
262 class is 'hside floatLeft gradient';
263 p { T 'pgxn_summary_paragraph' };
264 h3 { T 'Recent Releases' };
265 my $dists = $args->{dists};
266 if ($dists && @{ $dists }) {
267 dl {
268 id is 'recent';
269 my ($count, %seen) = 0;
270 for my $dist (@{ $dists }) {
271 next if $seen{ lc $dist->{dist} }++;
272 dt { a {
273 my @vals = map { $dist->{$_} } qw(dist version);
274 href is '/dist/' . lc join('/', @vals) . '/';
275 join ' ', @vals
276 } };
277 dd { $dist->{abstract} };
278 last if ++$i == 5;
279 };
280 };
281 h6 {
282 class is 'floatRight';
283 a {
284 href is '/recent/';
285 title is T 'See a longer list of recent releases.';
286 T 'More Releases';
287 }
288 };
289 } else {
290 p { T 'No Releases Yet' }
291 }
292 }; # /div.hside floatLeft gradient
293  
294 }; # /div#homepage
295 } $req, { %{ $args }, title => T 'hometitle' };
296 };
297  
298 sub _title_with($) {
299 $_[0] . ' / ' . T 'PostgreSQL Extension Network';
300 }
301  
302 template distribution => sub {
303 my ($self, $req, $args) = @_;
304 my $dist = $args->{dist};
305 wrapper {
306 div {
307 id is 'page';
308 class is 'dist';
309 div {
310 class is 'gradient meta';
311 div {
312 class is 'controls';
313 span {
314 class is 'download';
315 a {
316 class is 'url';
317 href is URI->new($args->{api_url} . $dist->download_path);
318 title is T 'Download [_1] [_2]', $dist->name, $dist->version;
319 img {
320 src is '/ui/img/download.svg';
321 alt is T 'Download';
322 };
323 };
324 }; # /span.download
325 span {
326 class is 'browse';
327 a {
328 class is 'url';
329 href is URI->new($args->{api_url} . $dist->source_path);
330 title is T 'Browse [_1] [_2]', $dist->name, $dist->version;
331 img {
332 src is '/ui/img/opened_folder.svg';
333 alt is T 'Browse';
334 };
335 };
336 }; # /span.download
337 }; # /div.controls
338 h1 { $args->{dist_name} };
339 dl {
340 dt { T 'This Release' };
341 dd {
342 span { class is 'fn'; $dist->name };
343 span { class is 'version'; $dist->version };
344 };
345 dt { T 'Date' };
346 dd {
347 my $datetime = $dist->date;
348 (my $date = $datetime) =~ s{T.+}{};
349 # Looking forward to HTML 5 in Template::Declare.
350 outs_raw qq{<time class="bday" datetime="$datetime">$date</time>};
351 };
352 dt { T 'Status' };
353 dd { T $dist->release_status };
354 my $rel = $dist->releases;
355 my @rels = @{ $rel->{stable} || [] };
356 if (my @others = (@{ $rel->{testing} || [] }, @{ $rel->{unstable} || [] })) {
357 @rels =
358 map { $_->[0] }
359 sort { $b->[1] <=> $a->[1] }
360 map { [ $_ => SemVer->declare($_->{version}) ] } @rels, @others;
361 }
362 if (@rels > 1) {
363 # Show latest version for other statuses.
364 for my $status (qw(Stable Testing Unstable)) {
365 my $stat_version = $dist->version_for(lc $status) or next;
366 if ($dist->version ne $stat_version) {
367 dt { T "Latest $status" };
368 dd {
369 my $datetime = $dist->date_for(lc $status);
370 (my $date = $datetime) =~ s{T.+}{};
371 a {
372 href is '/dist/' . $dist->name . lc "/$stat_version/";
373 outs $dist->name . " $stat_version — ";
374 outs_raw qq{<time datetime="$datetime">$date</time>};
375 }
376 };
377 }
378 }
379 # Create a select list of all other versions.
380 dt { class is 'other'; T 'Other Releases' };
381 dd {
382 select {
383 id is 'vnav';
384 my $version = $dist->version;
385 for my $rel (@rels) {
386 # Include release status in the option name?
387 option {
388 value is '/dist/' . lc $dist->name . lc "/$rel->{version}/";
389 selected is 'selected' if $rel->{version} eq $version;
390 (my $date = $rel->{date}) =~ s{T.+}{};
391 "$rel->{version} — $date";
392 };
393 }
394 };
395 script {
396 # https://content-security-policy.com/examples/allow-inline-script/
397 # Hash for Content-Security-Policy header to allow this JS to execute.
398 # script-src 'sha256-GN1zhliF5ZZMDFdFdgbLI+BAIxikH+5wEBDQEdf4Ryk='
399 outs_raw q{document.getElementById("vnav").addEventListener("change",function(){window.location.href=this.options[this.selectedIndex].value})};
400 }
401 };
402 }
403 dt { T 'Abstract' };
404 dd { class is 'abstract'; $dist->abstract };
405 if (my $descr = $dist->description) {
406 dt { T 'Description' };
407 dd { class is 'description'; $descr };
408 }
409 dt { T 'Released By' };
410 dd {
411 span { class is 'vcard'; a {
412 class is 'url fn';
413 href is '/user/' . lc $dist->user;
414 $dist->user;
415 }};
416 };
417 dt { T 'License' };
418 dd {
419 if (ref $dist->license eq 'HASH') {
420 my $licenses = $dist->license;
421 for my $license (sort keys %{ $licenses }) {
422 a {
423 rel is 'license';
424 href is $licenses->{$license};
425 $license;
426 };
427 }
428 } else {
429 for my $l (ref $dist->license ? @{ $dist->license } : ($dist->license)) {
430 if (my $license = _license($l)) {
431 a {
432 rel is 'license';
433 href is $license->url;
434 _license_name($license);
435 };
436 } else {
437 my %other_strings = (
438 map { $_ => 1 } qw(open_source restricted unrestricted)
439 );
440 outs $other_strings{$l} ? $l : 'unknown';
441 }
442 }
443 for my $license (grep {
444 defined
445 } map {
446 _license($_)
447 } ref $dist->license ? @{ $dist->license } : ($dist->license)) {
448 }
449 }
450 };
451 my $res = $dist->resources;
452 if (%{ $res }) {
453 dt { T 'Resources' };
454 my @res;
455 if (my $url = $res->{homepage}) {
456 push @res => [ 'url', $url, T 'www' ];
457 }
458 if (my $repo = $res->{repository}) {
459 if (my $url = $repo->{url}) {
460 push @res => [ 'url', $url, $repo->{type} ];
461 }
462 if (my $url = $repo->{web}) {
463 # XXX Think of a better name than "repo"?
464 push @res => [ 'url', $url, T 'repo' ];
465 }
466 }
467 if (my $bug = $res->{bugtracker}) {
468 if (my $url = $bug->{web}) {
469 push @res => [ 'url', $url, T 'bugs' ]
470 }
471  
472 if (my $email = $bug->{mailto}) {
473 push @res => [ 'email', "mailto:$email", $email ]
474 }
475 }
476 dd {
477 class is 'resources';
478 ul {
479 my $last = pop @res;
480 for my $spec (@res) {
481 li {
482 a {
483 class is $spec->[0];
484 href is $spec->[1];
485 $spec->[2];
486 };
487 };
488 }
489 li {
490 class is 'last';
491 a {
492 class is $last->[0];
493 href is $last->[1];
494 $last->[2];
495 };
496 };
497 };
498 };
499 }
500 if (my @files = $dist->special_files) {
501 dt { T 'Special Files' };
502 dd {
503 class is 'files';
504 ul {
505 my $uri = $args->{api_url} . $dist->source_path;
506 for my $file (@files) {
507 li {
508 class is 'last' if $file eq $files[-1];
509 a {
510 href is URI->new("$uri$file");
511 $file;
512 };
513 };
514 }
515 }
516 };
517 }
518 if (my @tags = $dist->tags) {
519 dt { T 'Tags' };
520 dd {
521 class is 'tags';
522 ul {
523 my $last = pop @tags;
524 for my $tag (@tags) {
525 li { a {
526 href is URI->new(lc "/tag/$tag/");
527 $tag;
528 } };
529 }
530 li {
531 class is 'last';
532 a {
533 href is URI->new(lc "/tag/$last/");
534 $last;
535 };
536 };
537 };
538 };
539 }
540 }; # /dl
541 }; # /div.gradient meta
542  
543 my $docs = $dist->docs;
544 my $sep = $req->uri =~ m{/$} ? '' : '/';
545 div {
546 class is 'gradient exts';
547 h3 { T 'Extensions' };
548 dl {
549 my $provides = $dist->provides;
550 for my $ext (sort { $a cmp $b } keys %{ $provides }) {
551 my $info = $provides->{$ext};
552 my $path = $info->{docpath};
553 dt {
554 if ($path) {
555 delete $docs->{$path};
556 a {
557 href is $req->uri->path . "$sep$path.html";
558 span { class is 'fn'; $ext };
559 span { class is 'version'; $info->{version} };
560 };
561 } else {
562 span { class is 'fn'; $ext };
563 span { class is 'version'; $info->{version} };
564 }
565 };
566 dd { class is 'abstract'; $info->{abstract} };
567 }
568 } # /dl
569 }; # /div.gradient exts
570  
571 my $has_readme = delete $docs->{README};
572  
573 if (%{ $docs }) {
574 div {
575 class is 'gradient docs';
576 h3 { T 'Documentation' };
577 dl {
578 while (my ($path, $info) = each %{ $docs }) {
579 dt {
580 class is 'doc';
581 a {
582 href is $req->uri->path . "$sep$path.html";
583 span {
584 class is 'fn';
585 if ($info->{abstract}) {
586 outs $info->{title}
587 } else {
588 outs basename $path;
589 }
590 };
591 };
592 };
593 dd { class is 'abstract'; $info->{abstract} || $info->{title} };
594 }
595 };
596 };
597 }
598  
599 if ($has_readme) {
600 my $body = $dist->body_for_html_doc('README');
601 utf8::decode $body;
602 div {
603 class is 'gradient exts readme';
604 h3 { T 'README' };
605 outs_raw $body;
606 };
607 }
608 }; # /div#page
609 } $req, {
610 %{ $args },
611 title => _title_with $args->{dist_name} . ': ' . $dist->abstract,
612 description => $dist->description,
613 keywords => join(', ' => $dist->tags),
614 user_twitter => $args->{user}->twitter,
615 crumb => sub {
616 li { a {
617 href is '/user/' . lc $dist->user;
618 title is $dist->user;
619 $dist->user;
620 } };
621 li {
622 class is 'sub here';
623 a {
624 href is $req->uri->path;
625 title is $args->{dist_name};
626 $args->{dist_name};
627 }
628 };
629 },
630 };
631 };
632  
633 template document => sub {
634 my ($self, $req, $args) = @_;
635 my $dist = $args->{dist};
636 my $info = $dist->docs->{$args->{docpath}};
637 my $title = $info->{abstract} ? $info->{title} : basename $args->{docpath};
638  
639 wrapper {
640 div {
641 id is 'page';
642 class is 'doc';
643 outs_raw $args->{body};
644 }; # /div#page
645 } $req, {
646 %{ $args },
647 title => _title_with $title . ($info->{abstract} ? ": $info->{abstract}" : ''),
648 description => $info->{abstract},
649 keywords => join(', ' => $dist->tags),
650 user_twitter => $args->{user}->twitter,
651 crumb => sub {
652 li { a {
653 href is '/user/' . lc $dist->user;
654 title is $dist->user;
655 $dist->user;
656 } };
657 li {
658 class is 'sub';
659 a {
660 href is $args->{dist_uri};
661 title is $args->{dist_name};
662 $args->{dist_name};
663 }
664 };
665 li {
666 class is 'sub here';
667 a {
668 href is $req->uri->path;
669 title is $title;
670 $title;
671 }
672 };
673 },
674 };
675 };
676  
677 template spec => sub {
678 my ($self, $req, $args) = @_;
679 my $title = T 'PGXN Meta Spec';
680  
681 wrapper {
682 div {
683 id is 'page';
684 class is 'doc';
685 outs_raw $args->{body};
686 }; # /div#page
687 } $req, {
688 %{ $args },
689 title => _title_with $title,
690 description => 'The PGXN distribution metadata specification',
691 };
692 };
693  
694 template user => sub {
695 my ($self, $req, $args) = @_;
696 my $user = $args->{user};
697  
698 wrapper {
699 div {
700 id is 'page';
701 class is 'dist';
702 div {
703 class is 'gradient meta vcard';
704 a {
705 class is 'avatar';
706 href is $user->uri || $req->uri->path;
707 img {
708 src is gravatar_url(
709 rating => 'pg',
710 email => $user->email,
711 size => 80,
712 https => 1,
713 default => "$args->{base_url}/ui/img/shirt.png",
714 );
715 };
716 };
717 h1 { class is 'fn'; $user->name };
718 dl {
719 dt { T 'Nickname' };
720 dd {a {
721 class is 'nickname';
722 href is '/user/' . lc $user->nickname;
723 $user->nickname;
724 } };
725 dt { T 'Email' };
726 dd {
727 class is 'email';
728 outs_raw _link_for_email($user->email);
729 };
730 if (my $uri = $user->uri) {
731 dt { T 'URL' };
732 dd {
733 class is 'url';
734 a { href is $uri; $uri; };
735 };
736 }
737 if (my $t = $user->twitter) {
738 dt { T 'Twitter' };
739 dd {
740 class is 'twitter';
741 a { href is "https://twitter.com/$t"; $t };
742 };
743 }
744 };
745 }; # /div.gradient meta vcard
746  
747 show release_table => $req, $user->releases, $args;
748 }; # /div#page
749 } $req, {
750 %{ $args },
751 title => _title_with $user->name . ' (' . $user->nickname . ')',
752 description => T('Contact and extension release information for PGXN user "[_1]"', $user->nickname),
753 keywords => 'PostgreSQL, extensions, PGXN, PostgreSQL Extension Network, user, ' . $user->nickname,
754 };
755 };
756  
757 template tags => sub {
758 my ($self, $req, $args) = @_;
759 wrapper {
760 div {
761 id is 'page';
762 div {
763 class is 'gradient';
764 h1 { T 'Release Tags' };
765 show search_form => {
766 id => 'homesearch',
767 in => 'tags',
768 autofocus => 1,
769 };
770 outs_raw $args->{cloud}->html;
771 };
772 };
773 } $req, {
774 %{ $args },
775 title => T('Tags'),
776 description => T('Search for tags on PostgreSQL extension releases on PGXN'),
777 keywords => 'PostgreSQL, extensions, PGXN, PostgreSQL Extension Network, tags, search',
778 };
779 };
780  
781 template tag => sub {
782 my ($self, $req, $args) = @_;
783 my $tag = $args->{tag};
784 my $title = T 'Tag: [_1]', $tag->name;
785  
786 wrapper {
787 div {
788 id is 'page';
789 class is 'dist';
790 h1 { $title };
791 show release_table => $req, $tag->releases, $args;
792 }; # /div#page
793 } $req, {
794 %{ $args },
795 title => _title_with $title,
796 description => T('A list of PGXN extensions tagged "[_1]"', $tag),
797 keywords => "PostgreSQL, extensions, PGXN, PostgreSQL Extension Network, tags, $tag",
798 };
799 };
800  
801 template recent => sub {
802 my ($self, $req, $args) = @_;
803 my $dists = $args->{dists};
804 my $title = T 'Recent Releases';
805  
806 wrapper {
807 div {
808 id is 'page';
809 div {
810 id is 'results';
811 class is 'gradient';
812 h1 { $title };
813 if ($dists && @{ $dists }) {
814 show 'results/recent' => $dists;
815 } else {
816 h3 { T 'No Releases Yet' }
817 }
818 }; # /div.gradient
819 }; # div#page
820 } $req, {
821 %{ $args },
822 title => _title_with $title,
823 description => T('Recent PostgreSQL extension releases on PGXN'),
824 keywords => 'PostgreSQL, extensions, PGXN, PostgreSQL Extension Network, distribution, release, recent',
825 };
826 };
827  
828 template users => sub {
829 my ($self, $req, $args) = @_;
830 my $users = $args->{users};
831 my $title = T 'Search Users';
832 my $char = $args->{char} || '';
833  
834 wrapper {
835 div {
836 id is 'page';
837 div {
838 class is 'gradient';
839 if ($char && $users) {
840 h1 { $title = T 'Nicknames starting with "[_1]"', $char }
841 id is 'results';
842 if (@{ $users }) {
843 $args->{params} = [ c => $char ];
844 show 'results/users' => $users;
845 } else {
846 h3 { T 'None found' };
847 }
848 } else {
849 h1 { $title };
850 show search_form => {
851 id => 'homesearch',
852 in => 'users',
853 };
854 h3 { T 'Or select a letter' };
855 ul {
856 id is 'llist';
857 my $uri = $req->uri->path;
858 for my $c ('a'..'z') {
859 li {
860 a {
861 href is "$uri?c=$c";
862 $c;
863 };
864 };
865 }
866 };
867 }
868 };
869 };
870 } $req, {
871 %{ $args },
872 title => _title_with $title,
873 description => T('Search for PostgreSQL Extension Network users'),
874 keywords => 'PostgreSQL, extensions, PGXN, PostgreSQL Extension Network, users, search',
875 };
876 };
877  
878 template search => sub {
879 my ($self, $req, $args) = @_;
880 my $res = $args->{results};
881  
882 wrapper {
883 div {
884 id is 'page';
885 div {
886 id is 'results';
887 class is 'gradient';
888 if ($res->{hits} && @{ $res->{hits} }) {
889 $args->{params} = [
890 in => $args->{in},
891 q => $res->{query},
892 l => $res->{limit},
893 ];
894 show results => $req, $args;
895 } else {
896 h3 { T 'Search matched no documents.' }
897 }
898 }; # /div.gradient
899 }; # div#page
900 } $req, {
901 %{ $args },
902 title => $args->{results}{query} . ' / ' . T('PGXN Search'),
903 description => T('PGXN [_1] search results for "[_2]"', $args->{in}, $args->{results}{query}),
904 keywords => 'PostgreSQL, extensions, PGXN, PostgreSQL Extension Network, search',
905 crumb => sub {
906 li {
907 class is 'notmenu';
908 show search_form => {
909 in => $args->{in},
910 id => 'resultsearch',
911 %{ $res },
912 };
913 }
914 },
915 };
916 };
917  
918 template results => sub {
919 my ($self, $req, $args) = @_;
920 my $res = $args->{results};
921 my $hits = $res->{hits};
922 h3 {
923 T '[_1]-[_2] of [_3] found',
924 $res->{offset} + 1,
925 $res->{offset} + @$hits,
926 $res->{count};
927 };
928 show "results/$args->{in}" => $hits;
929 if (my $c = $res->{count}) {
930 my $uri = URI->new($req->uri->path);
931 my @params = @{ $args->{params} };
932 div {
933 class is 'searchnav';
934 if ($res->{offset}) {
935 p {
936 class is 'floatLeft';
937 a {
938 $uri->query_form(
939 @params,
940 o => $res->{offset} - $res->{limit}
941 );
942 href is $uri;
943 title is T 'Previous results';
944 T '← Prev';
945 };
946 };
947 }
948 if ($c > $res->{offset} + $res->{limit}) {
949 p {
950 class is 'floatRight';
951 style is 'clear:right';
952 a {
953 $uri->query_form(
954 @params,
955 o => $res->{offset} + $res->{limit}
956 );
957 href is $uri;
958 title is T 'Next results';
959 T 'Next →';
960 };
961 };
962 }
963 };
964 }
965 };
966  
967 template 'results/extensions' => sub {
968 _detailed_results(extension => $_[1]);
969 };
970  
971 template 'results/docs' => sub {
972 _detailed_results(title => $_[1]);
973 };
974  
975 # template 'results/detailed' => sub {
976 sub _detailed_results {
977 my $label = shift;
978 for my $hit (@{ +shift }) {
979 div {
980 class is 'res';
981 h2 {
982 if ($hit->{docpath}) {
983 a {
984 href is '/dist/' . lc $hit->{dist} . "/$hit->{docpath}.html";
985 $hit->{$label}
986 };
987 } else {
988 $hit->{$label}
989 }
990 };
991 p { outs_raw $hit->{excerpt} };
992 ul {
993 li {
994 class is 'dist';
995 a {
996 href is lc "/dist/$hit->{dist}/";
997 title is T 'In the [_1] distribution', $hit->{dist};
998 "$hit->{dist} $hit->{version}";
999 };
1000 };
1001 li {
1002 class is 'date';
1003 (my $date = $hit->{date}) =~ s{T.+}{};
1004 # Looking forward to HTML 5 in Template::Declare.
1005 outs_raw qq{<time class="bday" datetime="$hit->{date}">$date</time>};
1006 };
1007 li {
1008 class is 'user';
1009 a {
1010 href is lc "/user/$hit->{user}/";
1011 title is T 'Released by [_1]', $hit->{user_name};
1012 $hit->{user_name};
1013 };
1014 };
1015 };
1016 };
1017 }
1018 };
1019  
1020 template 'results/dists' => sub {
1021 _dist_results(['dist'], $_[1]);
1022 };
1023  
1024 template 'results/recent' => sub {
1025 _dist_results([qw(dist version)], $_[1]);
1026 };
1027  
1028 sub _dist_results {
1029 my ($fields, $res) = @_;
1030 for my $hit (@{ $res }) {
1031 div {
1032 class is 'res';
1033 h2 {
1034 a {
1035 my @vals = map { $hit->{$_} } @{ $fields };
1036 href is '/dist/' . lc join('/', @vals) . '/';
1037 join ' ', @vals
1038 };
1039 };
1040 p { $hit->{excerpt} ? outs_raw $hit->{excerpt} : $hit->{abstract} };
1041 ul {
1042 li {
1043 class is 'date';
1044 (my $date = $hit->{date}) =~ s{T.+}{};
1045 # Looking forward to HTML 5 in Template::Declare.
1046 outs_raw qq{<time class="bday" datetime="$hit->{date}">$date</time>};
1047 };
1048 li {
1049 class is 'user';
1050 a {
1051 href is lc "/user/$hit->{user}/";
1052 title is T 'Released by [_1]', $hit->{user_name};
1053 $hit->{user_name};
1054 };
1055 };
1056 };
1057 }
1058 }
1059 }
1060  
1061 template 'results/tags' => sub {
1062 my $self = shift;
1063 for my $hit (@{ + shift }) {
1064 div {
1065 class is 'res';
1066 h2 {
1067 a {
1068 href is lc "/tag/$hit->{tag}";
1069 $hit->{tag}
1070 };
1071 };
1072 }
1073 }
1074 };
1075  
1076 template 'results/users' => sub {
1077 my $self = shift;
1078 for my $hit (@{ +shift }) {
1079 div {
1080 class is 'res';
1081 h2 {
1082 a {
1083 href is lc "/user/$hit->{user}";
1084 $hit->{user};
1085 };
1086 };
1087 p { outs_raw $hit->{name} };
1088 }
1089 }
1090 };
1091  
1092 template feedback => sub {
1093 my ($self, $req, $args) = @_;
1094 wrapper {
1095 div {
1096 id is 'info';
1097 div {
1098 class is 'gradient';
1099 outs_raw $l->from_file('feedback.html', _link_for_email($args->{feedback_to}));
1100 };
1101 };
1102 } $req, {
1103 %{ $args },
1104 title => _title_with T 'Feedback',
1105 description => T('Submit feedback to PGXN or join the mail list'),
1106 keywords => 'PostgreSQL, extensions, PGXN, PostgreSQL Extension Network, contact, email, questions, community',
1107 };
1108 };
1109  
1110 template about => sub {
1111 my ($self, $req, $args) = @_;
1112 wrapper {
1113 div {
1114 id is 'info';
1115 div {
1116 class is 'gradient';
1117 outs_raw $l->from_file(
1118 'about.html',
1119 @{ $args->{stats} }{qw(extensions dists releases users tags mirrors)}
1120 );
1121 };
1122 };
1123 } $req, {
1124 %{ $args },
1125 title => _title_with T 'About PGXN',
1126 description => T('Background on PGXN'),
1127 keywords => 'PostgreSQL, extensions, PGXN, PostgreSQL Extension Network, metadata, about, manager, api, client, search',
1128 };
1129 };
1130  
1131 template donors => sub {
1132 my ($self, $req, $args) = @_;
1133 my $title = T 'Donors';
1134 wrapper {
1135 div {
1136 id is 'info';
1137 class is 'donors';
1138 div {
1139 class is 'gradient';
1140 h1 { $title };
1141 p { outs_raw T 'donors_intro' };
1142  
1143 h2 { T 'Founders' };
1144 show 'founders';
1145  
1146 h2 { T 'Patrons' };
1147 show 'patrons';
1148  
1149 h2 { T 'Benefactors' };
1150 show 'benefactors';
1151  
1152 div {
1153 div {
1154 class is 'width50 floatLeft';
1155 h2 { T 'Sponsors' };
1156 ul {
1157 li { 'Richard Broersma' };
1158 li {a{
1159 href is 'https://tigerlead.com/';
1160 'TigerLead';
1161 }};
1162 li { 'Thom Brown' };
1163 li { 'Hitoshi Harada' };
1164 li {a{
1165 href is 'https://www.25th-floor.com/';
1166 '25th-floor - de Pretis & Helmberger KG';
1167 }};
1168 };
1169 };
1170  
1171 div {
1172 class is 'width50 floatRight';
1173 h2 { T 'Advocates' };
1174 ul {
1175 li {a{
1176 href is 'https://www.hubbellgrp.com/';
1177 'Hubbell Group Inc.';
1178 }};
1179 li { 'John S. Gage' };
1180 li {a{
1181 href is 'https://www.2ndquadrant.us/';
1182 'Greg Smith';
1183 }};
1184 li {a{
1185 href is 'https://www.urbandb.com/';
1186 'UrbanDB.com';
1187 }};
1188 li {a{
1189 href is 'https://depesz.com/';
1190 'depesz';
1191 }};
1192 li {a{
1193 href is 'https://jim.nasby.net/';
1194 'Jim Nasby';
1195 }};
1196 li {a{
1197 href is 'https://www.progressivepractice.com/';
1198 'Jon Erdman';
1199 }};
1200 };
1201 };
1202 };
1203  
1204 div {
1205 style is 'clear:both; padding-top: 2em;';
1206 div {
1207 class is 'width50 floatLeft';
1208  
1209 h2 { T 'Supporters' };
1210 ul {
1211 li {a{
1212 href is 'https://www.dagolden.com/';
1213 'David Golden';
1214 }};
1215 li {a{
1216 href is 'https://thoughts.j-davis.com/';
1217 'Jeff Davis';
1218 }};
1219 li {a{
1220 href is 'https://www.estately.com/';
1221 'Estately';
1222 }};
1223 li {a{
1224 href is 'https://www.full-table-scan.com/';
1225 'Chris Spotts';
1226 }};
1227 };
1228 };
1229  
1230 div {
1231 class is 'width50 floatRight';
1232  
1233 h2 { T 'Boosters' };
1234 ul {
1235 li {a{
1236 href is 'https://www.kineticode.com/';
1237 'Kineticode, Inc.';
1238 }};
1239 li {a{
1240 href is 'https://www.cxnet.cl/';
1241 'CxNet (Chile)';
1242 }};
1243 li {a{
1244 href is 'https://www.schemaverse.com/';
1245 'Schemaverse';
1246 }};
1247 li {a{
1248 href is 'https://github.com/fabiotr/';
1249 'Fábio Telles Rodriguez';
1250 }};
1251 li {a{
1252 href is 'https://www.nextbio.com/b/search/author/Wenjian%20Yang';
1253 'Wenjian Yang';
1254 }};
1255 li {a{
1256 href is 'https://pgdba.net/blog/';
1257 'Michael Nacos';
1258 }};
1259 li { 'August Zajonc' };
1260 };
1261 };
1262 };
1263 };
1264 };
1265 } $req, {
1266 %{ $args },
1267 title => _title_with $title,
1268 description => T('donor description'),
1269 keywords => 'PostgreSQL, extensions, PGXN, PostgreSQL Extension Network, donors, support, funding thanks',
1270 };
1271 };
1272  
1273 template art => sub {
1274 my ($self, $req, $args) = @_;
1275 wrapper {
1276 div {
1277 id is 'info';
1278 div {
1279 class is 'gradient';
1280 outs_raw $l->from_file('art.html');
1281 };
1282 };
1283 } $req, {
1284 %{ $args },
1285 title => _title_with 'Identity',
1286 description => T('identity description'),
1287 keywords => 'PostgreSQL, extensions, PGXN, PostgreSQL Extension Network, identity, logo, gear, type, download, asset',
1288 };
1289 };
1290  
1291 template faq => sub {
1292 my ($self, $req, $args) = @_;
1293 wrapper {
1294 div {
1295 id is 'info';
1296 div {
1297 class is 'gradient';
1298 outs_raw $l->from_file('faq.html');
1299 };
1300 };
1301 } $req, {
1302 %{ $args },
1303 title => _title_with 'FAQ',
1304 description => T('faq description'),
1305 keywords => 'PostgreSQL, extensions, PGXN, PostgreSQL Extension Network, faq, questions, answers, releasing, registring, client, conttributing',
1306 };
1307 };
1308  
1309 template mirroring => sub {
1310 my ($self, $req, $args) = @_;
1311 wrapper {
1312 div {
1313 id is 'info';
1314 div {
1315 class is 'gradient';
1316 outs_raw $l->from_file('mirroring.html', _obscure($args->{feedback_to}) . '?subject=Mirror Registration&amp;body= &quot;mirror.hostname&quot;: {%0a &quot;url&quot;: &quot;https://hostname.of.the.pgxn/mirroring/site/root&quot;,%0a &quot;frequency&quot;: &quot;daily/bidaily/.../weekly&quot;,%0a &quot;location&quot;: &quot;city, (area?, )country, continent (lon lat)&quot;,%0a &quot;organization&quot;: &quot;full organization name&quot;,%0a &quot;timezone&quot;: &quot;Area/Location zoneinfo tz&quot;,%0a &quot;contact&quot;: &quot;email.address.to.contact@for.this.mirror&quot;,%0a &quot;bandwidth&quot;: &quot;1Gbps, 100Mbps, DSL, etc.&quot;,%0a &quot;src&quot;: &quot;rsync://from.which.host/is/this/site/mirroring/from/&quot;,%0a &quot;rsync&quot;: &quot;rsync://hostname.of.the.mirror/path (if you provide it)&quot;,%0a &quot;notes&quot;: &quot;(optional field) access restrictions, for example?&quot;%0a }%0a');
1317 };
1318 };
1319 } $req, {
1320 %{ $args },
1321 title => _title_with T('Mirroring PGXN'),
1322 description => T('mirroring description'),
1323 keywords => 'PostgreSQL, extensions, PGXN, PostgreSQL Extension Network, mirror, rsync',
1324 };
1325 };
1326  
1327 my $err = sub {
1328 my ($req, $args) = @_;
1329 wrapper {
1330 div {
1331 class is 'width100 floatLeft';
1332 div {
1333 class is 'error gradient';
1334 h1 { $args->{title} };
1335 blockquote {
1336 class is $args->{class};
1337 p { $args->{message} };
1338 };
1339 };
1340 };
1341 } $req, {
1342 %{ $args },
1343 title => _title_with T $args->{title},
1344 };
1345 };
1346  
1347 template notfound => sub {
1348 my ($self, $req, $args) = @_;
1349 $err->($req => {
1350 %{ $args },
1351 class => 'exclamation',
1352 title => T('Not Found'),
1353 message => T('Resource not found.'),
1354 });
1355 };
1356  
1357 template badrequest => sub {
1358 my ($self, $req, $args) = @_;
1359 $err->($req => {
1360 %{ $args },
1361 class => 'stop',
1362 title => T('Bad Request'),
1363 message => T(
1364 'Bad request: Missing or invalid "[_1]" query parameter.',
1365 $args->{param}
1366 ),
1367 });
1368 };
1369  
1370 template servererror => sub {
1371 my ($self, $req, $args) = @_;
1372 $err->($req => {
1373 %{ $args },
1374 class => 'stop',
1375 title => T('Internal Server Error'),
1376 message => T('Internal server error.'),
1377 });
1378 };
1379  
1380 template search_form => sub {
1381 my ($self, $args) = @_;
1382 form {
1383 id is $args->{id};
1384 action is '/search';
1385 enctype is 'application/x-www-form-urlencoded';
1386 method is 'get';
1387 fieldset {
1388 class is 'query';
1389 input {
1390 type is 'text';
1391 name is 'q';
1392 autofocus is 'autofocus' if $args->{autofocus};
1393 value is $args->{query};
1394 };
1395 }; # /fieldset.query
1396 fieldset {
1397 class is 'submitin';
1398 label { attr { id is 'inlabel'; for => 'searchin' }; T 'in' };
1399 select {
1400 id is 'searchin';
1401 name is 'in';
1402 my $in = $args->{in};
1403 for my $spec (
1404 [ docs => 'Documentation' ],
1405 [ extensions => 'Extensions' ],
1406 [ dists => 'Distributions' ],
1407 [ users => 'Users' ],
1408 [ tags => 'Tags' ]
1409 ) {
1410 option {
1411 value is $spec->[0];
1412 selected is 'selected' if $in eq $spec->[0];
1413 T $spec->[1];
1414 };
1415 }
1416 };
1417 input {
1418 type is 'submit';
1419 value is T 'PGXN Search';
1420 class is 'button';
1421 };
1422 }; # /fieldset.submitin
1423 }; # /form#resultsearch
1424 };
1425  
1426 template release_table => sub {
1427 my ($self, $req, $rel, $args) = @_;
1428 my $api = $args->{api};
1429 my $user = $args->{user};
1430 div {
1431 class is 'gradient dists';
1432 h3 { T 'Distributions' };
1433 if (%{ $rel }) {
1434 table { tbody {
1435 for my $dist (sort keys %{ $rel }) {
1436 my $status = first { $rel->{$dist}{$_} } qw(stable testing unstable);
1437 my $info = $rel->{$dist}{$status}[0];
1438 row {
1439 class is 'dist';
1440 cell {
1441 class is 'name';
1442 a {
1443 class is 'url';
1444 href is lc "/dist/$dist" . ($user ? "/$info->{version}/" : '/');
1445 span { class is 'fn'; $dist };
1446 span { class is 'version'; $info->{version} };
1447 span { class is 'status'; "($status)" } if $status ne 'stable';
1448 };
1449 };
1450 cell {
1451 class is 'abstract';
1452 $rel->{$dist}{abstract};
1453 };
1454 cell {
1455 class is 'bday';
1456 (my $date = $info->{date}) =~ s{T.+}{};
1457 # Looking forward to HTML 5 in Template::Declare.
1458 outs_raw qq{<time class="bday" datetime="$info->{date}">$date</time>};
1459 };
1460 cell {
1461 class is 'browse';
1462 a {
1463 class is 'url';
1464 href is URI->new($args->{api_url} . $api->source_path_for($dist => $info->{version}));
1465 title is T 'Browse [_1] [_2]', $dist, $info->{version};
1466 img {
1467 src is '/ui/img/opened_folder.svg';
1468 alt is T 'Browse';
1469 };
1470 }
1471 };
1472 cell {
1473 class is 'download';
1474 a {
1475 class is 'url';
1476 href is URI->new($args->{api_url} . $api->download_path_for($dist => $info->{version}));
1477 title is T 'Download [_1] [_2]', $dist, $info->{version};
1478 img {
1479 src is '/ui/img/download.svg';
1480 alt is T 'Download';
1481 };
1482 };
1483 };
1484 }; # /tr.dist
1485 }
1486 } }; # /table
1487 } else {
1488 p {
1489 class is 'alas';
1490 T 'Alas, [_1] has yet to release a distribution.', $user->nickname;
1491 } if $user;
1492 }
1493 }; # /div.gradient dists
1494 };
1495  
1496 template founders => sub {
1497 div {
1498 id is 'founders';
1499 a {
1500 href is 'https://www.meetme.com/';
1501 title is 'myYearbook';
1502 img {
1503 src is '/ui/img/myyearbook.png';
1504 alt is 'myYearbook.com';
1505 };
1506 };
1507 a {
1508 href is 'https://www.pgexperts.com/';
1509 title is 'PostgreSQL Experts, Inc.';
1510 img {
1511 src is '/ui/img/pgexperts.png';
1512 alt is 'PGX';
1513 };
1514 };
1515 a {
1516 href is 'https://www.dalibo.org/en/';
1517 title is 'Dalibo';
1518 img {
1519 src is '/ui/img/dalibo.png';
1520 alt is 'Dalibo';
1521 };
1522 };
1523 };
1524 };
1525  
1526 template patrons => sub {
1527 div {
1528 id is 'patrons';
1529 h3 {
1530 a {
1531 href is 'https://www.enovafinancial.com/';
1532 title is 'Enova Financial';
1533 img {
1534 src is '/ui/img/enova.png';
1535 alt is 'e';
1536 };
1537 outs ' Enova Financial';
1538 };
1539 };
1540 };
1541 };
1542  
1543 template benefactors => sub {
1544 ul {
1545 id is 'benefactors';
1546 for my $spec (
1547 [ 'https://www.etsy.com/' => 'Etsy' ],
1548 [ 'https://www.postgresql.us/' => 'US PostgreSQL Association' ],
1549 [ 'https://www.commandprompt.com/' => 'Command Prompt, Inc.' ],
1550 [ 'https://www.marchex.com/' => 'Marchex' ],
1551 [ 'https://younicycle.com/' => 'Younicycle, The Web System' ],
1552 ) {
1553 li { a { href is $spec->[0]; $spec->[1] } };
1554 }
1555 };
1556 };
1557  
1558 my %class_for = (
1559 agpl_3 => 'AGPL_3',
1560 apache_1_1 => 'Apache_1_1',
1561 apache_2_0 => 'Apache_2_0',
1562 artistic_1 => 'Artistic_1_0',
1563 artistic_2 => 'Artistic_2_0',
1564 bsd => 'BSD',
1565 freebsd => 'FreeBSD',
1566 gfdl_1_2 => 'GFDL_1_2',
1567 gfdl_1_3 => undef,
1568 gpl_1 => 'GPL_1',
1569 gpl_2 => 'GPL_2',
1570 gpl_3 => 'GPL_3',
1571 lgpl_2_1 => 'LGPL_2_1',
1572 lgpl_3_0 => 'LGPL_3_0',
1573 mit => 'MIT',
1574 mozilla_1_0 => 'Mozilla_1_0',
1575 mozilla_1_1 => 'Mozilla_1_1',
1576 openssl => 'OpenSSL',
1577 perl_5 => 'Perl_5',
1578 postgresql => 'PostgreSQL',
1579 qpl_1_0 => 'QPL_1_0',
1580 ssleay => 'SSLeay',
1581 sun => 'Sun',
1582 zlib => 'Zlib',
1583 );
1584  
1585 sub _license($) {
1586 my $class = $class_for{+shift} or return;
1587 $class = "Software::License::$class";
1588 eval "require $class; 1" or die;
1589 return $class;
1590 }
1591  
1592 # XXX https://github.com/Perl-Toolchain-Gang/Software-License/issues/78
1593 sub _license_name($) {
1594 my $class = ref $_[0] || $_[0];
1595 my ($name) = $class =~ /([^:]+)$/; # Grab the package name.
1596 $name =~ s/(\d)_(\d)/$1.$2/g; # Use dots in versions.
1597 $name =~ s/_/ /g; # Use spaces everywhere else.
1598 return $name;
1599 }
1600  
1601 sub _link_for_email {
1602 my $email = shift;
1603 return '<a href="'
1604 . _obscure(URI->new("mailto:$email"))
1605 . '">' . _obscure($email)
1606 . '</a>';
1607 };
1608  
1609 sub _obscure ($) {
1610 #
1611 # Input: an email address, e.g. "foo@example.com"
1612 #
1613 # Output: the email address as a mailto link, with each character
1614 # of the address encoded as either a decimal or hex entity, in
1615 # the hopes of foiling most address harvesting spam bots. E.g.:
1616 #
1617 # <a href="&#x6D;&#97;&#105;&#108;&#x74;&#111;:&#102;&#111;&#111;&#64;&#101;
1618 # x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;">&#102;&#111;&#111;
1619 # &#64;&#101;x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;</a>
1620 #
1621 # Based on a filter by Matthew Wickline, posted to the BBEdit-Talk
1622 # mailing list: <https://tinyurl.com/yu7ue>
1623 #
1624 my $addr = shift;
1625  
1626 my @encode = (
1627 sub { '&#' . ord(shift) . ';' },
1628 sub { '&#x' . sprintf( "%X", ord(shift) ) . ';' },
1629 sub { shift },
1630 );
1631  
1632 $addr =~ s{(.)}{
1633 my $char = $1;
1634 if ( $char eq '@' ) {
1635 # this *must* be encoded. I insist.
1636 $char = $encode[int rand 1]->($char);
1637 }
1638 elsif ( $char ne ':' ) {
1639 # leave ':' alone (to spot mailto: later)
1640 my $r = rand;
1641 # roughly 10% raw, 45% hex, 45% dec
1642 $char = (
1643 $r > .9 ? $encode[2]->($char) :
1644 $r < .45 ? $encode[1]->($char) :
1645 $encode[0]->($char)
1646 );
1647 }
1648 $char;
1649 }gex;
1650  
1651 return $addr;
1652 }
1653  
1654 =head1 Name
1655  
1656 PGXN::Site::Templates - HTML templates for PGXN::Site
1657  
1658 =head1 Synopsis
1659  
1660 use PGXN::Site::Templates;
1661 Template::Declare->init( dispatch_to => ['PGXN::Site::Templates'] );
1662 print Template::Declare->show('home', $req, {
1663 title => 'PGXN::Site',
1664 });
1665  
1666 =head1 Description
1667  
1668 This class defines the HTML templates used by PGXN::Site. They are used
1669 internally by L<PGXN::Site::Controller> to render the UI. They're implemented
1670 with L<Template::Declare>, but interface wise, all you need to do is C<show>
1671 them as in the L</Synopsis>.
1672  
1673 =head1 Templates
1674  
1675 =head2 Wrapper
1676  
1677 =head3 C<wrapper>
1678  
1679 Wrapper template called by all page view templates that wraps them in the
1680 basic structure of the site (logo, navigation, footer, etc.). It also handles
1681 the title of the site, and any status message or error message. These must be
1682 stored under the C<title>, C<status_msg>, and C<error_msg> keys in the args
1683 hash, respectively.
1684  
1685 =begin comment
1686  
1687 XXX Document all parameters.
1688  
1689 =end comment
1690  
1691 =head2 Full Page Templates
1692  
1693 =head3 C<home>
1694  
1695 Renders the home page of the app.
1696  
1697 =head2 Utility Functions
1698  
1699 =head3 C<T>
1700  
1701 h1 { T 'Welcome!' };
1702  
1703 Translates the string using L<PGXN::Site::Locale>.
1704  
1705 =head1 Author
1706  
1707 David E. Wheeler <david@justatheory.com>
1708  
1709 =head1 Copyright and License
1710  
1711 Copyright (c) 2010-2021 David E. Wheeler.
1712  
1713 This module is free software; you can redistribute it and/or modify it under
1714 the L<PostgreSQL License|https://www.opensource.org/licenses/postgresql>.
1715  
1716 Permission to use, copy, modify, and distribute this software and its
1717 documentation for any purpose, without fee, and without a written agreement is
1718 hereby granted, provided that the above copyright notice and this paragraph
1719 and the following two paragraphs appear in all copies.
1720  
1721 In no event shall David E. Wheeler be liable to any party for direct,
1722 indirect, special, incidental, or consequential damages, including lost
1723 profits, arising out of the use of this software and its documentation, even
1724 if David E. Wheeler has been advised of the possibility of such damage.
1725  
1726 David E. Wheeler specifically disclaims any warranties, including, but not
1727 limited to, the implied warranties of merchantability and fitness for a
1728 particular purpose. The software provided hereunder is on an "as is" basis,
1729 and David E. Wheeler has no obligations to provide maintenance, support,
1730 updates, enhancements, or modifications.
1731  
1732 =cut