OSDN Git Service

abandoned web_root option
authormorimoto <morimoto@180c8125-5b33-4295-ad04-72a68a15b4cc>
Wed, 9 Jan 2008 18:49:17 +0000 (18:49 +0000)
committermorimoto <morimoto@180c8125-5b33-4295-ad04-72a68a15b4cc>
Wed, 9 Jan 2008 18:49:17 +0000 (18:49 +0000)
now template_dir works as search path

lib/Keitairc/View.pm

index 2e5fd03..fd7f7c3 100644 (file)
@@ -1,6 +1,6 @@
 # -*-perl-*-
 # Keitairc::View
-# $Id: View.pm,v 1.1 2008-01-08 05:52:14 morimoto Exp $
+# $Id: View.pm,v 1.2 2008-01-09 18:49:17 morimoto Exp $
 # $Source: /home/ishikawa/work/keitairc/tmp/keitairc/lib/Keitairc/View.pm,v $
 #
 # Copyright (c) 2008 Jun Morimoto <morimoto@mrmt.net>
@@ -33,11 +33,9 @@ sub redirect{
        my $me = shift;
        my $path = shift;
 
-       $path =~ s|^/+||;
        $path = sprintf('http://%s:%d%s%s',
                        $me->{Config}->web_host(),
                        $me->{Config}->web_port(),
-                       $me->{Config}->web_root(),
                        $path);
        ::log_debug("path [$path]");
        my $response = HTTP::Response->new(302);
@@ -46,16 +44,25 @@ sub redirect{
 }
 
 ################################################################
+sub template_path{
+       my $me = shift;
+       my $template = shift;
+       for my $template_dir (split(':', $me->{Config}->template_dir())){
+               if(-r "$template_dir/$template"){
+                       return "$template_dir/$template";
+               }
+       }
+}
+
+################################################################
 sub render{
        my $me = shift;
        my $template = shift;
        my $vars = shift;
-
        my $t = new HTML::Template(
-               filename => $me->{Config}->template_dir() . '/' . $template,
+               filename => $me->template_path($template),
                die_on_bad_params => 0,
                cache => 1);
-       $t->param(web_root => $me->{Config}->web_root());
        $t->param(title => $me->{Config}->web_title());
        $t->param(version => $me->{Config}->version());
        $t->param(viewport => $me->{ClientInfo}->is_ipod());