Changeset 190


Ignore:
Timestamp:
Jul 10, 2003, 7:06:59 PM (19 years ago)
Author:
kake
Message:

Added preferences option for including or excluding text formatting rules link in navbar.

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Build.PL

    r189 r190  
    7171{ question => "contact email address for the wiki admin?",
    7272  variable => "contact_email"
    73   }
     73  },
     74{ question => "what's the name of the node to use for the text formatting rules link?",
     75  variable => "formatting_rules_node",
     76  default  => "Text Formatting Examples"
     77  },
    7478);
    7579
  • trunk/Changes

    r189 r190  
    55        @INDEX_LINK macros now have optional title text like so:
    66          @INDEX_LINK [[Category Pubs|Pubs]]
     7        Added preferences option for including or excluding text formatting
     8          rules link in navbar.  Enable this by setting text_formatting_node
     9          in your config file.
    710
    8110.18    16 June 2003
  • trunk/lib/OpenGuides/CGI.pm

    r189 r190  
    22use strict;
    33use vars qw( $VERSION );
    4 $VERSION = '0.02';
     4$VERSION = '0.03';
    55
    66use Carp qw( croak );
     
    3131      include_geocache_link  => 1,
    3232      preview_above_edit_box => 1,
    33       latlong_traditional    => 1
     33      latlong_traditional    => 1,
     34      omit_formatting_link   => 1,
    3435  );
    3536
     
    5758      include_geocache_link  => 1,
    5859      preview_above_edit_box => 1,
    59       latlong_traditional    => 1
     60      latlong_traditional    => 1,
     61      omit_formatting_link   => 1,
    6062  );
    6163
     
    7577                    gclink => $args{include_geocache_link},
    7678                    prevab => $args{preview_above_edit_box},
    77                     lltrad => $args{latlong_traditional} }
     79                    lltrad => $args{latlong_traditional},
     80                    omitfmtlk => $args{omit_formatting_link},
     81                  }
    7882    );
    7983    return $cookie;
     
    102106        %data = $cookies{$cookie_name}->value; # call ->value in list context
    103107    }
    104     return ( username               => $data{user} || "Anonymous",
    105              include_geocache_link  => $data{gclink} || 0,
    106              preview_above_edit_box => $data{prevab} || 0,
    107              latlong_traditional    => $data{lltrad} || 0  );
     108    return ( username               => $data{user}      || "Anonymous",
     109             include_geocache_link  => $data{gclink}    || 0,
     110             preview_above_edit_box => $data{prevab}    || 0,
     111             latlong_traditional    => $data{lltrad}    || 0,
     112             omit_formatting_link   => $data{omitfmtlk} || 0,
     113           );
    108114}
    109115
  • trunk/lib/OpenGuides/Template.pm

    r189 r190  
    33use strict;
    44use vars qw( $VERSION );
    5 $VERSION = '0.07';
     5$VERSION = '0.08';
    66
    77use Carp qw( croak );
     
    5050                                      content_type => "text/html",
    5151                                      cookies      => $cookie,
    52                                       vars         => { foo => "bar" }
     52                                      vars         => {foo => "bar"}
    5353  );
    5454
    5555Returns everything you need to send to STDOUT, including the
    5656Content-Type: header. Croaks unless C<template> is supplied.
     57
     58The variables supplied in C<vars> are passed through to the template
     59specified.  Additional Template Toolkit variables are automatically
     60set and passed through as well, as described below.  B<Note:>
     61variables set in C<vars> will over-ride any variables of the same name
     62in the config object or the user cookies.
     63
     64=over
     65
     66=item * C<site_name>
     67
     68=item * C<cgi_url>
     69
     70=item * C<full_cgi_url>
     71
     72=item * C<contact_email>
     73
     74=item * C<stylesheet>
     75
     76=item * C<home_link>
     77
     78=item * C<formatting_rules_link> (unless C<omit_formatting_link> is set in user cookie)
     79
     80=item * C<home_name>
     81
     82=back
     83
     84If C<node> is supplied:
     85
     86=item * C<node_name>
     87
     88=item * C<node_param> (the node name escaped for use in URLs)
     89
     90=back
    5791
    5892Content-Type: defaults to C<text/html> and is omitted if the
     
    67101    my $template_path = $config->{_}->{template_path};
    68102    my $tt = Template->new( { INCLUDE_PATH => $template_path } );
    69     my $tt_vars = $args{vars} || {};
    70103
    71104    my $script_name = $config->{_}->{script_name};
     
    76109    $script_url .= "/" unless $script_url =~ /\/$/;
    77110
    78     $tt_vars = { %$tt_vars,
    79                  site_name     => $config->{_}->{site_name},
    80                  cgi_url       => $script_name,
    81                  full_cgi_url  => $script_url . $script_name,
    82                  contact_email => $config->{_}->{contact_email},
    83                  stylesheet    => $config->{_}->{stylesheet_url},
    84                  home_link     => $script_url . $script_name,
    85                  home_name     => $config->{_}->{home_name}
     111    # Check cookie to see if we need to set the formatting_rules_link.
     112    my %cookie_data = OpenGuides::CGI->get_prefs_from_cookie(config=>$config);
     113    my $formatting_rules_link = "";
     114    my $formatting_rules_node = $config->{_}->{formatting_rules_node} || "";
     115    if ( $formatting_rules_node and ! $cookie_data{omit_formatting_link} ) {
     116        $formatting_rules_link = $script_url . $script_name . "?"
     117                               . uri_escape($args{wiki}->formatter->node_name_to_node_param($formatting_rules_node));
     118    }
     119
     120    my $tt_vars = { site_name             => $config->{_}->{site_name},
     121                    cgi_url               => $script_name,
     122                    full_cgi_url          => $script_url . $script_name,
     123                    contact_email         => $config->{_}->{contact_email},
     124                    stylesheet            => $config->{_}->{stylesheet_url},
     125                    home_link             => $script_url . $script_name,
     126                    home_name             => $config->{_}->{home_name},
     127                    formatting_rules_link => $formatting_rules_link,
     128                    formatting_rules_node => $formatting_rules_node,
    86129    };
    87130
     
    90133        $tt_vars->{node_param} = CGI->escape($args{wiki}->formatter->node_name_to_node_param($args{node}));
    91134    }
     135
     136    # Now set further TT variables if explicitly supplied - do this last
     137    # as these override auto-set ones.
     138    $tt_vars = { %$tt_vars, %{ $args{vars} || {} } };
    92139
    93140    my $header = "";
     
    135182parameters in a L<CGI> object, and packages them nicely for passing to
    136183templates or storing in L<CGI::Wiki> datastore.  If you supply both
    137 C<metadata> and C<cgi_obj> then C<metadata will take precedence, but
     184C<metadata> and C<cgi_obj> then C<metadata> will take precedence, but
    138185don't do that.
    139186
  • trunk/preferences.cgi

    r189 r190  
    2626    my $pre_above    = $cgi->param("preview_above_edit_box") || 0;
    2727    my $latlong_trad = $cgi->param("latlong_traditional")    || 0;
     28    my $omit_fmt_lnk = $cgi->param("omit_formatting_link")   || 0;
    2829    my $cookie = OpenGuides::CGI->make_prefs_cookie(
    2930        config => $config,
     
    3132        include_geocache_link => $gc_link,
    3233        preview_above_edit_box => $pre_above,
    33         latlong_traditional => $latlong_trad
     34        latlong_traditional => $latlong_trad,
     35        omit_formatting_link => $omit_fmt_lnk,
    3436    );
    3537    print OpenGuides::Template->output(
     
    4244                      include_geocache_link  => $gc_link,
    4345                      preview_above_edit_box => $pre_above,
    44                       latlong_traditional    => $latlong_trad
     46                      latlong_traditional    => $latlong_trad,
     47                      omit_formatting_link   => $omit_fmt_lnk
    4548                    }
    4649    );
  • trunk/t/13_cookies.t

    r189 r190  
    11use strict;
    22use Config::Tiny;
    3 use Test::More tests => 14;
     3use Test::More tests => 15;
    44
    55use_ok( "OpenGuides::CGI" );
     
    2121    include_geocache_link  => 1,
    2222    preview_above_edit_box => 1,
    23     latlong_traditional    => 1
     23    latlong_traditional    => 1,
     24    omit_formatting_link   => 1,
    2425);
    2526isa_ok( $cookie, "CGI::Cookie", "->make_prefs_cookie returns a cookie" );
     
    4243is( $prefs{preview_above_edit_box}, 1, "...and preview prefs" );
    4344is( $prefs{latlong_traditional}, 1, "...and latlong prefs" );
     45is( $prefs{omit_formatting_link}, 1, "...and formatting link prefs" );
    4446
    4547# Check that cookie parsing fails nicely if no cookie set.
     
    4749%prefs = eval { OpenGuides::CGI->get_prefs_from_cookie( config => $config ); };
    4850is( $@, "", "->get_prefs_from_cookie doesn't die if no cookie set" );
    49 is( keys %prefs, 4, "...and returns four default values" );
     51is( keys %prefs, 5, "...and returns five default values" );
    5052
  • trunk/t/15_template.t

    r189 r190  
    11use strict;
    2 use Test::More tests => 19;
     2use Test::More tests => 22;
    33use Config::Tiny;
    44use Cwd;
     
    1212$config->{_}->{template_path} = cwd . "/t/templates";
    1313
    14 eval { OpenGuides::Template->output( config => $config ); };
     14# White box testing - we know that OpenGuides::Template only actually uses
     15# the node_name_to_node_param method of the formatter component of the wiki
     16# object passed in, and I CBA to faff about with picking out the test DB
     17# info to make a proper wiki object here.
     18my $fake_wiki = Test::MockObject->new;
     19$fake_wiki->mock("formatter",
     20                 sub { return CGI::Wiki::Formatter::UseMod->new; } );
     21
     22eval { OpenGuides::Template->output( wiki   => $fake_wiki,
     23                                     config => $config ); };
    1524ok( $@, "->output croaks if no template file supplied" );
    1625
    1726eval {
    18     OpenGuides::Template->output( config   => $config,
     27    OpenGuides::Template->output( wiki     => $fake_wiki,
     28                                  config   => $config,
    1929                                  template => "15_test.tt" );
    2030};
     
    2232
    2333my $output = OpenGuides::Template->output(
     34    wiki     => $fake_wiki,
    2435    config   => $config,
    2536    template => "15_test.tt",
     
    3142
    3243$output = OpenGuides::Template->output(
     44    wiki         => $fake_wiki,
    3345    config       => $config,
    3446    template     => "15_test.tt",
     
    3951
    4052$output = OpenGuides::Template->output(
    41     config => $config,
     53    wiki     => $fake_wiki,
     54    config   => $config,
    4255    template => "15_idonotexist.tt"
    4356);
     
    4558
    4659# Test TT variables are auto-set from config.
    47 
    4860$output = OpenGuides::Template->output(
     61    wiki     => $fake_wiki,
    4962    config   => $config,
    5063    template => "15_test.tt"
     
    6073like( $output, qr/HOME LINK: http:\/\/wiki.example.com\/mywiki.cgi/, "home_link var set" );
    6174like( $output, qr/HOME NAME: Home Page/, "home_name var set" );
     75like( $output,
     76      qr/FORMATTING RULES LINK: http:\/\/wiki.example.com\/mywiki.cgi\?Rules/,
     77      "formatting_rules_link var set" );
    6278
    6379# Test TT variables auto-set from node name.
    64 
    65 # White box testing - we know that OpenGuides::Template only actually uses
    66 # the node_name_to_node_param method of the formatter component of the wiki
    67 # object passed in, and I CBA to faff about with picking out the test DB
    68 # info to make a proper wiki object here.
    69 my $fake_wiki = Test::MockObject->new;
    70 $fake_wiki->mock("formatter",
    71                  sub { return CGI::Wiki::Formatter::UseMod->new; } );
    72 
    7380$output = OpenGuides::Template->output(
    7481    wiki     => $fake_wiki,
     
    8491my $cookie = CGI::Cookie->new( -name => "x", -value => "y" );
    8592$output = OpenGuides::Template->output(
     93    wiki     => $fake_wiki,
    8694    config   => $config,
    8795    template => "15_test.tt",
     
    94102$config->{_}->{template_path} = cwd . "/t/templates";
    95103$output = OpenGuides::Template->output(
     104    wiki     => $fake_wiki,
    96105    config   => $config,
    97106    template => "15_test.tt"
     
    107116$config->{_}->{script_name} = "wiki.cgi";
    108117$output = OpenGuides::Template->output(
     118    wiki     => $fake_wiki,
    109119    config   => $config,
    110120    template => "15_test.tt"
     
    113123      "full_cgi_url OK when trailing '/' missed off script_url" );
    114124
     125# Test that TT vars are picked up from user cookie prefs.
     126my $cookie = OpenGuides::CGI->make_prefs_cookie(
     127    config                 => $config,
     128    omit_formatting_link   => 1,
     129);
     130$ENV{HTTP_COOKIE} = $cookie;
     131$output = OpenGuides::Template->output(
     132    wiki     => $fake_wiki,
     133    config   => $config,
     134    template => "15_test.tt"
     135);
     136like( $output, qr/FORMATTING RULES LINK: /,
     137      "formatting_rules_link TT var blank as set in cookie" );
    115138
     139# Test that explicitly supplied vars override vars in cookie.
     140$output = OpenGuides::Template->output(
     141    wiki     => $fake_wiki,
     142    config   => $config,
     143    template => "15_test.tt",
     144    vars     => { omit_formatting_link => "fish" },
     145);
     146like( $output, qr/OMIT FORMATTING LINK: fish/,
     147      "explicitly supplied TT vars override cookie ones" );
  • trunk/t/15_wiki.conf

    r189 r190  
    22script_url = http://wiki.example.com/
    33script_name =
     4formatting_rules_node = Rules
  • trunk/t/21_wiki.conf

    r189 r190  
    77stylesheet_url = http://wiki.example.com/styles.css
    88home_name = Home Page
     9formatting_rules_node = Rules
  • trunk/t/templates/15_test.tt

    r189 r190  
    1111NODE NAME: [% node_name %]
    1212NODE PARAM: [% node_param %]
     13
     14FORMATTING RULES LINK: [% formatting_rules_link %]
     15OMIT FORMATTING LINK: [% omit_formatting_link %]
  • trunk/templates/navbar.tt

    r189 r190  
    1010    [% END %]
    1111    <li><a href="preferences.cgi">Set username/preferences</a></li>
     12    [% IF formatting_rules_link %]
     13      <li><a href="[% formatting_rules_link %]">[% formatting_rules_node %]</a></li>
     14    [% END %]
    1215    [% IF not_editable %]
    1316    </ul><br />
  • trunk/templates/preferences.tt

    r189 r190  
    4949    </p>
    5050
     51    [% IF formatting_rules_node %]
     52      <p>
     53      [% IF omit_formatting_link %]
     54        <input type="checkbox" name="omit_formatting_link" value="1" checked />
     55      [% ELSE %]
     56        <input type="checkbox" name="omit_formatting_link" value="1" />
     57      [% END %]
     58      Omit &#8220;[% formatting_rules_node %]&#8221; link from navbar.
     59      </p>
     60    [% END %]
     61
    5162    <input type="submit" value="Set it" class="form_button" />
    5263    <input type="hidden" name="action" value="set_preferences">
     
    7990  </p>
    8091
     92  [% IF formatting_rules_node %]
     93    <p>&#8220;[% formatting_rules_node %]&#8221; link
     94      [% IF omit_formatting_link %] not [% END %]
     95    included in navbar</p>
     96  [% END %]
     97
    8198  <p><a href="[% full_cgi_url %]">Return to the wiki</a></p>
    8299
Note: See TracChangeset for help on using the changeset viewer.