Author: kake
Date: 2012-05-02 18:10:39 +0100 (Wed, 02 May 2012)
New Revision: 1376
Modified:
trunk/lib/OpenGuides.pm
trunk/preferences.cgi
trunk/t/58_navbar_common_locales_categories.t
trunk/t/59_preferences.t
Log:
Moved preferences form display from preferences.cgi into OpenGuides.pm
Modified: trunk/lib/OpenGuides.pm
===================================================================
--- trunk/lib/OpenGuides.pm 2012-05-02 16:04:06 UTC (rev 1375)
+++ trunk/lib/OpenGuides.pm 2012-05-02 17:10:39 UTC (rev 1376)
@@ -637,6 +637,36 @@
}
}
+=item B<display_prefs_form>
+
+ $guide->display_prefs_form;
+
+Displays a form that lets the user view and set their preferences. The
+C<return_output> and C<return_tt_vars> parameters can be used to return
+the output or template variables, instead of printing the output to STDOUT.
+
+=cut
+
+sub display_prefs_form {
+ my ($self, %args) = @_;
+ my $config = $self->config;
+ my $wiki = $self->wiki;
+
+ my $output = OpenGuides::Template->output(
+ wiki => $wiki,
+ config => $config,
+ template => "preferences.tt",
+ vars => {
+ not_editable => 1,
+ show_form => 1,
+ not_deletable => 1,
+ },
+ noheaders => $args{noheaders},
+ );
+ return $output if $args{return_output};
+ print $output;
+}
+
=item B<display_recent_changes>
$guide->display_recent_changes;
Modified: trunk/preferences.cgi
===================================================================
--- trunk/preferences.cgi 2012-05-02 16:04:06 UTC (rev 1375)
+++ trunk/preferences.cgi 2012-05-02 17:10:39 UTC (rev 1376)
@@ -4,6 +4,7 @@
use strict;
use sigtrap die => 'normal-signals';
use CGI;
+use OpenGuides;
use OpenGuides::Config;
use OpenGuides::CGI;
use OpenGuides::JSON;
@@ -12,7 +13,8 @@
my $config_file = $ENV{OPENGUIDES_CONFIG_FILE} || "wiki.conf";
my $config = OpenGuides::Config->new( file => $config_file );
-my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
+my $guide = OpenGuides->new( config => $config );
+my $wiki = $guide->wiki;
my $cgi = CGI->new();
my $action = $cgi->param('action') || '';
my $format = $cgi->param('format') || '';
@@ -25,7 +27,7 @@
print "Content-type: text/javascript\n\n";
print $json_writer->make_prefs_json();
} else {
- show_form();
+ $guide->display_prefs_form;
}
sub set_preferences {
@@ -58,16 +60,3 @@
}
);
}
-
-sub show_form {
- print OpenGuides::Template->output(
- wiki => $wiki,
- config => $config,
- template => "preferences.tt",
- vars => {
- not_editable => 1,
- show_form => 1,
- not_deletable => 1,
- }
- );
-}
Modified: trunk/t/58_navbar_common_locales_categories.t
===================================================================
--- trunk/t/58_navbar_common_locales_categories.t 2012-05-02 16:04:06 UTC (rev 1375)
+++ trunk/t/58_navbar_common_locales_categories.t 2012-05-02 17:10:39 UTC (rev 1376)
@@ -26,18 +26,8 @@
}
sub get_preferences {
- my ($guide) = @_;
-
- return OpenGuides::Template->output(
- wiki => $guide->wiki,
- config => $guide->config,
- template => "preferences.tt",
- noheaders => 1,
- vars => {
- not_editable => 1,
- show_form => 1
- },
- );
+ my $guide = shift;
+ return $guide->display_prefs_form( return_output => 1, noheaders => 1 );
}
my %pages = (
Modified: trunk/t/59_preferences.t
===================================================================
--- trunk/t/59_preferences.t 2012-05-02 16:04:06 UTC (rev 1375)
+++ trunk/t/59_preferences.t 2012-05-02 17:10:39 UTC (rev 1376)
@@ -35,13 +35,15 @@
display_google_maps => 1,
);
$ENV{HTTP_COOKIE} = $cookie;
-Test::HTML::Content::tag_ok( get_output($wiki, $config),
+my $output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
+Test::HTML::Content::tag_ok( $output,
"input", { type => "checkbox", name => "display_google_maps" },
"Node map preference checkbox shown when we have a GMaps API key." );
# But not if the node map is globally disabled
$config->show_gmap_in_node_display( 0 );
-Test::HTML::Content::no_tag( get_output($wiki, $config),
+$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
+Test::HTML::Content::no_tag( $output,
"input", { type => "checkbox", name => "display_google_maps" },
"...but not when node maps are globally disabled." );
@@ -55,12 +57,14 @@
display_google_maps => 1,
);
$ENV{HTTP_COOKIE} = $cookie;
-Test::HTML::Content::tag_ok( get_output($wiki, $config),
+$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
+Test::HTML::Content::tag_ok( $output,
"input", { type => "checkbox", name => "display_google_maps" },
"Node map preference checkbox shown when we're using Leaflet." );
$config->show_gmap_in_node_display( 0 );
-Test::HTML::Content::no_tag( get_output($wiki, $config),
+$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
+Test::HTML::Content::no_tag( $output,
"input", { type => "checkbox", name => "display_google_maps" },
"...but not when node maps are globally disabled." );
@@ -68,7 +72,7 @@
my $json_writer = OpenGuides::JSON->new( wiki => $wiki,
config => $config );
delete $ENV{HTTP_COOKIE};
-my $output = eval {
+$output = eval {
$json_writer->make_prefs_json();
};
ok( !$@, "->make_prefs_json() doesn't die when no cookie set." );
@@ -116,19 +120,3 @@
if ( $@ ) { warn "# Warning was: $@"; }
is( $parsed->{username}, "Kake",
"...and the correct username is included in the output" );
-
-sub get_output {
- my ($wiki, $config) = @_;
-
- return OpenGuides::Template->output(
- wiki => $wiki,
- config => $config,
- template => "preferences.tt",
- noheaders => 1,
- vars => {
- not_editable => 1,
- show_form => 1
- },
- );
-}
-