]> git.deb.at Git - pkg/blosxom.git/commitdiff
Add hash/hashref interpolation support to blosxom.cgi, and tests.
authorGavin Carr <gonzai@users.sourceforge.net>
Fri, 19 Oct 2007 10:19:16 +0000 (10:19 +0000)
committerGavin Carr <gonzai@users.sourceforge.net>
Fri, 19 Oct 2007 10:19:16 +0000 (10:19 +0000)
ChangeLog
blosxom.cgi
t/driver_tests
t/interpolate/config/blosxom.conf [new file with mode: 0644]
t/interpolate/data/content_type.html [new file with mode: 0644]
t/interpolate/data/date.html [new file with mode: 0644]
t/interpolate/data/foot.html [new file with mode: 0644]
t/interpolate/data/head.html [new file with mode: 0644]
t/interpolate/data/story.html [new file with mode: 0644]
t/interpolate/expected.html [new file with mode: 0644]
t/interpolate/spec.yaml [new file with mode: 0644]

index faae1fd53d39ab3a256738c279970aba00d39d80..d6140538f747a9ff32d101157efd54f97ae0709a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
 v2.0.3
+    * added initial blosxom.spec and supporting files in rpm directory
     * added support for multiple plugin directories using $plugin_path
        * changed plugin loading to use @INC instead of hardcoded 
          $plugin_dir
index 638830fe39a4a966c9c59902d44699b9c9097375..4e19e64a27e20e423427d02a3fdf93045d616553 100755 (executable)
@@ -510,10 +510,10 @@ sub generate {
 
     # Define default interpolation subroutine
     $interpolate = sub {
-
         package blosxom;
         my $template = shift;
-        $template =~ s/(\$\w+(?:::\w+)*)/"defined $1 ? $1 : ''"/gee;
+        # Interpolate scalars, namespaced scalars, and hash/hashref scalars
+        $template =~ s/(\$\w+(?:::\w+)*(?:(?:->)?{(['"]?)[-\w]+\2})?)/"defined $1 ? $1 : ''"/gee;
         return $template;
     };
 
index a053c509cdb753a904c5287b95ca19c54a8969c3..a7d2714734dcf2185aff8dd88cb87d635af5b525 100644 (file)
@@ -1,5 +1,6 @@
 01_templates.t
 02_smoketest.t
 03_permalinks.t
+03_interpolate.t
 04_plugin_dir.t
 04_plugin_list.t
diff --git a/t/interpolate/config/blosxom.conf b/t/interpolate/config/blosxom.conf
new file mode 100644 (file)
index 0000000..9daf90f
--- /dev/null
@@ -0,0 +1,29 @@
+$blog_title = 'Interpolation Testing';
+$blog_description = 'Terpolation Turpentine';
+$datadir = "$ENV{BLOSXOM_CONFIG_DIR}/../data";
+use vars qw(%hash $hashref $hash);
+%hash = (
+  abc => 123,
+  def => 456,
+  'X-Factor' => 789,
+);
+$hashref = {
+  abc => 123,
+  def => 456,
+  'X-Factor' => 789,
+};
+$Blosxom::Test::string = 'this is a test';
+%Blosxom::Test::hash = (
+  abc => 123,
+  def => 456,
+  'X-Factor' => 789,
+);
+$Blosxom::Test::hashref = {
+  abc => 123,
+  def => 456,
+  'X-Factor' => 789,
+};
+# Silence $hash warnings
+$hash = '';
+
+1;
diff --git a/t/interpolate/data/content_type.html b/t/interpolate/data/content_type.html
new file mode 100644 (file)
index 0000000..e81f92a
--- /dev/null
@@ -0,0 +1 @@
+text/xhtml; charset=UTF-8
diff --git a/t/interpolate/data/date.html b/t/interpolate/data/date.html
new file mode 100644 (file)
index 0000000..2cdf76d
--- /dev/null
@@ -0,0 +1 @@
+        <h3>$yr-$mo_num-$da</h3>
diff --git a/t/interpolate/data/foot.html b/t/interpolate/data/foot.html
new file mode 100644 (file)
index 0000000..308b1d0
--- /dev/null
@@ -0,0 +1,2 @@
+</body>
+</html>
diff --git a/t/interpolate/data/head.html b/t/interpolate/data/head.html
new file mode 100644 (file)
index 0000000..3984681
--- /dev/null
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+</head>
+<body>
+<pre>
+# Basic scalars
+title: $blog_title
+description: $blosxom::blog_description
+# Namespaced scalars
+Blosxom::Test::string: $Blosxom::Test::string
+# Hash values
+hash{abc}: $hash{abc}
+hash{'X-Factor'}: $hash{'X-Factor'}
+blosxom::hash{def}: $blosxom::hash{def}
+blosxom::hash{"X-Factor"}: $blosxom::hash{"X-Factor"}
+hashref->{abc}: $hashref->{abc}
+blosxom::hashref->{def}: $blosxom::hashref->{def}
+Blosxom::Test::hash{abc}: $Blosxom::Test::hash{abc}
+Blosxom::Test::hash{'X-Factor'}: $Blosxom::Test::hash{'X-Factor'}
+Blosxom::Test::hashref->{def}: $Blosxom::Test::hashref->{def}
+Blosxom::Test::hashref->{"X-Factor"}: $Blosxom::Test::hashref->{"X-Factor"}
+# Bad quoting with hash values
+hash{'X-Factor}: $hash{'X-Factor}
+hash{X-Factor'}: $hash{X-Factor'}
+hash{"X-Factor'}: $hash{"X-Factor'}
+</pre>
diff --git a/t/interpolate/data/story.html b/t/interpolate/data/story.html
new file mode 100644 (file)
index 0000000..7f3d068
--- /dev/null
@@ -0,0 +1,3 @@
+        <h4><a name="$fn">$title</a></h4>
+        <div>$body</div>
+        <p>posted at: $ti | path: <a href="$url$path">$path </a> | <a href="$url/$yr/$mo_num/$da#$fn">permanent link to this entry</a></p>
diff --git a/t/interpolate/expected.html b/t/interpolate/expected.html
new file mode 100644 (file)
index 0000000..f9c8598
--- /dev/null
@@ -0,0 +1,32 @@
+Content-Type: text/xhtml; charset=UTF-8\r
+\r
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+</head>
+<body>
+<pre>
+# Basic scalars
+title: Interpolation Testing
+description: Terpolation Turpentine
+# Namespaced scalars
+Blosxom::Test::string: this is a test
+# Hash values
+hash{abc}: 123
+hash{'X-Factor'}: 789
+blosxom::hash{def}: 456
+blosxom::hash{"X-Factor"}: 789
+hashref->{abc}: 123
+blosxom::hashref->{def}: 456
+Blosxom::Test::hash{abc}: 123
+Blosxom::Test::hash{'X-Factor'}: 789
+Blosxom::Test::hashref->{def}: 456
+Blosxom::Test::hashref->{"X-Factor"}: 789
+# Bad quoting with hash values
+hash{'X-Factor}: {'X-Factor}
+hash{X-Factor'}: {X-Factor'}
+hash{"X-Factor'}: {"X-Factor'}
+</pre>
+</body>
+</html>
diff --git a/t/interpolate/spec.yaml b/t/interpolate/spec.yaml
new file mode 100644 (file)
index 0000000..93883d3
--- /dev/null
@@ -0,0 +1,4 @@
+tests:
+  - 
+    - ""
+    - expected.html