| 231 | | sub render { |
| 232 | | my ( $c, $name, $args ) = @_; |
| 233 | | |
| 234 | | croak "invalid args : $args" unless ref $args eq 'HASH'; |
| 235 | | |
| 236 | | DEBUG "rendering template"; |
| 237 | | |
| 238 | | # set default vars |
| 239 | | $args = { |
| 240 | | docroot => $c->{config}->{httpd}->{root}, |
| 241 | | render_line => sub { render_line( $c, @_ ) }, |
| 242 | | user_agent => $c->{user_agent}, |
| 243 | | mobile_agent => $c->{mobile_agent}, |
| 244 | | title => $c->{config}->{httpd}->{title}, |
| 245 | | version => $App::Mobirc::VERSION, |
| 246 | | now => time(), |
| 247 | | |
| 248 | | %$args, |
| 249 | | }; |
| 250 | | |
| 251 | | my $tmpl_dir = $c->{mobile_agent}->is_non_mobile ? 'pc' : 'mobile'; |
| 252 | | DEBUG "tmpl_dir: $tmpl_dir"; |
| 253 | | |
| 254 | | my $tt = Template->new( |
| 255 | | LOAD_TEMPLATES => [ |
| 256 | | Template::Provider::Encoding->new( |
| 257 | | ABSOLUTE => 1, |
| 258 | | INCLUDE_PATH => dir( $c->{config}->{global}->{assets_dir}, 'tmpl', $tmpl_dir, )->stringify, |
| 259 | | ) |
| 260 | | ], |
| 261 | | ); |
| 262 | | $tt->process("$name.html", $args, \my $out) |
| 263 | | or die $tt->error; |
| 264 | | |
| 265 | | DEBUG "rendering done"; |
| | 230 | sub make_response { |
| | 231 | my ( $c, $out ) = @_; |
| | 261 | sub render { |
| | 262 | my ( $c, $name, $args ) = @_; |
| | 263 | |
| | 264 | croak "invalid args : $args" unless ref $args eq 'HASH'; |
| | 265 | |
| | 266 | DEBUG "rendering template"; |
| | 267 | |
| | 268 | # set default vars |
| | 269 | $args = { |
| | 270 | docroot => $c->{config}->{httpd}->{root}, |
| | 271 | render_line => sub { render_line( $c, @_ ) }, |
| | 272 | user_agent => $c->{user_agent}, |
| | 273 | mobile_agent => $c->{mobile_agent}, |
| | 274 | title => $c->{config}->{httpd}->{title}, |
| | 275 | version => $App::Mobirc::VERSION, |
| | 276 | now => time(), |
| | 277 | |
| | 278 | %$args, |
| | 279 | }; |
| | 280 | |
| | 281 | my $tmpl_dir = $c->{mobile_agent}->is_non_mobile ? 'pc' : 'mobile'; |
| | 282 | DEBUG "tmpl_dir: $tmpl_dir"; |
| | 283 | |
| | 284 | my $tt = Template->new( |
| | 285 | LOAD_TEMPLATES => [ |
| | 286 | Template::Provider::Encoding->new( |
| | 287 | ABSOLUTE => 1, |
| | 288 | INCLUDE_PATH => dir( $c->{config}->{global}->{assets_dir}, 'tmpl', $tmpl_dir, )->stringify, |
| | 289 | ) |
| | 290 | ], |
| | 291 | ); |
| | 292 | $tt->process("$name.html", $args, \my $out) |
| | 293 | or die $tt->error; |
| | 294 | |
| | 295 | DEBUG "rendering done"; |
| | 296 | |
| | 297 | return make_response($c, $out); |
| | 298 | } |
| | 299 | |