Changeset 1095


Ignore:
Timestamp:
Jun 20, 2007, 5:34:42 PM (14 years ago)
Author:
Dominic Hargreaves
Message:

Only linkify categories and locales if they exist (fixes #15)

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides/Template.pm

    r1091 r1095  
    320320
    321321    my @categories = map { { name => $_,
    322                              url  => "$script_name?Category_"
    323             . uri_escape($formatter->node_name_to_node_param($_)) } } @catlist;
     322                             url  => $args{wiki}->node_exists( "Category_" . $formatter->node_name_to_node_param($_)) ? "$script_name?Category_"
     323            . uri_escape($formatter->node_name_to_node_param($_)) : "" } } @catlist;
    324324
    325325    my @locales    = map { { name => $_,
    326                              url  => "$script_name?Locale_"
    327             . uri_escape($formatter->node_name_to_node_param($_)) } } @loclist;
     326                             url  => $args{wiki}->node_exists( "Locale_" . $formatter->node_name_to_node_param($_)) ? "$script_name?Locale_"
     327            . uri_escape($formatter->node_name_to_node_param($_)) : "" } } @loclist;
    328328
    329329    # The 'website' attribute might contain a URL so we wiki-format it here
  • trunk/t/51_display_node.t

    r1064 r1095  
    1313}
    1414
    15 plan tests => 9;
     15plan tests => 13;
    1616
     17Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
    1718Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    1819my $config = OpenGuides::Config->new(
     
    6162
    6263unlike( $output, qr{^\QLocation: }ms, '...but not with redirect=0' );
     64
     65$wiki->write_node( "Non-existent categories and locales", "foo", undef,
     66                                { category => [ "Does not exist" ],
     67                                  locale   => [ "Does not exist" ] } );
     68
     69$output = $guide->display_node( id => 'Non-existent categories and locales',
     70                                return_output => 1
     71                              );
     72
     73unlike( $output, qr{\Q<a href="wiki.cgi?Category_Does_Not_Exist"},
     74    'Category name not linked if category does not exist' );
     75
     76$wiki->write_node( "Category_Does_Not_Exist", "bar", undef, undef );
     77
     78$output = $guide->display_node( id => 'Non-existent categories and locales',
     79                                return_output => 1
     80                              );
     81
     82like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Not_Exist"},
     83    'but does when it does exist' );
     84
     85unlike( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Not_Exist"},
     86    'Locale name not linked if category does not exist' );
     87
     88$wiki->write_node( "Locale_Does_Not_Exist", "wibble", undef, undef );
     89
     90$output = $guide->display_node( id => 'Non-existent categories and locales',
     91                                return_output => 1
     92                              );
     93
     94like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Not_Exist"},
     95    'but does when it does exist' );
     96
     97
  • trunk/templates/display_metadata.tt

    r937 r1095  
    8282        <span class="metadata_label">Categories:</span>
    8383        [% FOREACH category = categories %]
    84           <a href="[% category.url %]" class="category">[% category.name %]</a>[%- "," UNLESS loop.last %]
     84          [% IF category.url != "" %]
     85            <a href="[% category.url %]" class="category">[% category.name %]</a>[%- "," UNLESS loop.last %]
     86          [% ELSE %]
     87            [% category.name %][%- "," UNLESS loop.last %]
     88          [% END %]
    8589        [% END %]
    8690      </li>
     
    9195        <span class="metadata_label">Locales:</span>
    9296        [% FOREACH locale = locales %]
    93           <a href="[% locale.url %]" class="addr locality">[% locale.name %]</a>[%- "," UNLESS loop.last %]
     97          [% IF locale.url != "" %]
     98            <a href="[% locale.url %]" class="addr locality">[% locale.name %]</a>[%- "," UNLESS loop.last %]
     99          [% ELSE %]
     100            [% locale.name %][%- "," UNLESS loop.last %]
     101          [% END %]
    94102        [% END %]
    95103      </li>
Note: See TracChangeset for help on using the changeset viewer.