Changeset 182

Show
Ignore:
Timestamp:
03/08/07 10:16:57 (1 year ago)
Author:
ingy
Message:
 r3480@skinny:  ingy | 2007-03-08 10:09:39 -0800
 Put all the template modules into Spoon::Template.
 
 This simplifies things a lot. Kwiki is already basically married to
 Template Toolkit, so this is fine.
 
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/core/Kwiki/lib/Kwiki/Boot/V1.pm

    r178 r182  
    2727        preferences_class => 'Kwiki::Preferences', 
    2828        registry_class => 'Kwiki::Registry', 
    29         template_class => 'Kwiki::Template::TT2', 
     29        template_class => 'Spoon::Template', 
    3030        users_class => 'Kwiki::Users', 
    3131    }; 
  • trunk/src/core/Kwiki/lib/Kwiki/Boot/V2.pm

    r178 r182  
    2828        preferences_class => 'Kwiki::Preferences', 
    2929        registry_class => 'Kwiki::Registry', 
    30         template_class => 'Kwiki::Template::TT2', 
     30        template_class => 'Spoon::Template', 
    3131        users_class => 'Kwiki::Users', 
    3232    }; 
  • trunk/src/core/Spoon/lib/Spoon/Template.pm

    r87 r182  
    11package Spoon::Template; 
    2 use Spoon::Base -Base; 
     2use Spoon::Base -Base, 'conf'; 
     3# use Spoon::Base 'conf'; 
    34use Template; 
    45 
     
    67const template_path => [ './template' ]; 
    78field path => []; 
    8 stub 'render'; 
    99field config => -init => '$self->hub->config'; 
    1010field cgi => -init => '$self->hub->cgi'; 
     11field template_object => 
     12      -init => '$self->create_template_object'; 
     13conf template_path => [ './template/tt2' ]; 
    1114 
    1215sub init { 
     
    5053    } @templates; 
    5154} 
     55 
     56sub compile_dir { 
     57    my $dir = $self->plugin_directory . '/ttc'; 
     58    mkdir $dir unless -d $dir; 
     59    return $dir; 
     60} 
     61         
     62sub create_template_object { 
     63    require Template; 
     64    # XXX Make template caching a configurable option 
     65    Template->new({ 
     66        LOAD_TEMPLATES => [ 
     67            Kwiki::Template::TT2::UTF8::Provider->new({ 
     68                INCLUDE_PATH => $self->path, 
     69            })], 
     70        # INCLUDE_PATH => $self->path, 
     71        TOLERANT => 0, 
     72        COMPILE_DIR => $self->compile_dir, 
     73        COMPILE_EXT => '.ttc', 
     74    }); 
     75} 
     76 
     77sub render { 
     78    my $template = shift; 
     79 
     80    my $output; 
     81    my $t = $self->template_object; 
     82    eval { 
     83        $t->process($template, {@_}, \$output) or die $t->error; 
     84    }; 
     85    die "Template Toolkit error:\n$@" if $@; 
     86    return $output; 
     87} 
     88 
     89package Kwiki::Template::TT2::UTF8::Provider; 
     90use base 'Template::Provider'; 
     91 
     92sub utf8_upgrade { 
     93    my @list = map pack('U*', unpack 'U0U*', $_), @_; 
     94    return wantarray ? @list : $list[0]; 
     95} 
     96 
     97sub _load { 
     98    my ($data, $error) = $self->SUPER::_load(@_); 
     99    if (defined $data) { 
     100        $data->{text} = $self->utf8_upgrade($data->{text}); 
     101    } 
     102    return ($data, $error); 
     103}