Changeset 509

Show
Ignore:
Timestamp:
09/20/04 21:05:10 (4 years ago)
Author:
kake
Message:

@INDEX_LIST macro

Location:
trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/Build.PL

    r501 r509  
    233233        'CGI::Cookie'                     => 0, 
    234234        'CGI::Wiki'                       => '0.54', 
    235         'CGI::Wiki::Formatter::UseMod'    => '0.09', 
     235        'CGI::Wiki::Formatter::UseMod'    => '0.16', # macros 
    236236        'CGI::Wiki::Plugin::Categoriser'  => 0, 
    237237        'CGI::Wiki::Plugin::Diff'         => '0.07', # earlier buggy 
  • trunk/Changes

    r507 r509  
    88          on edit form, banner at top of page (see CUSTOMISATION file 
    99          for details). 
     10        Added new macro - used as eg @INDEX_LIST [[Locale Fulham]] 
    1011 
    11120.40    18 September 2004 
  • trunk/PREREQUISITES

    r490 r509  
    1 Modules required by OpenGuides 0.40 
     1Modules required by OpenGuides 0.41 
    22=================================== 
    33 
     
    77CGI::Cookie 
    88CGI::Wiki (version 0.54 or later) 
    9 CGI::Wiki::Formatter::UseMod (version 0.09 or later) 
     9CGI::Wiki::Formatter::UseMod (version 0.16 or later) 
    1010CGI::Wiki::Plugin::Categoriser 
    1111CGI::Wiki::Plugin::Diff (version 0.07 or later) 
  • trunk/lib/OpenGuides/Utils.pm

    r469 r509  
    33use strict; 
    44use vars qw( $VERSION ); 
    5 $VERSION = '0.07'; 
     5$VERSION = '0.08'; 
    66 
    77use Carp qw( croak ); 
     
    120120        qr/\@INDEX_LINK\s+\[\[(Category|Locale)\s+([^\]|]+)\|?([^\]]+)?\]\]/ => 
    121121            sub { 
     122                  my $wiki = shift; 
    122123                  my $link_title = $_[2] || "View all pages in $_[0] $_[1]"; 
    123124                  return qq(<a href="$script_name?action=index;index_type=) . uri_escape(lc($_[0])) . qq(;index_value=) . uri_escape($_[1]) . qq(">$link_title</a>); 
    124125                }, 
    125         qr/\@RSS\s+\[(.*?)\]/ => sub {  
     126        qr/\@INDEX_LIST\s+\[\[(Category|Locale)\s+([^\]]+)]]/ => 
     127             sub { 
     128                   my ($wiki, $type, $value) = @_; 
     129                   my @nodes = $wiki->list_nodes_by_metadata( 
     130                       metadata_type  => $type, 
     131                       metadata_value => $value, 
     132                       ignore_case    => 1, 
     133                   ); 
     134                   unless ( scalar @nodes ) { 
     135                       return "\n* No pages currently in " 
     136                              . lc($type) . " $value\n"; 
     137                   } 
     138                   my $return = "\n"; 
     139                   foreach my $node ( @nodes ) { 
     140                       $return .= "* " 
     141                               . $wiki->formatter->format_link( 
     142                                                                wiki => $wiki, 
     143                                                                link => $node, 
     144                                                              ) 
     145                                . "\n"; 
     146                   } 
     147                   return $return; 
     148                 }, 
     149        qr/\@RSS\s+\[(.*?)\]/ => sub { 
     150                                       my $wiki = shift;  
    126151                                      # Get the URL. It's already been formatted into a  
    127152                                      # hyperlink so we need to reverse that. 
     
    156181                                   div code strike sub sup font)], 
    157182        macros              => \%macros, 
     183        pass_wiki_to_macros => 1, 
    158184        node_prefix         => "$script_name?", 
    159185        edit_prefix         => "$script_name?action=edit&id=", 
  • trunk/t/12_macros.t

    r361 r509  
    11use strict; 
     2use CGI::Wiki::Setup::SQLite; 
    23use Config::Tiny; 
    3 use OpenGuides::Utils; 
    4 use Test::More tests => 2; 
     4use OpenGuides; 
     5use Test::More tests => 6; 
    56 
    67eval { require DBD::SQLite; }; 
     
    89 
    910SKIP: { 
    10     skip "DBD::SQLite not installed - no database to test with", 2 
     11    skip "DBD::SQLite not installed - no database to test with", 6 
    1112      unless $have_sqlite; 
     13 
     14    # Clear out the database from any previous runs. 
     15    unlink "t/node.db"; 
     16    unlink <t/indexes/*>; 
     17    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } ); 
    1218 
    1319    my $config = Config::Tiny->new; 
     
    1824                     script_url         => "", 
    1925                     script_name        => "", 
     26                     site_name          => "Test", 
     27                     template_path      => "./templates", 
     28                     home_name          => "Home", 
    2029                   }; 
    2130 
    22     my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); 
    23     my $formatter = $wiki->formatter; 
     31    my $guide = OpenGuides->new( config => $config ); 
     32    my $wiki = $guide->wiki; 
    2433 
    25     my $wikitext = <<WIKI; 
     34    # Test @INDEX_LINK 
     35    $wiki->write_node( "Test 1", "\@INDEX_LINK [[Category Foo]]" ) 
     36      or die "Can't write node"; 
     37    $wiki->write_node( "Test 2", "\@INDEX_LINK [[Category Bar|Bars]]" ) 
     38      or die "Can't write node"; 
    2639 
    27 \@INDEX_LINK [[Category Foo]] 
     40    my $output; 
     41    $output = $guide->display_node( 
     42                                    return_output => 1, 
     43                                    id            => "Test 1", 
     44                                  ); 
     45    like( $output, qr/View all pages in Category Foo/, 
     46          "\@INDEX_LINK has right default link text" ); 
     47    $output = $guide->display_node( 
     48                                    return_output => 1, 
     49                                    id            => "Test 2", 
     50                                  ); 
     51    like( $output, qr/>Bars<\/a>/, "...and can be overridden" ); 
    2852 
    29 \@INDEX_LINK [[Category Bar|Bars]] 
    30  
    31 WIKI 
    32  
    33     my $html = $formatter->format($wikitext); 
    34     like( $html, qr/View all pages in Category Foo/, 
    35           "\@INDEX_LINK has right default link text" ); 
    36     like( $html, qr/>Bars<\/a>/, "...and can be overridden" ); 
     53    # Test @INDEX_LIST 
     54    $wiki->write_node( "Test 3", "\@INDEX_LIST [[Category Foo]]" ) 
     55      or die "Can't write node"; 
     56    $wiki->write_node( "Test 4", "\@INDEX_LIST [[Locale Bar]]" ) 
     57      or die "Can't write node"; 
     58    $wiki->write_node( "Test 5", "\@INDEX_LIST [[Category Nonexistent]]" ) 
     59      or die "Can't write node"; 
     60    $wiki->write_node( "Test 6", "\@INDEX_LIST [[Locale Nonexistent]]" ) 
     61      or die "Can't write node"; 
     62    $wiki->write_node( "Wibble", "wibble", undef, 
     63                       { 
     64                         category => "foo", 
     65                         locale   => "bar", 
     66                       } 
     67                     ) 
     68      or die "Can't write node"; 
     69    $output = $guide->display_node( 
     70                                    return_output => 1, 
     71                                    id            => "Test 3", 
     72                                  ); 
     73    like ( $output, qr|<a href=".*">Wibble</a>|, 
     74           '@INDEX_LIST works for categories' ); 
     75    $output = $guide->display_node( 
     76                                    return_output => 1, 
     77                                    id            => "Test 5", 
     78                                  ); 
     79    like ( $output, qr|No pages currently in category|, 
     80           "...and fails nicely if no pages in category" ); 
     81    $output = $guide->display_node( 
     82                                    return_output => 1, 
     83                                    id            => "Test 4", 
     84                                  ); 
     85    like ( $output, qr|<a href=".*">Wibble</a>|, 
     86           '@INDEX_LIST works for locales' ); 
     87    $output = $guide->display_node( 
     88                                    return_output => 1, 
     89                                    id            => "Test 6", 
     90                                  ); 
     91    like ( $output, qr|No pages currently in locale|, 
     92           "...and fails nicely if no pages in locale" ); 
    3793}