comparison Lib/IMPL/Web/QueryHandler/PageFormat.pm @ 154:eb478083f72b

Url support
author wizard
date Thu, 30 Sep 2010 02:13:05 +0400
parents 60fd224f3e3c
children 8638dd1374bf
comparison
equal deleted inserted replaced
153:3765adf1803f 154:eb478083f72b
9 use IMPL::Web::TT::Document; 9 use IMPL::Web::TT::Document;
10 use Template::Plugin::URL; 10 use Template::Plugin::URL;
11 use IMPL::Security::Context; 11 use IMPL::Security::Context;
12 use File::Spec; 12 use File::Spec;
13 use HTML::TreeBuilder; 13 use HTML::TreeBuilder;
14 use URI;
14 use Error qw(:try); 15 use Error qw(:try);
15 16
16 $Template::Plugin::URL::JOINT = '&'; 17 $Template::Plugin::URL::JOINT = '&';
17 18
18 BEGIN { 19 BEGIN {
70 my @path = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" ); 71 my @path = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" );
71 72
72 my @pathContainer = @path; 73 my @pathContainer = @path;
73 pop @pathContainer; 74 pop @pathContainer;
74 75
75 $doc->LoadFile ( File::Spec->catfile($this->templatesBase,@path), $this->templatesCharset, $this->templatesBase ); 76 $doc->LoadFile (
77 File::Spec->catfile($this->templatesBase,@path),
78 $this->templatesCharset,
79 $this->templatesBase,
80 {
81 result => scalar($nextHandler->()),
82 action => $action,
83 app => $action->application,
76 84
77 $doc->AddVar( result => $nextHandler->() ); 85 absoluteUrl => sub { new URI(join ('/', @root, $_[0]) ) },
78 $doc->AddVar( action => $action ); 86 baseUrl => sub { new URI (join ('/', @root, @base, $_[0]) ) },
79 $doc->AddVar( app => $action->application ); 87 relativeUrl => sub { new URI(join ('/', @root, @base, @pathContainer,$_[0]) ) },
80 88
81 $doc->AddVar( absoluteUrl => sub { join '/', @root, $_[0] } ); 89 user => IMPL::Security::Context->current->principal,
82 $doc->AddVar( baseUrl => sub { join '/', @root, @base, $_[0] } ); 90 session => IMPL::Security::Context->current,
83 $doc->AddVar( relativeUrl => sub { join '/', @root, @base, @pathContainer,$_[0] } );
84 91
85 $doc->AddVar( user => IMPL::Security::Context->current->principal ); 92 to_json => \&to_json,
86 $doc->AddVar( session => IMPL::Security::Context->current ); 93 escape_string => sub { $_[0] =~ s/"/"/g; $_[0] },
87 94 }
88 $doc->AddVar( to_json => \&to_json ); 95 );
89 $doc->AddVar( escape_string => sub { $_[0] =~ s/"/"/g; $_[0] } );
90
91 96
92 $action->response->contentType('text/html'); 97 $action->response->contentType('text/html');
93 my $hOut = $action->response->streamBody; 98 my $hOut = $action->response->streamBody;
94 if ($this->formatOutput == 1) { 99 if ($this->formatOutput == 1) {
95 my $tree = new HTML::TreeBuilder(); 100 my $tree = new HTML::TreeBuilder();
106 print $hOut $doc->Render(); 111 print $hOut $doc->Render();
107 } 112 }
108 } finally { 113 } finally {
109 $doc->Dispose; 114 $doc->Dispose;
110 }; 115 };
116 }
117
118 sub URI::_query::new_params {
119 my ($this,$params) = @_;
120
121 my $clone = $this->clone;
122 if (ref $params eq 'HASH' ) {
123 my %newParams = ($clone->query_form , %$params);
124 $clone->query_form(map { $_, $newParams{$_} } sort keys %newParams );
125 }
126 return $clone;
111 } 127 }
112 128
113 1; 129 1;
114 130
115 __END__ 131 __END__