Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix tags update when server_root is set
November::Tags.new() now takes a config param, instead of always
creating its own new Config object.
  • Loading branch information
softmoth committed Jul 9, 2011
1 parent e68e5b0 commit 4d3f6b5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
10 changes: 5 additions & 5 deletions lib/November.pm
Expand Up @@ -60,7 +60,7 @@ class November does November::Session does November::Cache {
}

# TODO: we need plugin system (see topics in mail-list)
my $t = November::Tags.new;
my $t = November::Tags.new(:$.config);

my $title = $page.trans( ['_'] => [' '] );

Expand Down Expand Up @@ -127,15 +127,15 @@ class November does November::Session does November::Cache {
self.remove-cache-entry( $page );

# TODO: we need plugin system (see topics in mail-list)
my $t = November::Tags.new();
my $t = November::Tags.new(:$.config);
$t.update_tags($page, $tags);

$.cgi.redirect('/view/' ~ $page );
return;
}

# TODO: we need plugin system (see topics in mail-list)
my $t = November::Tags.new;
my $t = November::Tags.new(:$.config);
self.response( 'edit.tmpl',
{
PAGE => $page,
Expand All @@ -160,7 +160,7 @@ class November does November::Session does November::Cache {
);

# Should really use the $tags parameter here, this will do for now...
#my $t = November::Tags.new();
#my $t = November::Tags.new(:$.config);
#my $tags = $t.tags_parse( $tags );

self.response( 'edit.tmpl',
Expand Down Expand Up @@ -341,7 +341,7 @@ class November does November::Session does November::Cache {

method list_all_pages {

my $t = November::Tags.new();
my $t = November::Tags.new(:$.config);
my %params;
%params<TAGS> = $t.all_tags if $t;

Expand Down
14 changes: 9 additions & 5 deletions lib/November/Tags.pm
Expand Up @@ -3,11 +3,15 @@ use v6;
use November::Config;

class November::Tags {
my $server_root = November::Config.new.server_root;
# TODO Nasty hack to enable testing to use different paths
has $.page_tags_path is rw = $server_root ~ 'data/page_tags/';
has $.tags_count_path is rw = $server_root ~ 'data/tags_count';
has $.tags_index_path is rw = $server_root ~ 'data/tags_index';
has $.page_tags_path is rw;
has $.tags_count_path is rw;
has $.tags_index_path is rw;

submethod BUILD(:$config = November::Config.new) {
$.page_tags_path = $config.server_root ~ 'data/page_tags/';
$.tags_count_path = $config.server_root ~ 'data/tags_count';
$.tags_index_path = $config.server_root ~ 'data/tags_index';
}

method update_tags($_: Str $page, Str $new_tags) {
my $old_tags = .read_page_tags($page).chomp;
Expand Down
8 changes: 6 additions & 2 deletions t/tags/norm_counts.t
Expand Up @@ -5,15 +5,19 @@ plan 3;

use November::Tags;

use November::Config;
my $config = November::Config.new(
server_root => 't/tags/',
);

role Testing {
method clear {
my $c = {};
self.write_tags_count( $c );
}
}

my $t = November::Tags.new does Testing;
$t.tags_count_path = 't/tags/data/tags_count';
my $t = November::Tags.new(:$config) does Testing;
$t.clear;

is( ($t.norm_counts).perl, '{}', 'With empty tags_count norm_counts produce empty Hash' );
Expand Down
7 changes: 6 additions & 1 deletion t/tags/update_tags.t
Expand Up @@ -5,6 +5,11 @@ plan 8;

use November::Tags;

use November::Config;
my $config = November::Config.new(
server_root => 't/tags/',
);

role Testing {
method clear ($_:) {
my $c = {};
Expand All @@ -15,7 +20,7 @@ role Testing {
}
}

my $t = November::Tags.new does Testing;
my $t = November::Tags.new(:$config) does Testing;
$t.page_tags_path = 't/tags/data/page_tags/';
$t.tags_count_path = 't/tags/data/tags_count';
$t.tags_index_path = 't/tags/data/tags_index';
Expand Down

0 comments on commit 4d3f6b5

Please sign in to comment.