Author: kake Date: 2012-08-17 17:24:05 +0100 (Fri, 17 Aug 2012) New Revision: 1434
Modified: trunk/Changes trunk/lib/OpenGuides/Utils.pm trunk/t/102_macros.t Log: Implemented new @INDEX_LIST_NO_PREFIX macro.
Modified: trunk/Changes =================================================================== --- trunk/Changes 2012-08-17 15:36:57 UTC (rev 1433) +++ trunk/Changes 2012-08-17 16:24:05 UTC (rev 1434) @@ -6,6 +6,7 @@ 0.70 ? Updated URLs for Leaflet JavaScript and CSS. Added meta descriptions to headers of map and list index pages. + Implemented new @INDEX_LIST_NO_PREFIX macro.
0.69 07 July 2012 The output of the "show_missing_metadata" action is now alphabetised.
Modified: trunk/lib/OpenGuides/Utils.pm =================================================================== --- trunk/lib/OpenGuides/Utils.pm 2012-08-17 15:36:57 UTC (rev 1433) +++ trunk/lib/OpenGuides/Utils.pm 2012-08-17 16:24:05 UTC (rev 1434) @@ -137,33 +137,16 @@ qr/@INDEX_LIST\s+[[(Category|Locale)\s+([^]]+)]]/ => sub { my ($wiki, $type, $value) = @_; - - # We may be being called by Wiki::Toolkit::Plugin::Diff, - # which doesn't know it has to pass us $wiki - unless ( UNIVERSAL::isa( $wiki, "Wiki::Toolkit" ) ) { - return "(unprocessed INDEX_LIST macro)"; - } - - my @nodes = sort $wiki->list_nodes_by_metadata( - metadata_type => $type, - metadata_value => $value, - ignore_case => 1, - ); - unless ( scalar @nodes ) { - return "\n* No pages currently in " - . lc($type) . " $value\n"; - } - my $return = "\n"; - foreach my $node ( @nodes ) { - $return .= "* " - . $wiki->formatter->format_link( - wiki => $wiki, - link => $node, - ) - . "\n"; - } - return $return; + return $class->do_index_list_macro( + wiki => $wiki, type => $type, value => $value, + include_prefix => 1 ); }, + qr/@INDEX_LIST_NO_PREFIX\s+[[(Category|Locale)\s+([^]]+)]]/ => + sub { + my ($wiki, $type, $value) = @_; + return $class->do_index_list_macro( + wiki => $wiki, type => $type, value => $value ); + }, qr/@MAP_LINK\s+[[(Category|Locale)\s+([^]|]+)|?([^]]+)?]]/ => sub { if ( UNIVERSAL::isa( $_[0], "Wiki::Toolkit" ) ) { @@ -263,6 +246,41 @@ return $wiki; }
+sub do_index_list_macro { + my ( $class, %args ) = @_; + my ( $wiki, $type, $value, $include_prefix ) + = @args{ qw( wiki type value include_prefix ) }; + + # We may be being called by Wiki::Toolkit::Plugin::Diff, + # which doesn't know it has to pass us $wiki + if ( !UNIVERSAL::isa( $wiki, "Wiki::Toolkit" ) ) { + if ( $args{include_prefix} ) { + return "(unprocessed INDEX_LIST macro)"; + } else { + return "(unprocessed INDEX_LIST_NO_PREFIX macro)"; + } + } + + my @nodes = sort $wiki->list_nodes_by_metadata( + metadata_type => $type, + metadata_value => $value, + ignore_case => 1, + ); + unless ( scalar @nodes ) { + return "\n* No pages currently in " . lc($type) . " $value\n"; + } + my $return = "\n"; + foreach my $node ( @nodes ) { + my $title = $node; + $title =~ s/^(Category|Locale) // unless $args{include_prefix}; + $return .= "* " + . $wiki->formatter->format_link( wiki => $wiki, + link => "$node|$title" ) + . "\n"; + } + return $return; +} + =item B<get_wgs84_coords>
Returns coordinate data suitable for use with Google Maps (and other GIS
Modified: trunk/t/102_macros.t =================================================================== --- trunk/t/102_macros.t 2012-08-17 15:36:57 UTC (rev 1433) +++ trunk/t/102_macros.t 2012-08-17 16:24:05 UTC (rev 1434) @@ -11,7 +11,7 @@ plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; }
-plan tests => 19; +plan tests => 27;
SKIP: { # Clear out the database from any previous runs. @@ -22,35 +22,42 @@ my $wiki = $guide->wiki;
# Test @INDEX_LINK - $wiki->write_node( "Test 1", "@INDEX_LINK [[Category Foo]]" ) + $wiki->write_node( "Category Alpha", "@INDEX_LINK [[Category Alpha]]", + undef, { category => "category" } ) or die "Can't write node"; - $wiki->write_node( "Test 2", "@INDEX_LINK [[Category Bar|Bars]]" ) + + $wiki->write_node( "Category Beta", "@INDEX_LINK [[Category Beta|Betas]]", + undef, { category => "category" } ) or die "Can't write node";
my $output; $output = $guide->display_node( return_output => 1, - id => "Test 1", + id => "Category Alpha", ); - like( $output, qr/View all pages in Category Foo/, + like( $output, qr/View all pages in Category Alpha/, "@INDEX_LINK has right default link text" ); - like( $output, qr/action=index;cat=foo/, "...and URL looks right" ); + like( $output, qr/action=index;cat=alpha/, "...and URL looks right" );
$output = $guide->display_node( return_output => 1, - id => "Test 2", + id => "Category Beta", ); - like( $output, qr/>Bars</a>/, "Default link text can be overridden" ); - like( $output, qr/action=index;cat=bar/, "...and URL looks right" ); + like( $output, qr/>Betas</a>/, "Default link text can be overridden" ); + like( $output, qr/action=index;cat=beta/, "...and URL looks right" );
# Test @INDEX_LIST - $wiki->write_node( "Test 3", "@INDEX_LIST [[Category Foo]]" ) + $wiki->write_node( "Category Foo", "@INDEX_LIST [[Category Foo]]", + undef, { category => "category" } ) or die "Can't write node"; - $wiki->write_node( "Test 4", "@INDEX_LIST [[Locale Bar]]" ) + $wiki->write_node( "Locale Bar", "@INDEX_LIST [[Locale Bar]]", + undef, { category => "locales" } ) or die "Can't write node"; - $wiki->write_node( "Test 5", "@INDEX_LIST [[Category Nonexistent]]" ) + $wiki->write_node( "Category Empty", "@INDEX_LIST [[Category Empty]]", + undef, { category => "foo" } ) or die "Can't write node"; - $wiki->write_node( "Test 6", "@INDEX_LIST [[Locale Nonexistent]]" ) + $wiki->write_node( "Locale Empty", "@INDEX_LIST [[Locale Empty]]", + undef, { locale => "bar" } ) or die "Can't write node"; $wiki->write_node( "Wibble", "wibble", undef, { @@ -59,31 +66,90 @@ } ) or die "Can't write node"; + $output = $guide->display_node( return_output => 1, - id => "Test 3", + id => "Category Foo", ); like ( $output, qr|<a href=".*">Wibble</a>|, - '@INDEX_LIST works for categories' ); + '@INDEX_LIST works for regular pages in categories' ); + like ( $output, qr|<a href=".*">Category Empty</a>|, + '...and for category pages in categories' ); $output = $guide->display_node( return_output => 1, - id => "Test 5", + id => "Category Empty", ); like ( $output, qr|No pages currently in category|, "...and fails nicely if no pages in category" ); $output = $guide->display_node( return_output => 1, - id => "Test 4", + id => "Locale Bar", ); like ( $output, qr|<a href=".*">Wibble</a>|, - '@INDEX_LIST works for locales' ); + '@INDEX_LIST works for regular pages in locales' ); + like ( $output, qr|<a href=".*">Locale Empty</a>|, + '...and for locale pages in locales' ); $output = $guide->display_node( return_output => 1, - id => "Test 6", + id => "Locale Empty", ); like ( $output, qr|No pages currently in locale|, "...and fails nicely if no pages in locale" );
+ # Test @INDEX_LIST_NO_PREFIX + $wiki->write_node( "Category Foo NP", + "@INDEX_LIST_NO_PREFIX [[Category Foo NP]]", + undef, { category => "category" } ) + or die "Can't write node"; + $wiki->write_node( "Locale Bar NP", + "@INDEX_LIST_NO_PREFIX [[Locale Bar NP]]", + undef, { category => "locales" } ) + or die "Can't write node"; + $wiki->write_node( "Category Empty NP", + "@INDEX_LIST_NO_PREFIX [[Category Empty NP]]", + undef, { category => "foo np" } ) + or die "Can't write node"; + $wiki->write_node( "Locale Empty NP", + "@INDEX_LIST_NO_PREFIX [[Locale Empty NP]]", + undef, { locale => "bar np" } ) + or die "Can't write node"; + $wiki->write_node( "Wibble NP", "wibble", undef, + { + category => "foo np", + locale => "bar np", + } + ) + or die "Can't write node"; + + $output = $guide->display_node( + return_output => 1, + id => "Category Foo NP", + ); + like ( $output, qr|<a href=".*">Wibble NP</a>|, + '@INDEX_LIST_NO_PREFIX works for regular pages in categories' ); + like ( $output, qr|<a href=".*">Empty NP</a>|, + '...and for category pages in categories' ); + $output = $guide->display_node( + return_output => 1, + id => "Category Empty NP", + ); + like ( $output, qr|No pages currently in category|, + "...and fails nicely if no pages in category" ); + $output = $guide->display_node( + return_output => 1, + id => "Locale Bar NP", + ); + like ( $output, qr|<a href=".*">Wibble NP</a>|, + '@INDEX_LIST_NO_PREFIX works for regular pages in locales' ); + like ( $output, qr|<a href=".*">Empty NP</a>|, + '...and for locale pages in locales' ); + $output = $guide->display_node( + return_output => 1, + id => "Locale Empty NP", + ); + like ( $output, qr|No pages currently in locale|, + "...and fails nicely if no pages in locale" ); + # Test @MAP_LINK OpenGuides::Test->write_data( guide => $guide,
openguides-commits@lists.openguides.org