Author: dom
Date: 2007-06-20 17:34:42 +0100 (Wed, 20 Jun 2007)
New Revision: 1095
Modified:
trunk/lib/OpenGuides/Template.pm
trunk/t/51_display_node.t
trunk/templates/display_metadata.tt
Log:
Only linkify categories and locales if they exist (fixes #15)
Modified: trunk/lib/OpenGuides/Template.pm
===================================================================
--- trunk/lib/OpenGuides/Template.pm 2007-06-19 18:32:56 UTC (rev 1094)
+++ trunk/lib/OpenGuides/Template.pm 2007-06-20 16:34:42 UTC (rev 1095)
@@ -319,12 +319,12 @@
}
my @categories = map { { name => $_,
- url => "$script_name?Category_"
- . uri_escape($formatter->node_name_to_node_param($_)) } } @catlist;
+ url => $args{wiki}->node_exists(
"Category_" . $formatter->node_name_to_node_param($_)) ?
"$script_name?Category_"
+ . uri_escape($formatter->node_name_to_node_param($_)) : "" } }
@catlist;
my @locales = map { { name => $_,
- url => "$script_name?Locale_"
- . uri_escape($formatter->node_name_to_node_param($_)) } } @loclist;
+ url => $args{wiki}->node_exists( "Locale_"
. $formatter->node_name_to_node_param($_)) ? "$script_name?Locale_"
+ . uri_escape($formatter->node_name_to_node_param($_)) : "" } }
@loclist;
# The 'website' attribute might contain a URL so we wiki-format it here
# rather than just CGI::escapeHTMLing it all in the template.
Modified: trunk/t/51_display_node.t
===================================================================
--- trunk/t/51_display_node.t 2007-06-19 18:32:56 UTC (rev 1094)
+++ trunk/t/51_display_node.t 2007-06-20 16:34:42 UTC (rev 1095)
@@ -12,8 +12,9 @@
plan skip_all => "DBD::SQLite could not be used - no database to test with
($error)";
}
-plan tests => 9;
+plan tests => 13;
+Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
my $config = OpenGuides::Config->new(
vars => {
@@ -60,3 +61,37 @@
$output = $guide->display_node( id => 'Redirect Test', return_output =>
1, redirect => 0 );
unlike( $output, qr{^\QLocation: }ms, '...but not with redirect=0' );
+
+$wiki->write_node( "Non-existent categories and locales", "foo",
undef,
+ { category => [ "Does not exist" ],
+ locale => [ "Does not exist" ] } );
+
+$output = $guide->display_node( id => 'Non-existent categories and
locales',
+ return_output => 1
+ );
+
+unlike( $output, qr{\Q<a href="wiki.cgi?Category_Does_Not_Exist"},
+ 'Category name not linked if category does not exist' );
+
+$wiki->write_node( "Category_Does_Not_Exist", "bar", undef, undef
);
+
+$output = $guide->display_node( id => 'Non-existent categories and
locales',
+ return_output => 1
+ );
+
+like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Not_Exist"},
+ 'but does when it does exist' );
+
+unlike( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Not_Exist"},
+ 'Locale name not linked if category does not exist' );
+
+$wiki->write_node( "Locale_Does_Not_Exist", "wibble", undef, undef
);
+
+$output = $guide->display_node( id => 'Non-existent categories and
locales',
+ return_output => 1
+ );
+
+like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Not_Exist"},
+ 'but does when it does exist' );
+
+
Modified: trunk/templates/display_metadata.tt
===================================================================
--- trunk/templates/display_metadata.tt 2007-06-19 18:32:56 UTC (rev 1094)
+++ trunk/templates/display_metadata.tt 2007-06-20 16:34:42 UTC (rev 1095)
@@ -81,7 +81,11 @@
<li class="categories_list">
<span class="metadata_label">Categories:</span>
[% FOREACH category = categories %]
- <a href="[% category.url %]" class="category">[%
category.name %]</a>[%- "," UNLESS loop.last %]
+ [% IF category.url != "" %]
+ <a href="[% category.url %]" class="category">[%
category.name %]</a>[%- "," UNLESS loop.last %]
+ [% ELSE %]
+ [% category.name %][%- "," UNLESS loop.last %]
+ [% END %]
[% END %]
</li>
[% END %]
@@ -90,7 +94,11 @@
<li class="locales_list">
<span class="metadata_label">Locales:</span>
[% FOREACH locale = locales %]
- <a href="[% locale.url %]" class="addr locality">[%
locale.name %]</a>[%- "," UNLESS loop.last %]
+ [% IF locale.url != "" %]
+ <a href="[% locale.url %]" class="addr locality">[%
locale.name %]</a>[%- "," UNLESS loop.last %]
+ [% ELSE %]
+ [% locale.name %][%- "," UNLESS loop.last %]
+ [% END %]
[% END %]
</li>
[% END %]
Show replies by date