Header.pm 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. It takes these arguments, all optional, and dies on any other:
  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. theme_dir as Trog::Component::render_template()
  23. gives it, when it is not passed
  24. The template also gets icons, the URL path of each favicon by its file name,
  25. from the theme where it has that icon and from the stock ones where it does
  26. not.
  27. The list arguments default to empty rather than to the stock sheets, so that a
  28. caller which has none -- rss_style(), notably -- gets a header with none, as it
  29. did when the route rendered this itself.
  30. =cut
  31. my @arguments = qw{title route lang author meta_desc meta_tags default_tags stylesheets print_styles scripts embed no_doctype title_select theme_dir};
  32. my %known = map { $_ => 1 } @arguments;
  33. sub render (%args) {
  34. my @unknown = grep { !$known{$_} } sort keys(%args);
  35. die "The Header component takes no argument named @unknown\n" if @unknown;
  36. $args{$_} //= undef for @arguments;
  37. $args{lang} //= 'en-US';
  38. $args{title} //= 'tCMS';
  39. $args{stylesheets} //= [];
  40. $args{print_styles} //= [];
  41. $args{scripts} //= [];
  42. $args{icons} = { map { $_ => Trog::Themes::url_path( Trog::Themes::themed("img/icon/$_") ) } qw{favicon.svg favicon-167.png favicon-180.png favicon-48.png favicon-192.png} };
  43. return Trog::Component::render_template( 'header.tx', \%args );
  44. }
  45. 1;