Header.pm 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package Trog::Component::Header;
  2. use 5.040;
  3. use re '/aasx';
  4. use warnings FATAL => 'all';
  5. use Trog::Component ();
  6. use Trog::Themes;
  7. =head1 Trog::Component::Header
  8. Everything from the doctype down to the opening body tag: the title, the social
  9. and icon metadata, and the stylesheet and script links.
  10. =head1 FUNCTIONS
  11. =head2 render(%args) = STRING
  12. Render header.tx.
  13. Recognized arguments, all optional:
  14. title / route / lang / author the page itself
  15. meta_desc / meta_tags / default_tags social metadata, built by the route
  16. stylesheets / print_styles / scripts resolved paths, built by finish_render
  17. embed embedded view, which adds a base target
  18. no_doctype leave the doctype off, for the RSS
  19. stylesheet, which is XSL rather than HTML
  20. The list arguments default to empty rather than to the stock sheets, so that a
  21. caller which has none -- rss_style(), notably -- gets a header with none, as it
  22. did when the route rendered this itself.
  23. theme_dir is worked out here rather than passed, as it is the same for every
  24. page and the template only wants it to build asset paths.
  25. =cut
  26. sub render (%args) {
  27. $args{lang} //= 'en-US';
  28. $args{title} //= 'tCMS';
  29. $args{stylesheets} //= [];
  30. $args{print_styles} //= [];
  31. $args{scripts} //= [];
  32. # td() answers a rooted URL path, which for a themed site starts /www/ --
  33. # the template builds hrefs with it, and /www is not in the URL space.
  34. my $theme_dir = Trog::Themes::td();
  35. $theme_dir =~ s|^/www/||;
  36. $args{theme_dir} //= $theme_dir;
  37. return Trog::Component::render_template( 'header.tx', \%args );
  38. }
  39. 1;