PostFooter.pm 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package Trog::Component::PostFooter;
  2. use 5.040;
  3. use re '/aa';
  4. use Trog::Component ();
  5. use Trog::Themes;
  6. =head1 Trog::Component::PostFooter
  7. The per-post footer a series can name in its metadata, drawn from the footers/
  8. directory of the stock templates or the theme's.
  9. =head1 FUNCTIONS
  10. =head2 render(%args) = STRING
  11. Render footers/$args{name}.
  12. The name comes out of post data, so it is checked against the footers/ listing
  13. before it becomes a path -- see available(). Returns the empty string when no
  14. name is given, so that the caller can ask unconditionally.
  15. Beyond the name, the template gets the post it belongs to and the route it is
  16. being shown at, plus theme_dir for building asset paths. That is narrower than
  17. the whole request hash these used to be rendered with; a theme whose footer
  18. wants something else should be handed it at the call site in posts.tx.
  19. =cut
  20. sub render (%args) {
  21. my $name = delete $args{name};
  22. return '' unless defined $name && length $name;
  23. die "No such footer '$name'\n" unless grep { $_ eq $name } @{ available() };
  24. $args{theme_dir} //= Trog::Themes::td();
  25. return Trog::Component::render_template( "footers/$name", \%args );
  26. }
  27. =head2 available() = ARRAYREF
  28. The footers a post may name: every .tx in footers/, the theme's and the stock ones
  29. both. This is the same list the series edit form offers, so anything the form
  30. can pick renders, and nothing else does.
  31. =cut
  32. sub available () {
  33. return Trog::Themes::themed_templates_in_dir( 'footers', 'text/html', 1 );
  34. }
  35. 1;