| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package Trog::Component::Header;
- use 5.040;
- use re '/aasx';
- use warnings FATAL => 'all';
- use Trog::Component ();
- use Trog::Themes;
- =head1 Trog::Component::Header
- Everything from the doctype down to the opening body tag: the title, the social
- and icon metadata, and the stylesheet and script links.
- =head1 FUNCTIONS
- =head2 render(%args) = STRING
- Render header.tx.
- It takes these arguments, all optional, and dies on any other:
- title / route / lang / author the page itself
- meta_desc / meta_tags / default_tags social metadata, built by the route
- stylesheets / print_styles / scripts resolved paths, built by finish_render
- embed embedded view, which adds a base target
- no_doctype leave the doctype off, for the RSS
- stylesheet, which is XSL rather than HTML
- title_select in place of title, the XPath of the
- title, for that same stylesheet
- The list arguments default to empty rather than to the stock sheets, so that a
- caller which has none -- rss_style(), notably -- gets a header with none, as it
- did when the route rendered this itself.
- theme_dir is worked out here when it is not passed, as it is the same for every
- page and the template only wants it to build asset paths.
- =cut
- my @arguments = qw{title route lang author meta_desc meta_tags default_tags stylesheets print_styles scripts embed no_doctype title_select theme_dir};
- my %known = map { $_ => 1 } @arguments;
- sub render (%args) {
- my @unknown = grep { !$known{$_} } sort keys(%args);
- die "The Header component takes no argument named @unknown\n" if @unknown;
- $args{$_} //= undef for @arguments;
- $args{lang} //= 'en-US';
- $args{title} //= 'tCMS';
- $args{stylesheets} //= [];
- $args{print_styles} //= [];
- $args{scripts} //= [];
- # td() answers a rooted URL path, which for a themed site starts /www/ --
- # the template builds hrefs with it, and /www is not in the URL space.
- my $theme_dir = Trog::Themes::td();
- $theme_dir =~ s|^/www/||;
- $args{theme_dir} //= $theme_dir;
- return Trog::Component::render_template( 'header.tx', \%args );
- }
- 1;
|