diff options
Diffstat (limited to 'lib/WebCoso/TT.pm')
-rw-r--r-- | lib/WebCoso/TT.pm | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/lib/WebCoso/TT.pm b/lib/WebCoso/TT.pm index b6962fd..15e2072 100644 --- a/lib/WebCoso/TT.pm +++ b/lib/WebCoso/TT.pm @@ -4,18 +4,43 @@ use warnings; use WebCoso::Common; use Path::Class; use Template; +use Template::Stash; use Log::Log4perl ':easy'; +$Template::Stash::HASH_OPS->{sortf}=sub { + my ($hash,$field)=@_; + + if ($field) { + return [ sort { lc $hash->{$a}{$field} cmp lc $hash->{$b}{$field} } (keys %$hash )]; + } + else { + return [ sort { lc $hash->{$a} cmp lc $hash->{$b} } (keys %$hash )]; + } +}; + +$Template::Stash::HASH_OPS->{nsortf}=sub { + my ($hash,$field)=@_; + + if ($field) { + return [ sort { $hash->{$a}{$field} <=> $hash->{$b}{$field} } (keys %$hash )]; + } + else { + return [ sort { $hash->{$a} <=> $hash->{$b} } (keys %$hash )]; + } +}; + sub new { my ($class,%opts)=@_; - $opts{stash}||={ + my $self={%opts}; + bless $self,$class; + + $self->{stash}||={ dstUriFor => \&WebCoso::Common::dstUriFor, isLang => \&WebCoso::Common::isLang, + atomIdFor => sub{WebCoso::Common::getAtomIdFor($self->{fc},@_)}, }; - my $self={%opts}; - $self->{template_provider}=Template::Provider->new({ INCLUDE_PATH=> $self->{TMPLPATH}, ABSOLUTE=>1, @@ -57,14 +82,13 @@ sub new { pop @{$self->{template_provider}->include_path}; }; - bless $self,$class; + return $self; } - sub expandTT { my ($self)=@_; return $self->{expander} - } +} 1; |