Changeset 172
- Timestamp:
- 02/23/07 15:51:49 (2 years ago)
- Files:
-
- trunk/lib/Kwiki/Boot/Base.pm (added)
- trunk/lib/Kwiki/Paths (added)
- trunk/lib/Kwiki/Paths/V1.pm (added)
- trunk/lib/Kwiki/Paths/V2.pm (added)
- trunk/src/core/Kwiki/lib/Kwiki/Boot.pm (modified) (1 diff)
- trunk/src/core/Kwiki/lib/Kwiki/Boot/Base.pm (added)
- trunk/src/core/Kwiki/lib/Kwiki/Boot/V1.pm (modified) (5 diffs)
- trunk/src/core/Kwiki/lib/Kwiki/Boot/V2.pm (modified) (5 diffs)
- trunk/src/core/Kwiki/lib/Kwiki/Command/V1.pm (modified) (1 diff)
- trunk/src/core/Kwiki/lib/Kwiki/Command/V2.pm (modified) (6 diffs)
- trunk/src/core/Kwiki/lib/Kwiki/Config.pm (modified) (2 diffs)
- trunk/src/core/Kwiki/lib/Kwiki/Paths (added)
- trunk/src/core/Kwiki/lib/Kwiki/Paths/V1.pm (added)
- trunk/src/core/Kwiki/lib/Kwiki/Paths/V2.pm (added)
- trunk/src/core/Spoon/lib/Spoon/Config.pm (modified) (4 diffs)
- trunk/src/core/modules.mk (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/core/Kwiki/lib/Kwiki/Boot.pm
r151 r172 1 1 package Kwiki::Boot; 2 2 use Kwiki::Base -Base; 3 4 field 'config';5 field 'kwiki';6 7 sub new {8 $self = $self->SUPER::new(@_);9 $self->init();10 return $self;11 }12 13 sub init {14 for my $type (qw(main config hub)) {15 my $method = "${type}_class";16 my $class = $self->$method;17 eval "use $class; 1" or die $@;18 }19 20 my $config = $self->config_class->new(@_);21 $self->config($config);22 23 my $hub = $self->hub_class->new;24 25 my $main = $self->main_class->new;26 $hub->main($main);27 $hub->config($config);28 29 $self->kwiki($main);30 }31 3 32 4 sub boot { trunk/src/core/Kwiki/lib/Kwiki/Boot/V1.pm
r160 r172 1 1 package Kwiki::Boot::V1; 2 use Kwiki::Boot -Base;2 use Kwiki::Boot::Base -Base; 3 3 4 4 const main_class => 'Kwiki'; … … 7 7 8 8 sub init { 9 $self->SUPER::init ('config*.*');9 $self->SUPER::init; 10 10 $self->add_default_classes; 11 11 $self->add_configs_files; … … 14 14 15 15 sub add_configs_files { 16 $self->config->add_path('config');17 16 $self->config->add_file('config.yaml'); 17 for my $filepath (glob 'config*.*') { 18 $self->config->add_filepath($filepath); 19 } 18 20 } 19 21 … … 23 25 24 26 sub add_default_classes { 25 my %default = (27 my $default = { 26 28 cgi_class => 'Kwiki::CGI', 27 29 command_class => 'Kwiki::Command::V1', 28 config_class => 'Kwiki::Config',29 30 cookie_class => 'Kwiki::Cookie', 30 31 css_class => 'Kwiki::CSS', … … 32 33 headers_class => 'Spoon::Headers', 33 34 hooks_class => 'Spoon::Hooks', 34 hub_class => 'Kwiki::Hub',35 35 javascript_class => 'Kwiki::Javascript', 36 36 pages_class => 'Kwiki::Pages', 37 paths_class => 'Kwiki::Paths::V1', 37 38 preferences_class => 'Kwiki::Preferences', 38 39 registry_class => 'Kwiki::Registry', 39 40 template_class => 'Kwiki::Template::TT2', 40 41 users_class => 'Kwiki::Users', 41 ); 42 while (my($key, $val) = each %default) { 43 unless (defined $self->config->{$key}) { 44 $self->config->add_config({ $key => $val }); 45 } 46 } 42 }; 43 $self->SUPER::add_default_classes($default); 47 44 } 48 trunk/src/core/Kwiki/lib/Kwiki/Boot/V2.pm
r160 r172 1 1 package Kwiki::Boot::V2; 2 use Kwiki::Boot -Base;2 use Kwiki::Boot::Base -Base; 3 3 4 4 const main_class => 'Kwiki'; … … 7 7 8 8 sub init { 9 $self->SUPER::init('config*.*');10 9 $self->add_default_classes; 11 10 $self->add_configs_files; … … 14 13 15 14 sub add_configs_files { 15 # TODO Get all config locations from hub->paths 16 16 $self->config->add_path('config'); 17 17 $self->config->add_file('config.yaml'); … … 19 19 20 20 sub add_plugins_files { 21 # TODO Get all plugins files from hub->paths 21 22 $self->config->add_plugins_file('plugins'); 22 23 } 23 24 24 25 sub add_default_classes { 25 my %default = (26 my $default = { 26 27 cgi_class => 'Kwiki::CGI', 27 28 command_class => 'Kwiki::Command::V2', 28 config_class => 'Kwiki::Config',29 29 cookie_class => 'Kwiki::Cookie', 30 30 css_class => 'Kwiki::CSS', … … 32 32 headers_class => 'Spoon::Headers', 33 33 hooks_class => 'Spoon::Hooks', 34 hub_class => 'Kwiki::Hub',35 34 javascript_class => 'Kwiki::Javascript', 36 35 pages_class => 'Kwiki::Pages', 36 paths_class => 'Kwiki::Paths::V2', 37 37 preferences_class => 'Kwiki::Preferences', 38 38 registry_class => 'Kwiki::Registry', 39 39 template_class => 'Kwiki::Template::TT2', 40 40 users_class => 'Kwiki::Users', 41 ); 42 while (my($key, $val) = each %default) { 43 unless (defined $self->config->{$key}) { 44 $self->config->add_config({ $key => $val }); 45 } 46 } 41 }; 42 $self->SUPER::add_default_classes($default); 47 43 } 48 trunk/src/core/Kwiki/lib/Kwiki/Command/V1.pm
r161 r172 50 50 # 51 51 # privacy_group: 52 END 52 53 53 54 $self->create_new_view_plugins; trunk/src/core/Kwiki/lib/Kwiki/Command/V2.pm
r161 r172 4 4 sub handle_new { 5 5 $self->assert_directory(shift, 'Kwiki'); 6 $self->update_kwiki_env_file; 7 $self->apply_kwiki_env_file; 8 $self->create_www_link; 6 9 $self->add_new_default_config; 7 10 $self->install('files'); 11 $self->create_database; 12 $self->create_plugin_scratch; 8 13 $self->set_permissions; 9 14 $self->finished_msg; 10 15 } 11 16 17 sub create_plugin_scratch { 18 $ENV{KWIKI_PLUGIN_SCRATCH_FILEPATH} or return; 19 my $plugin = io($ENV{KWIKI_PLUGIN_SCRATCH_FILEPATH}) or return; 20 $plugin->mkpath unless $plugin->exists; 21 } 22 23 sub create_database { 24 my $target = $ENV{KWIKI_DATABASE_FILEPATH} or return; 25 my $source = $self->hub->paths->find_first_filepath('database'); 26 unless (-d $target) { 27 mkdir $target or die; 28 } 29 system("cp $source/* $target") == 0 or die; 30 } 31 32 sub apply_kwiki_env_file { 33 my $env = $self->parse_env(io($self->kwiki_env_path)->all); 34 for my $k (keys %$env) { 35 next if defined $ENV{$k}; 36 $ENV{$k} = $env->{$k} if length($env->{$k}); 37 } 38 } 39 40 sub create_www_link { 41 my $flavor_path = $ENV{KWIKI_BASE} . '/flavor/' . $ENV{KWIKI_FLAVOR}; 42 die "No such directory '$flavor_path'" 43 unless -d $flavor_path and -d "$flavor_path/www"; 44 my $www = $ENV{KWIKI_WWW_FILEPATH} or die; 45 io->link("$www/__")->assert->symlink("$flavor_path/www"); 46 } 47 48 sub update_kwiki_env_file { 49 my $env_file = io($self->kwiki_env_path); 50 my $env_text = $env_file->exists 51 ? $env_file->all 52 : $self->default_kwiki_env; 53 my $env = $self->parse_env($env_text); 54 for my $k (keys %ENV) { 55 next unless exists $env->{$k}; 56 my $v = $ENV{$k}; 57 $v = '' unless defined $v; 58 $env_text =~ s/^$k=.*$/$k=$v/m; 59 } 60 $env_file->print($env_text); 61 } 62 63 sub kwiki_env_path { 64 for (qw(_kwiki .ht_kwiki)) { 65 return $_ if -e $_; 66 } 67 return '_kwiki'; 68 } 69 70 sub parse_env { 71 my $text = shift; 72 my $env = {}; 73 for (split /\n/, $text) { 74 $env->{$1} ||= $2 if /^(\w+)\s*=\s*['"]?(.*?)['"]?\s*$/; 75 } 76 return $env; 77 } 78 79 sub default_kwiki_env { 80 return <<'...'; 81 KWIKI_BOOT=V2 82 KWIKI_LIB_PATH=lib 83 KWIKI_BASE= 84 KWIKI_FLAVOR=Vanilla 85 KWIKI_TEST_CLEAN=0 86 KWIKI_PLUGIN_SCRATCH_FILEPATH=plugin 87 KWIKI_DATABASE_FILEPATH=database 88 KWIKI_WWW_FILEPATH=www 89 ... 90 } 91 12 92 sub handle_new_view { 93 die; 13 94 $self->assert_directory(shift, 'kwiki view'); 14 95 die "Parent directory does not look like a Kwiki installation" … … 34 115 # 35 116 # privacy_group: 117 END 36 118 37 119 $self->create_new_view_plugins; … … 60 142 $self->hub->config->add_config( 61 143 { 62 display_class => 'Kwiki::Display',63 edit_class => 'Kwiki::Edit',64 144 files_class => 'Kwiki::Files::V2', 65 theme_class => 'Kwiki::Theme::Basic',66 toolbar_class => 'Kwiki::Toolbar',67 status_class => 'Kwiki::Status',68 widgets_class => 'Kwiki::Widgets',69 145 } 70 146 ); … … 77 153 78 154 sub handle_update { 155 die; 79 156 chdir io->dir(shift || '.')->assert->open . ''; 80 157 die "Can't update non Kwiki directory!\n" … … 87 164 88 165 sub handle_update_all { 166 die; 89 167 my @dirs = (io->curdir, io->curdir->All_Dirs); 90 168 while (my $dir = shift @dirs) { … … 97 175 98 176 sub set_permissions { 177 my $database = $ENV{KWIKI_DATABASE_FILEPATH} or die; 178 my $plugin = $ENV{KWIKI_PLUGIN_SCRATCH_FILEPATH} or die; 99 179 my $umask = umask 0000; 100 chmod 0777, qw(database plugin);101 chmod 0666, qw(database/HomePage);180 chmod 0777, $database, $plugin; 181 chmod 0666, glob "$database/*"; 102 182 chmod 0755, qw(index.cgi); 103 183 umask $umask; trunk/src/core/Kwiki/lib/Kwiki/Config.pm
r138 r172 6 6 const class_title => 'Kwiki Configuration'; 7 7 field script_name => ''; 8 field path => [];9 8 10 9 sub add_plugins_file { … … 62 61 63 62 sub add_file { 64 my $file = shift 65 or return; 66 my $file_path = ''; 67 for (@{$self->path}) { 68 $file_path = "$_/$file", last 69 if -f "$_/$file"; 70 } 71 return unless $file_path; 72 my $hash = $self->hash_from_file($file_path); 63 my $file = shift; 64 my $config_path = $self->hub->paths->lookup_path('config'); 65 for my $dir (@$config_path) { 66 my $filepath = "$dir/$file"; 67 $self->add_filepath($filepath) 68 if -f $filepath; 69 } 70 } 71 72 sub add_filepath { 73 my $filepath = shift; 74 my $hash = $self->hash_from_file($filepath); 73 75 for my $key (keys %$hash) { 74 next if defined $self->{$key}; 75 field $key; 76 $self->{$key} = $hash->{$key}; 77 } 78 } 79 80 sub add_path { 81 splice @{$self->path}, 0, 0, @_; 76 $self->add_field($key, $hash->{$key}); 77 } 82 78 } 83 79 trunk/src/core/Spoon/lib/Spoon/Config.pm
r138 r172 3 3 4 4 const class_id => 'config'; 5 field plugin_classes => []; 5 6 6 7 sub all { … … 8 9 } 9 10 10 sub default_configs { return }11 12 sub new() {13 my $class = shift;14 my $self = bless {}, $class;15 my (@configs) = map {16 /\*/ ? (sort glob) : ($_)17 } @_ ? @_ : $self->default_configs;18 $self->add_config($self->default_config);19 for my $config (@configs) {20 $self->rebless($self->add_config($config));21 }22 $self->init;23 return $self;24 }25 26 11 sub add_field { 27 my ($field, $default) = @_; 28 field $field => $default; 12 my ($field, $value) = @_; 13 field $field; 14 $self->{$field} = $value; 29 15 } 30 16 … … 39 25 } 40 26 return $hash; 41 }42 43 sub rebless {44 my $hash = shift;45 if (defined (my $config_class = $hash->{config_class})) {46 eval qq{ require $config_class }; die $@ if $@;47 bless $self, $config_class;48 }49 27 } 50 28 … … 84 62 return $hash; 85 63 } 86 87 sub default_config {88 +{89 plugin_classes => [$self->default_plugin_classes],90 }91 }92 93 sub default_plugin_classes { () }trunk/src/core/modules.mk
r161 r172 7 7 Kwiki/Command \ 8 8 Kwiki/Files \ 9 Kwiki/Paths \ 9 10 Kwiki/Template \ 10 11 Kwiki/Theme \ … … 13 14 Spoon \ 14 15 Spoon/Template \ 16 Spork \ 17 Spork/Config \ 18 Spork/Formatter \ 19 Spork/Template \ 15 20 Template \ 16 21 Template/Namespace \ … … 30 35 Spiffy.pm \ 31 36 Spoon.pm \ 37 Spork.pm \ 32 38 Template.pm \ 33 39 YAML.pm \ … … 85 91 Spoon/Trace.pm \ 86 92 Spoon/Utils.pm \ 93 Spork/Command.pm \ 94 Spork/Config.pm \ 95 Spork/Formatter.pm \ 96 Spork/Hub.pm \ 97 Spork/Plugin.pm \ 98 Spork/Registry.pm \ 99 Spork/Slides.pm \ 87 100 Template/Base.pm \ 88 101 Template/Config.pm \ … … 127 140 IO/All/Temp.pm \ 128 141 Kwiki/Archive/Simple.pm \ 142 Kwiki/Boot/Base.pm \ 129 143 Kwiki/Boot/V1.pm \ 130 144 Kwiki/Boot/V2.pm \ … … 133 147 Kwiki/Files/V1.pm \ 134 148 Kwiki/Files/V2.pm \ 149 Kwiki/Paths/V1.pm \ 150 Kwiki/Paths/V2.pm \ 135 151 Kwiki/Template/TT2.pm \ 136 152 Kwiki/Theme/Basic.pm \ 137 153 Spoon/Template/TT2.pm \ 154 Spork/Config/Default.pm \ 155 Spork/Formatter/Autringy.pm \ 156 Spork/Template/TT2.pm \ 138 157 Template/Namespace/Constants.pm \ 139 158 Template/Plugin/Autoformat.pm \
