Header.pm 1.7 KB

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