Changeset 161


Ignore:
Timestamp:
May 17, 2003, 8:24:30 PM (19 years ago)
Author:
kake
Message:

0.13 17 May 2003

Added some more stylesheet hooks.
Tweaked OpenGuides::Diff to make it testable, added a start at tests.
Lat and long now stored to only 6dp instead of millions.

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r160 r161  
    1 0.13   
     10.13    17 May 2003
    22        Added some more stylesheet hooks.
     3        Tweaked OpenGuides::Diff to make it testable, added a start at tests.
     4        Lat and long now stored to only 6dp instead of millions.
    35
    460.12    14 May 2003
  • trunk/MANIFEST

    r160 r161  
    4949t/22_rss_modwiki.t
    5050t/41_pubcrawl.t
     51t/51_diff.t
    5152t/templates/15_test.tt
    5253wiki.cgi
  • trunk/PREREQUISITES

    r160 r161  
    1 Modules required by OpenGuides 0.11
     1Modules required by OpenGuides 0.13
    22===================================
    33
  • trunk/lib/OpenGuides/Diff.pm

    r160 r161  
    44use warnings;
    55
    6 require Exporter;
    7 
    8 our @ISA = qw(Exporter);
    9 
    10 # Items to export into callers namespace by default. Note: do not export
    11 # names by default without a very good reason. Use EXPORT_OK instead.
    12 # Do not simply export all your public functions/methods/constants.
    13 
    14 # This allows declaration       use OpenGuides::Diff ':all';
    15 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
    16 # will save memory.
    17 our %EXPORT_TAGS = ( 'all' => [ qw(
    18         display_node_diff       
    19 ) ] );
    20 
    21 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
    22 
    23 our @EXPORT = qw(
    24        
    25 );
    26 
    27 our $VERSION = '0.01';
    28 
     6use Algorithm::Diff;
     7use VCS::Lite;
     8our $VERSION = '0.02';
    299
    3010=head1 NAME
    3111
    32 OpenGuides::Diff - OpenGuides module for displaying differences
     12OpenGuides::Diff - An OpenGuides helper to extract differences between two versions of a node.
     13
     14=head1 DESCRIPTION
     15
     16Makes a nice extract of differences between two versions of an
     17OpenGuides node.  Distributed and installed as part of the OpenGuides
     18project, not intended for independent installation.  This
     19documentation is probably only useful to OpenGuides developers.
    3320
    3421=head1 SYNOPSIS
    3522
     23  use Config::Tiny;
    3624  use OpenGuides::Diff;
     25  use OpenGuides::Template;
     26  use OpenGuides::Utils;
     27
     28  my $config = Config::Tiny->read( "wiki.conf" );
     29  my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
     30
     31  # Show the differences between versions 3 and 5 of the home node.
     32  my %diff_vars = OpenGuides::Diff->formatted_diff_vars(
     33      wiki => $wiki,
     34      node => "Home Page",
     35      versions => [5, 3]
     36  );
     37  print OpenGuides::Template->output( wiki     => $wiki,
     38                                      config   => $config,
     39                                      node     => "Home Page",
     40                                      template => "differences.tt",
     41                                      vars     => \%diff_vars );
    3742 
    38  
    39 =head1 DESCRIPTION
    40 
    41 This module provides display of differences for OpenGuides.
    42 
    43 =head2 EXPORT
    44 
    45 None by default.
    46 
    47 =head1 SEE ALSO
    48 
    49 L<OpenGuides>
    50 
    51 =head1 AUTHOR
    52 
    53 Ivor Williams, E<lt>ivor.williams@tiscali.co.ukE<gt>
    54 
    55 =head1 COPYRIGHT AND LICENSE
    56 
    57 Copyright 2003 by Ivor Williams
    58 
    59 This library is free software; you can redistribute it and/or modify
    60 it under the same terms as Perl itself.
    61 
    6243=cut
    63 use VCS::Lite;
    64 
    65 sub display_node_diff {
    66     my ($wiki, $node, $v1, $v2) = @_;
    67 
    68     my %ver1 = $wiki->retrieve_node( name => $node,
    69                                 version => $v1);
    70     my %ver2 = $wiki->retrieve_node( name => $node,
    71                                 version => $v2);
     44
     45=head1 METHODS
     46
     47=over 4
     48
     49=item B<formatted_diff_vars>
     50
     51  my %diff_vars = OpenGuides::Diff->formatted_diff_vars(
     52      wiki     => $wiki,
     53      node     => "Home Page",
     54      versions => [5, 3]
     55  );
     56
     57Returns a hash with the key-value pairs:
     58
     59=over 4
     60
     61=item *
     62
     63B<ver1> - The node version whose content we're considering canonical.
     64
     65B<ver2> - The node version that we're showing the differences from.
     66
     67B<content> - The (formatted) contents of version C<ver1> of the node.
     68
     69B<diff> - An array of hashrefs of C<hunks> of differences between the
     70versions - access from your template as C<diff.hunk.left> and
     71C<diff.hunk.right>.
     72
     73=back
     74
     75That explanation sucks.  Better wording solicited.
     76
     77=cut
     78
     79sub formatted_diff_vars {
     80    my ($class, %args) = @_;
     81    my ($wiki, $node)  = @args{ qw( wiki node ) };
     82    my ($v1, $v2)      = @{ $args{versions} };
     83
     84    my %ver1 = $wiki->retrieve_node( name => $node, version => $v1);
     85    my %ver2 = $wiki->retrieve_node( name => $node, version => $v2);
    7286
    7387    my $verstring1 = "Version ".$ver1{version};
     
    8599    $pag{content} = $wiki->format($ver1{content});
    86100    my $dlt = $el1->delta($el2)
    87         or main::process_template("differences.tt", $node, \%pag );
     101        or return %pag;
    88102    my ($c1,$c2,@dlt) = @$dlt;  # Unpicking a VCS::Lite::Delta object
    89103                                # but then I know what I am doing as I
     
    114128    $pag{diff} = \@out;
    115129
    116     # line below hacked to use namespace from caller assumed to be wiki.cgi
    117     main::process_template("differences.tt", $node, \%pag );
     130    return %pag;
    118131}
    119132
     
    169182}
    170183
     184=head1 SEE ALSO
     185
     186L<OpenGuides>
     187
     188=head1 AUTHOR
     189
     190The OpenGuides Project (grubstreet@hummous.earth.li)
     191
     192=head1 COPYRIGHT
     193
     194     Copyright (C) 2003 The OpenGuides Project.  All Rights Reserved.
     195
     196This module is free software; you can redistribute it and/or modify it
     197under the same terms as Perl itself.
     198
     199=head1 CREDITS
     200
     201Code in this module mostly written by Ivor Williams,
     202E<lt>ivor.williams@tiscali.co.ukE<gt>
     203
     204=cut
     205
    1712061;
  • trunk/lib/OpenGuides/Template.pm

    r160 r161  
    197197                                                          Northing => $os_y );
    198198            %tt_vars = ( %tt_vars,
    199                          latitude  => $point->latitude,
    200                          longitude => $point->longitude,
     199                         latitude  => sprintf("%.6f", $point->latitude),
     200                         longitude => sprintf("%.6f", $point->longitude),
    201201                         os_x      => $os_x,
    202202                         os_y      => $os_y
  • trunk/templates/differences.tt

    r160 r161  
    2525[% content %]
    2626
    27 
    28 [% IF os_x AND os_y %]
    29   <hr>
    30 <form action="wiki.cgi">
    31 Find all things within
    32 <select name="distance_in_metres">
    33   <option value="200">200 metres</option>
    34   <option value="500">500 metres</option>
    35   <option value="1000">1 kilometre</option>
    36   <option value="2000">2 kilometres</option>
    37 </select>
    38 of here.
    39   <input type="hidden" name="id" value="[% node_name %]" />
    40   <input type="hidden" name="action" value="find_within_distance" />
    41   <input type="submit" name="Go" value="Go" class="form_button" />
    42 </form>
    43 [% END %]
    44 
    4527<br clear="all" />
    4628
    47 [% IF categories %]
    48   <hr />
    49   <small><b>Categories:</b>
    50   [% FOREACH category = categories %]
    51     <a href="[% category.url %]">[% category.name %]</a> /
    52   [% END %]
    53   </small>
    54 [% END %]
    55 
    56 [% IF locales %]
    57   <hr />
    58   <small><b>Locale:</b>
    59     [% FOREACH locale = locales %]
    60       <a href="[% locale.url %]">[% locale.name %]</a> /
    61     [% END %]
    62   </small>
    63 [% END %]
     29[% INCLUDE display_categories.tt %]
    6430
    6531<a href="wiki.cgi?action=list_all_versions;id=[% node_param %]">List all versions</a><br />
     
    7339
    7440[% INCLUDE footer.tt %]
     41
     42
  • trunk/wiki.cgi

    r160 r161  
    55
    66use vars qw( $VERSION );
    7 $VERSION = '0.12';
     7$VERSION = '0.13';
    88
    99use CGI qw/:standard/;
     
    2020use OpenGuides::RDF;
    2121use OpenGuides::Utils;
    22 use OpenGuides::Diff qw(display_node_diff);
     22use OpenGuides::Diff;
    2323use OpenGuides::Template;
    2424use Time::Piece;
     
    122122            my $other_ver = $q->param("diffversion");
    123123            if ( $other_ver ) {
    124                 display_node_diff($wiki, $node, $version, $other_ver);
     124                my %diff_vars = OpenGuides::Diff->formatted_diff_vars(
     125                    wiki     => $wiki,
     126                    node     => $node,
     127                    versions => [ $version, $other_ver ]
     128                );
     129                print OpenGuides::Template->output(
     130                    wiki     => $wiki,
     131                    config   => $config,
     132                    node     => $node,
     133                    template => "differences.tt",
     134                    vars     => \%diff_vars
     135                );
    125136            } else {
    126137                display_node($node, $version);
Note: See TracChangeset for help on using the changeset viewer.