From e9efcd432994620d4294f322ff04152134a1c1f4 Mon Sep 17 00:00:00 2001 From: Gavin Carr Date: Fri, 19 Oct 2007 10:19:16 +0000 Subject: [PATCH] Add hash/hashref interpolation support to blosxom.cgi, and tests. --- ChangeLog | 1 + blosxom.cgi | 4 ++-- t/driver_tests | 1 + t/interpolate/config/blosxom.conf | 29 +++++++++++++++++++++++++ t/interpolate/data/content_type.html | 1 + t/interpolate/data/date.html | 1 + t/interpolate/data/foot.html | 2 ++ t/interpolate/data/head.html | 28 ++++++++++++++++++++++++ t/interpolate/data/story.html | 3 +++ t/interpolate/expected.html | 32 ++++++++++++++++++++++++++++ t/interpolate/spec.yaml | 4 ++++ 11 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 t/interpolate/config/blosxom.conf create mode 100644 t/interpolate/data/content_type.html create mode 100644 t/interpolate/data/date.html create mode 100644 t/interpolate/data/foot.html create mode 100644 t/interpolate/data/head.html create mode 100644 t/interpolate/data/story.html create mode 100644 t/interpolate/expected.html create mode 100644 t/interpolate/spec.yaml 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 -- 2.30.2