Header.pm 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. title_select in place of title, the XPath of the
  21. title, for that same stylesheet
  22. The list arguments default to empty rather than to the stock sheets, so that a
  23. caller which has none -- rss_style(), notably -- gets a header with none, as it
  24. did when the route rendered this itself.
  25. theme_dir is worked out here rather than passed, as it is the same for every
  26. page and the template only wants it to build asset paths.
  27. =cut
  28. sub render (%args) {
  29. $args{lang} //= 'en-US';
  30. $args{title} //= 'tCMS';
  31. $args{stylesheets} //= [];
  32. $args{print_styles} //= [];
  33. $args{scripts} //= [];
  34. # td() answers a rooted URL path, which for a themed site starts /www/ --
  35. # the template builds hrefs with it, and /www is not in the URL space.
  36. my $theme_dir = Trog::Themes::td();
  37. $theme_dir =~ s|^/www/||;
  38. $args{theme_dir} //= $theme_dir;
  39. return Trog::Component::render_template( 'header.tx', \%args );
  40. }
  41. 1;