From: Gavin Carr Date: Fri, 19 Oct 2007 10:19:16 +0000 (+0000) Subject: Add hash/hashref interpolation support to blosxom.cgi, and tests. X-Git-Tag: debian/2.1.2-2~62 X-Git-Url: https://git.deb.at/w?a=commitdiff_plain;h=e9efcd432994620d4294f322ff04152134a1c1f4;p=pkg%2Fblosxom.git Add hash/hashref interpolation support to blosxom.cgi, and tests. --- diff --git a/ChangeLog b/ChangeLog index faae1fd..d614053 100644 --- 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 diff --git a/blosxom.cgi b/blosxom.cgi index 638830f..4e19e64 100755 --- a/blosxom.cgi +++ b/blosxom.cgi @@ -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; }; diff --git a/t/driver_tests b/t/driver_tests index a053c50..a7d2714 100644 --- a/t/driver_tests +++ b/t/driver_tests @@ -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 index 0000000..9daf90f --- /dev/null +++ b/t/interpolate/config/blosxom.conf @@ -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 index 0000000..e81f92a --- /dev/null +++ b/t/interpolate/data/content_type.html @@ -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 index 0000000..2cdf76d --- /dev/null +++ b/t/interpolate/data/date.html @@ -0,0 +1 @@ +

$yr-$mo_num-$da

diff --git a/t/interpolate/data/foot.html b/t/interpolate/data/foot.html new file mode 100644 index 0000000..308b1d0 --- /dev/null +++ b/t/interpolate/data/foot.html @@ -0,0 +1,2 @@ + + diff --git a/t/interpolate/data/head.html b/t/interpolate/data/head.html new file mode 100644 index 0000000..3984681 --- /dev/null +++ b/t/interpolate/data/head.html @@ -0,0 +1,28 @@ + + + + + +
+# 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'}
+
diff --git a/t/interpolate/data/story.html b/t/interpolate/data/story.html new file mode 100644 index 0000000..7f3d068 --- /dev/null +++ b/t/interpolate/data/story.html @@ -0,0 +1,3 @@ +

$title

+
$body
+

posted at: $ti | path: $path | permanent link to this entry

diff --git a/t/interpolate/expected.html b/t/interpolate/expected.html new file mode 100644 index 0000000..f9c8598 --- /dev/null +++ b/t/interpolate/expected.html @@ -0,0 +1,32 @@ +Content-Type: text/xhtml; charset=UTF-8 + + + + + + +
+# 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'}
+
+ + diff --git a/t/interpolate/spec.yaml b/t/interpolate/spec.yaml new file mode 100644 index 0000000..93883d3 --- /dev/null +++ b/t/interpolate/spec.yaml @@ -0,0 +1,4 @@ +tests: + - + - "" + - expected.html