if the link ends with /, add "index.html" (or cfg) when making the file
authorTony Cook <tony@develop-help.com>
Wed, 21 Sep 2011 01:41:52 +0000 (11:41 +1000)
committerTony Cook <tony@develop-help.com>
Wed, 21 Sep 2011 01:41:52 +0000 (11:41 +1000)
Note: link can only end with / by manually editing the db

MANIFEST
site/cgi-bin/modules/Article.pm
site/docs/config.pod
t/t16article.t [new file with mode: 0644]

index 33818fe..00f4a70 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -821,6 +821,7 @@ t/t12cat.t
 t/t13parent.t
 t/t13steps.t
 t/t15api.t
+t/t16article.t
 t/t20gen.t
 t/t21gencat.t                  Tests catalog generation
 t/t30rules.t                   Check for use strict and warnings
index 2a13f3a..9813a82 100644 (file)
@@ -8,7 +8,7 @@ use vars qw/@ISA/;
 @ISA = qw/Squirrel::Row BSE::TB::SiteCommon BSE::TB::TagOwner/;
 use Carp 'confess';
 
-our $VERSION = "1.006";
+our $VERSION = "1.007";
 
 sub columns {
   return qw/id parentid displayOrder title titleImage body
@@ -145,9 +145,14 @@ sub link_to_filename {
   length $link or return;
 
   my $filename = $link;
-  $filename =~ s!/\w*$!!;
+
+  # remove any appended title,
+  $filename =~ s!(.)/\w+$!$1!;
   $filename =~ s{^\w+://[\w.-]+(?::\d+)?}{};
   $filename = $cfg->content_base_path() . $filename;
+  if ($filename =~ m(/$)) {
+    $filename .= $cfg->entry("basic", "index_file", "index.html");
+  }
   $filename =~ s!//+!/!;
   
   return $filename;
index d493745..e7057f3 100644 (file)
@@ -1,3 +1,4 @@
+
 =head1 NAME
 
 config.pod - documents BSE configuration file options
@@ -417,6 +418,11 @@ Default: 1.
 If set to 0, dynamic article iterators will no access control filter
 their results.  Default: 1.
 
+=item index_file
+
+The name of the file to generate for static articles when the link is
+terminated by "/".  Default: C<index.html>.
+
 =back
 
 =head2 [mail]
diff --git a/t/t16article.t b/t/t16article.t
new file mode 100644 (file)
index 0000000..9f65261
--- /dev/null
@@ -0,0 +1,92 @@
+#!perl -w
+use strict;
+use Test::More tests => 6;
+
+use_ok("Article");
+
+{
+  my $cfg = bless 
+    {
+     paths =>
+     {
+      base => "/test",
+      public_html => '$(base)/htdocs',
+     }
+    }, "Test::Cfg";
+
+  is(Article->link_to_filename($cfg, "/"), "/test/htdocs/index.html",
+     "check default link to /");
+  is(Article->link_to_filename($cfg, "/foo.html/test"), "/test/htdocs/foo.html",
+     "check default link to filename - trailing title");
+  is(Article->link_to_filename($cfg, "/test.html"), "/test/htdocs/test.html",
+     "check default link to filename - trailing filename");
+  is(Article->link_to_filename($cfg, "//test.html"), "/test/htdocs/test.html",
+     "check default link to filename - doubled /");
+}
+
+{
+  my $cfg = bless 
+    {
+     paths =>
+     {
+      base => "/test",
+      public_html => '$(base)/htdocs',
+     },
+     basic =>
+     {
+      index_file => "default.htm"
+     }
+    }, "Test::Cfg";
+  is(Article->link_to_filename($cfg, "/"), "/test/htdocs/default.htm",
+     "check cfg link to filename");
+}
+
+package Test::Cfg;
+
+sub entry {
+  my ($self, $section, $key, $def) = @_;
+
+  my $sect = $self->{$section}
+    or return $def;
+  exists $sect->{$key} or return $def;
+
+  return $sect->{$key};
+}
+
+sub entryIfVar {
+  my ($self, $section, $key, $def) = @_;
+
+  my $value = $self->entry($section, $key);
+  defined $value
+    or return $def;
+
+  return $self->entryVar($section, $key);
+}
+
+sub entryErr {
+  my ($self, $section, $key) = @_;
+
+  my $value = $self->entry($section, $key);
+  defined $value or die "Missing [$section].$key";
+
+  return $value;
+}
+
+sub entryVar {
+  my ($self, $section, $key, $depth) = @_;
+
+  $depth ||= 0;
+  $depth < 10
+    or die "Too many levels of variables getting $key from $section";
+  my $value = $self->entryErr($section, $key);
+  $value =~ s!\$\(([\w ]+)/([\w ]+)\)! $self->entryVar($1, $2, $depth+1) !eg;
+  $value =~ s!\$\(([\w ]+)\)! $self->entryVar($section, $1, $depth+1) !eg;
+
+  $value;
+}
+
+sub content_base_path {
+  my ($self) = @_;
+
+  return $self->entryVar("paths", "public_html");
+}