Header.pm 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package Trog::Component::Header;
  2. use 5.040;
  3. use re '/aasx';
  4. use warnings FATAL => 'all';
  5. use Trog::Component ();
  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. It takes these arguments, all optional, and dies on any other:
  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. title_select in place of title, the XPath of the
  20. title, for that same stylesheet
  21. theme_dir as Trog::Component::render_template()
  22. gives it, when it is not passed
  23. The list arguments default to empty rather than to the stock sheets, so that a
  24. caller which has none -- rss_style(), notably -- gets a header with none, as it
  25. did when the route rendered this itself.
  26. =cut
  27. my @arguments = qw{title route lang author meta_desc meta_tags default_tags stylesheets print_styles scripts embed no_doctype title_select theme_dir};
  28. my %known = map { $_ => 1 } @arguments;
  29. sub render (%args) {
  30. my @unknown = grep { !$known{$_} } sort keys(%args);
  31. die "The Header component takes no argument named @unknown\n" if @unknown;
  32. $args{$_} //= undef for @arguments;
  33. $args{lang} //= 'en-US';
  34. $args{title} //= 'tCMS';
  35. $args{stylesheets} //= [];
  36. $args{print_styles} //= [];
  37. $args{scripts} //= [];
  38. return Trog::Component::render_template( 'header.tx', \%args );
  39. }
  40. 1;