package WebGUI::Style; =head1 LEGAL ------------------------------------------------------------------- WebGUI is Copyright 2001-2005 Plain Black Corporation. ------------------------------------------------------------------- Please read the legal notices (docs/legal.txt) and the license (docs/license.txt) that came with this distribution before using this software. ------------------------------------------------------------------- http://www.plainblack.com info@plainblack.com ------------------------------------------------------------------- =cut use strict; use Tie::CPHash; use WebGUI::International; use WebGUI::Macro; use WebGUI::Session; use WebGUI::Asset::Template; use WebGUI::URL; =head1 NAME Package WebGUI::Style =head1 DESCRIPTION This package contains utility methods for WebGUI's style system. =head1 SYNOPSIS use WebGUI::Style; $template = WebGUI::Style::getTemplate(); $html = WebGUI::Style::process($content); $html = generateAdditionalHeadTags(); setLink($url,\%params); setMeta(\%params); setRawHeadTags($html); setScript($url, \%params); =head1 SUBROUTINES These subroutines are available from this package: =cut #------------------------------------------------------------------- =head2 generateAdditionalHeadTags ( ) Creates tags that were set using setLink, setMeta, setScript, and setRawHeadTags. =cut sub generateAdditionalHeadTags { # generate additional raw tags my $tags = $session{page}{head}{raw}; # generate additional link tags foreach my $url (keys %{$session{page}{head}{link}}) { $tags .= '{$name}.'"'; } $tags .= '>'."\n"; } # generate additional meta tags foreach my $tag (@{$session{page}{head}{meta}}) { $tags .= '{$name}.'"'; } $tags .= ' />'."\n"; } delete $session{page}{head}; return $tags; } #------------------------------------------------------------------- =head2 process ( content, templateId ) Returns a parsed style with content based upon the current WebGUI session information. =head3 content The content to be parsed into the style. Usually generated by WebGUI::Page::generate(). =head3 templateId The unique identifier for the template to retrieve. =cut sub process { my %var; $var{'body.content'} = shift; my $templateId = shift; if ($session{page}{makePrintable} && exists $session{asset}) { $templateId = $session{asset}->get("printableStyleTemplateId"); } elsif ($session{scratch}{personalStyleId} ne "") { $templateId = $session{scratch}{personalStyleId}; } elsif ($session{page}{useEmptyStyle}) { $templateId = 6; } $var{'head.tags'} = ' '; if ($session{var}{adminOn}) { # This "triple incantation" panders to the delicate tastes of various browsers for reliable cache suppression. $var{'head.tags'} .= ' '; } $var{'head.tags'} .= generateAdditionalHeadTags(); $var{'head.tags'} .= "\n\n"; my $style = WebGUI::Asset::Template->new($templateId); my $output; if (defined $style) { $output = $style->process(\%var); } else { $output = "WebGUI was unable to instanciate your style template.".$var{'body.content'}; } $output = WebGUI::Macro::process($output); my $macroHeadTags = generateAdditionalHeadTags(); $macroHeadTags = WebGUI::Macro::process($macroHeadTags); $output =~ s/\<\!-- macro head tags --\>/$macroHeadTags/; return $output; } #------------------------------------------------------------------- =head2 setLink ( url, params ) Sets a tag into the
of this rendered page for this page view. This is typically used for dynamically adding references to CSS and RSS documents. =head3 url The URL to the document you are linking. =head3 params A hash reference containing the other parameters to be included in the link tag, such as "rel" and "type". =cut sub setLink { my $url = shift; my $params = shift; $session{page}{head}{link}{$url} = $params; } #------------------------------------------------------------------- =head2 setMeta ( params ) Sets a tag into the of this rendered page for this page view. =head3 params A hash reference containing the parameters of the meta tag. =cut sub setMeta { my $params = shift; push(@{$session{page}{head}{meta}},$params); } #------------------------------------------------------------------- =head2 setRawHeadTags ( tags ) Sets data to be output into the of the current rendered page for this page view. =head3 tags A raw string containing tags. This is just a raw string so you must actually pass in the full tag to use this call. =cut sub setRawHeadTags { my $tags = shift; $session{page}{head}{raw} .= $tags; } #------------------------------------------------------------------- =head2 setScript ( url, params ) Sets a