Skip to content

Commit

Permalink
made text_area helper a little smarter
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 10, 2012
1 parent 65432fd commit b7f3c1d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Changes
@@ -1,5 +1,9 @@
This file documents the revision history for Perl extension Mojolicious.

2.60 2012-03-10 00:00:00
- Made text_area helper a little smarter. (sshaw, sri)
- Fixed escaping bug in text_area helper.

2.59 2012-03-09 00:00:00
- Removed duplicate 2.58 directory.

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -32,7 +32,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Leaf Fluttering In Wind';
our $VERSION = '2.59';
our $VERSION = '2.60';

# "These old doomsday devices are dangerously unstable.
# I'll rest easier not knowing where they are."
Expand Down
15 changes: 12 additions & 3 deletions lib/Mojolicious/Plugin/TagHelpers.pm
Expand Up @@ -234,9 +234,16 @@ sub register {
my ($c, $name) = (shift, shift);

# Value
my $cb = ref $_[-1] && ref $_[-1] eq 'CODE' ? pop : sub {''};
if (defined(my $value = $c->param($name))) {
$cb = sub {$value}
my $cb = sub {''};
my $value;
if (@_ % 2) {
if (ref $_[-1] && ref $_[-1] eq 'CODE') { $cb = pop }
else { $value = shift }
}

# Make sure value is wrapped
if (defined($value = $c->param($name) || $value)) {
$cb = sub { xml_escape $value}
}

return $self->_tag('textarea', name => $name, @_, $cb);
Expand Down Expand Up @@ -614,6 +621,7 @@ picked up and shown as default.
=head2 C<text_area>
%= text_area 'foo'
%= text_area foo => 'Default!', cols => 40
%= text_area foo => begin
Default!
% end
Expand All @@ -622,6 +630,7 @@ Generate textarea element. Previous input values will automatically get
picked up and shown as default.
<textarea name="foo"></textarea>
<textarea cols="40" name="foo">Default!</textarea>
<textarea name="foo">
Default!
</textarea>
Expand Down
16 changes: 13 additions & 3 deletions t/mojolicious/tag_helper_lite_app.t
Expand Up @@ -8,7 +8,7 @@ BEGIN {
$ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher';
}

use Test::More tests => 57;
use Test::More tests => 60;

# "Hey! Bite my glorious golden ass!"
use Mojolicious::Lite;
Expand Down Expand Up @@ -201,7 +201,7 @@ $t->get_ok('/form/lala?a=2&b=0&c=2&d=3&escaped=1%22+%222')->status_is(200)
EOF

# GET /form (alternative)
$t->get_ok('/form/lala?c=b&d=3&e=4&f=5')->status_is(200)->content_is(<<EOF);
$t->get_ok('/form/lala?c=b&d=3&e=4&f=<5')->status_is(200)->content_is(<<EOF);
<form action="/links" method="post">
<input name="foo" />
</form>
Expand All @@ -214,7 +214,7 @@ $t->get_ok('/form/lala?c=b&d=3&e=4&f=5')->status_is(200)->content_is(<<EOF);
<input name="c" type="hidden" value="foo" />
<input name="d" type="file" />
<textarea cols="40" name="e" rows="50">4</textarea>
<textarea name="f">5</textarea>
<textarea name="f">&lt;5</textarea>
<input name="g" type="password" />
<input id="foo" name="h" type="password" />
<input type="submit" value="Ok!" />
Expand Down Expand Up @@ -327,6 +327,15 @@ $t->put_ok('/selection?preselect=1')->status_is(200)
# PATCH /☃
$t->patch_ok('/☃')->status_is(200)->content_is(<<'EOF');
<form action="/%E2%98%83">
<textarea cols="40" name="foo">b&lt;a&gt;r</textarea>
<input type="submit" value="☃" />
</form>
EOF

# PATCH /☃
$t->patch_ok('/☃?foo=ba<z')->status_is(200)->content_is(<<'EOF');
<form action="/%E2%98%83">
<textarea cols="40" name="foo">ba&lt;z</textarea>
<input type="submit" value="☃" />
</form>
EOF
Expand Down Expand Up @@ -431,5 +440,6 @@ __DATA__
@@ snowman.html.ep
%= form_for snowman => begin
%= text_area foo => 'b<a>r', cols => 40
%= submit_button '☃'
%= end

0 comments on commit b7f3c1d

Please sign in to comment.