Changeset 190

Show
Ignore:
Timestamp:
03/26/07 19:24:24 (1 year ago)
Author:
ingy
Message:
 r3675@skinny:  ingy | 2007-03-23 19:49:22 -0700
 Make Spoon::Template rely on Paths module.
 
 Start really fleshing out the Paths module.
Files:

Legend:

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

    r178 r190  
    4949 
    5050sub add_plugins_files { 
    51     for my $file ($self->hub->paths->all_filepaths('plugins')) { 
     51    for my $file ($self->hub->paths->all_files('plugins')) { 
    5252        $self->config->add_plugins_file($file); 
    5353    } 
  • trunk/src/core/Kwiki/lib/Kwiki/Command/V2.pm

    r178 r190  
    2323 
    2424sub create_database { 
    25     my @source_dirs = $self->hub->paths->all_filepaths('database'); 
     25    my @source_dirs = $self->hub->paths->all_files('database'); 
    2626    my $target_path = $ENV{KWIKI_DATABASE_LOCATION} or return; 
    2727    my $target = io($target_path); 
  • trunk/src/core/Kwiki/lib/Kwiki/Paths/V1.pm

    r178 r190  
    11package Kwiki::Paths::V1; 
    2 use Kwiki::Base -Base; 
     2use Kwiki::Paths -Base; 
    33use Cwd qw(cwd abs_path); 
    44 
     5sub path_values_init { 
     6    my $values = {}; 
     7    $values->{template} =  
     8        $self->hub->config->{template_path} || 
     9        [ './template/tt2' ]; 
     10    return $values; 
     11} 
     12 
    513# All directories in the config chain (starting at root). 
    6 sub all_paths
     14sub lookup_chain_init
    715    my $dir = cwd(); 
    8     my @paths = ($dir)
     16    my $paths = [$dir]
    917    while (1) { 
    1018        my $updir = abs_path("$dir/..") or last; 
     
    1220        $dir = $updir; 
    1321        last unless -e "$dir/config.yaml"; 
    14         unshift @paths, $dir; 
     22        last unless -e "$dir/plugins"; 
     23        unshift @$paths, $dir; 
     24        last unless io('plugins')->all =~ /^[+-]/m; 
    1525    } 
    16     return @paths; 
     26    return $paths; 
    1727} 
    1828 
    1929# All filepaths in the chain ending with the given file 
    20 sub all_filepaths { 
     30sub all_files { 
    2131    my $file = shift; 
    2232    return ('./config') if $file eq 'config'; 
    23  
    24     return grep { -e } map "$_/$file", $self->all_paths; 
     33    return grep { -e } map "$_/$file", @{$self->lookup_chain}; 
    2534} 
    2635 
    27 # First filepath in the chain ending with the given file 
    28 sub first_filepath { 
    29     return scalar $self->all_paths(shift); 
    30 } 
  • trunk/src/core/Kwiki/lib/Kwiki/Paths/V2.pm

    r178 r190  
    11package Kwiki::Paths::V2; 
    2 use Kwiki::Base -Base; 
     2use Kwiki::Paths -Base; 
    33use Cwd qw(cwd abs_path); 
    44 
    55field 'all_paths_cache'; 
    66 
     7sub path_values_init { 
     8    my $values = {}; 
     9 
     10    return $values; 
     11} 
     12 
    713# All directories in the config chain (starting at root). 
    8 sub all_paths
     14sub lookup_chain_init
    915    my $paths; 
    10 #     delete $self->{all_paths_cache} if @_; 
    11 #     $paths = $self->all_paths_cache; 
    12 #     return @$paths if ref $paths; 
    1316    $paths = []; 
    14 #     $self->all_paths_cache($paths); 
    1517    my $seen = {}; 
    1618     
     
    4042    } 
    4143 
    42     return @$paths; 
     44    return $paths; 
    4345} 
    44  
    45 # All filepaths in the chain ending with the given file 
    46 sub all_filepaths { 
    47     my $file = shift; 
    48     return grep { -e $_ } map "$_/$file", $self->all_paths(@_); 
    49 } 
    50  
    51 # First filepath in the chain ending with the given file 
    52 sub first_filepath { 
    53     my @all = $self->all_paths(@_); 
    54     return $all[-1]; 
    55 } 
  • trunk/src/core/Spoon/lib/Spoon/Base.pm

    r136 r190  
    160160} 
    161161 
     162sub utf8_upgrade { 
     163    my @list = map pack('U*', unpack 'U0U*', $_), @_; 
     164    return wantarray ? @list : $list[0]; 
     165} 
     166 
    162167sub uri_escape { 
    163168    require CGI::Util; 
  • trunk/src/core/Spoon/lib/Spoon/Config.pm

    r178 r190  
    1111sub add_file { 
    1212    my $file = shift; 
    13     for my $dir ($self->hub->paths->all_filepaths('config')) { 
     13    for my $dir ($self->hub->paths->all_files('config')) { 
    1414        my $filepath = "$dir/$file"; 
    1515        $self->add_config($filepath, @_) 
  • trunk/src/core/Spoon/lib/Spoon/Template.pm

    r182 r190  
    11package Spoon::Template; 
    22use Spoon::Base -Base, 'conf'; 
    3 # use Spoon::Base 'conf'; 
    43use Template; 
    54 
    65const class_id => 'template'; 
    7 const template_path => [ './template' ]; 
    8 field path => []; 
    9 field config => -init => '$self->hub->config'; 
    10 field cgi => -init => '$self->hub->cgi'; 
    11 field template_object => 
    12       -init => '$self->create_template_object'; 
    13 conf template_path => [ './template/tt2' ]; 
    146 
    15 sub init { 
    16     $self->add_path(@{$self->template_path}); 
    17 
     7field template_object => -init => '$self->create_template_object'; 
     8 
     9# These 3 methods have been deprecated and now are just delegating. 
     10sub add_path    { $self->hub->paths->add_path(template => @_) } 
     11sub append_path { $self->hub->paths->append_path(template => @_) } 
     12sub remove_path { $self->hub->paths->remove_path(template => @_) } 
    1813 
    1914sub all { 
    2015    return (  
    21         $self->config->all, 
    22         $self->is_in_cgi ? ($self->cgi->all) : (), 
     16        $self->hub->config->all, 
     17        $self->is_in_cgi ? ($self->hub->cgi->all) : (), 
    2318        hub => $self->hub, 
    2419    ); 
    25 } 
    26  
    27 sub add_path { 
    28     for (reverse @_) { 
    29         $self->remove_path($_); 
    30         unshift @{$self->path}, $_; 
    31     } 
    32 } 
    33  
    34 sub append_path { 
    35     for (@_) { 
    36         $self->remove_path($_); 
    37         push @{$self->path}, $_; 
    38     } 
    39 } 
    40  
    41 sub remove_path { 
    42     my $path = shift; 
    43     $self->path([grep {$_ ne $path} @{$self->path}]); 
    4420} 
    4521 
     
    5228        $self->render($_, $self->all, @_) 
    5329    } @templates; 
    54 } 
    55  
    56 sub compile_dir { 
    57     my $dir = $self->plugin_directory . '/ttc'; 
    58     mkdir $dir unless -d $dir; 
    59     return $dir; 
    60 } 
    61          
    62 sub 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     }); 
    7530} 
    7631 
     
    8742} 
    8843 
     44sub create_template_object { 
     45    require Template; 
     46    # XXX Make template caching a configurable option 
     47    Template->new({ 
     48        LOAD_TEMPLATES => [ 
     49            Kwiki::Template::TT2::UTF8::Provider->new({ 
     50                INCLUDE_PATH => $self->hub->paths->get_path('template'), 
     51            })], 
     52        # INCLUDE_PATH => $self->path, 
     53        TOLERANT => 0, 
     54        COMPILE_DIR => $self->compile_dir, 
     55        COMPILE_EXT => '.ttc', 
     56    }); 
     57} 
     58 
     59sub compile_dir { 
     60    my $dir = $self->plugin_directory . '/ttc'; 
     61    mkdir $dir unless -d $dir; 
     62    return $dir; 
     63} 
     64 
    8965package Kwiki::Template::TT2::UTF8::Provider; 
    9066use base 'Template::Provider'; 
    91  
    92 sub utf8_upgrade { 
    93     my @list = map pack('U*', unpack 'U0U*', $_), @_; 
    94     return wantarray ? @list : $list[0]; 
    95 
     67use Spoon::Base -Base; 
    9668 
    9769sub _load { 
  • trunk/src/core/modules.mk

    r184 r190  
    5858        Kwiki/Pages.pm \ 
    5959        Kwiki/Pane.pm \ 
     60        Kwiki/Paths.pm \ 
    6061        Kwiki/Plugin.pm \ 
    6162        Kwiki/Preferences.pm \