Changeset 190
- Timestamp:
- 03/26/07 19:24:24 (1 year ago)
- Files:
-
- trunk/lib/Kwiki/Paths.pm (added)
- trunk/src/core/Kwiki/lib/Kwiki/Boot/Base.pm (modified) (1 diff)
- trunk/src/core/Kwiki/lib/Kwiki/Command/V2.pm (modified) (1 diff)
- trunk/src/core/Kwiki/lib/Kwiki/Paths.pm (added)
- trunk/src/core/Kwiki/lib/Kwiki/Paths/V1.pm (modified) (2 diffs)
- trunk/src/core/Kwiki/lib/Kwiki/Paths/V2.pm (modified) (2 diffs)
- trunk/src/core/Spoon/lib/Spoon/Base.pm (modified) (1 diff)
- trunk/src/core/Spoon/lib/Spoon/Config.pm (modified) (1 diff)
- trunk/src/core/Spoon/lib/Spoon/Template.pm (modified) (3 diffs)
- trunk/src/core/modules.mk (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/core/Kwiki/lib/Kwiki/Boot/Base.pm
r178 r190 49 49 50 50 sub add_plugins_files { 51 for my $file ($self->hub->paths->all_file paths('plugins')) {51 for my $file ($self->hub->paths->all_files('plugins')) { 52 52 $self->config->add_plugins_file($file); 53 53 } trunk/src/core/Kwiki/lib/Kwiki/Command/V2.pm
r178 r190 23 23 24 24 sub create_database { 25 my @source_dirs = $self->hub->paths->all_file paths('database');25 my @source_dirs = $self->hub->paths->all_files('database'); 26 26 my $target_path = $ENV{KWIKI_DATABASE_LOCATION} or return; 27 27 my $target = io($target_path); trunk/src/core/Kwiki/lib/Kwiki/Paths/V1.pm
r178 r190 1 1 package Kwiki::Paths::V1; 2 use Kwiki:: Base-Base;2 use Kwiki::Paths -Base; 3 3 use Cwd qw(cwd abs_path); 4 4 5 sub path_values_init { 6 my $values = {}; 7 $values->{template} = 8 $self->hub->config->{template_path} || 9 [ './template/tt2' ]; 10 return $values; 11 } 12 5 13 # All directories in the config chain (starting at root). 6 sub all_paths{14 sub lookup_chain_init { 7 15 my $dir = cwd(); 8 my @paths = ($dir);16 my $paths = [$dir]; 9 17 while (1) { 10 18 my $updir = abs_path("$dir/..") or last; … … 12 20 $dir = $updir; 13 21 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; 15 25 } 16 return @paths;26 return $paths; 17 27 } 18 28 19 29 # All filepaths in the chain ending with the given file 20 sub all_file paths {30 sub all_files { 21 31 my $file = shift; 22 32 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}; 25 34 } 26 35 27 # First filepath in the chain ending with the given file28 sub first_filepath {29 return scalar $self->all_paths(shift);30 }trunk/src/core/Kwiki/lib/Kwiki/Paths/V2.pm
r178 r190 1 1 package Kwiki::Paths::V2; 2 use Kwiki:: Base-Base;2 use Kwiki::Paths -Base; 3 3 use Cwd qw(cwd abs_path); 4 4 5 5 field 'all_paths_cache'; 6 6 7 sub path_values_init { 8 my $values = {}; 9 10 return $values; 11 } 12 7 13 # All directories in the config chain (starting at root). 8 sub all_paths{14 sub lookup_chain_init { 9 15 my $paths; 10 # delete $self->{all_paths_cache} if @_;11 # $paths = $self->all_paths_cache;12 # return @$paths if ref $paths;13 16 $paths = []; 14 # $self->all_paths_cache($paths);15 17 my $seen = {}; 16 18 … … 40 42 } 41 43 42 return @$paths;44 return $paths; 43 45 } 44 45 # All filepaths in the chain ending with the given file46 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 file52 sub first_filepath {53 my @all = $self->all_paths(@_);54 return $all[-1];55 }trunk/src/core/Spoon/lib/Spoon/Base.pm
r136 r190 160 160 } 161 161 162 sub utf8_upgrade { 163 my @list = map pack('U*', unpack 'U0U*', $_), @_; 164 return wantarray ? @list : $list[0]; 165 } 166 162 167 sub uri_escape { 163 168 require CGI::Util; trunk/src/core/Spoon/lib/Spoon/Config.pm
r178 r190 11 11 sub add_file { 12 12 my $file = shift; 13 for my $dir ($self->hub->paths->all_file paths('config')) {13 for my $dir ($self->hub->paths->all_files('config')) { 14 14 my $filepath = "$dir/$file"; 15 15 $self->add_config($filepath, @_) trunk/src/core/Spoon/lib/Spoon/Template.pm
r182 r190 1 1 package Spoon::Template; 2 2 use Spoon::Base -Base, 'conf'; 3 # use Spoon::Base 'conf';4 3 use Template; 5 4 6 5 const 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' ];14 6 15 sub init { 16 $self->add_path(@{$self->template_path}); 17 } 7 field template_object => -init => '$self->create_template_object'; 8 9 # These 3 methods have been deprecated and now are just delegating. 10 sub add_path { $self->hub->paths->add_path(template => @_) } 11 sub append_path { $self->hub->paths->append_path(template => @_) } 12 sub remove_path { $self->hub->paths->remove_path(template => @_) } 18 13 19 14 sub all { 20 15 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) : (), 23 18 hub => $self->hub, 24 19 ); 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}]);44 20 } 45 21 … … 52 28 $self->render($_, $self->all, @_) 53 29 } @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 option65 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 30 } 76 31 … … 87 42 } 88 43 44 sub 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 59 sub compile_dir { 60 my $dir = $self->plugin_directory . '/ttc'; 61 mkdir $dir unless -d $dir; 62 return $dir; 63 } 64 89 65 package Kwiki::Template::TT2::UTF8::Provider; 90 66 use base 'Template::Provider'; 91 92 sub utf8_upgrade { 93 my @list = map pack('U*', unpack 'U0U*', $_), @_; 94 return wantarray ? @list : $list[0]; 95 } 67 use Spoon::Base -Base; 96 68 97 69 sub _load { trunk/src/core/modules.mk
r184 r190 58 58 Kwiki/Pages.pm \ 59 59 Kwiki/Pane.pm \ 60 Kwiki/Paths.pm \ 60 61 Kwiki/Plugin.pm \ 61 62 Kwiki/Preferences.pm \
