| 1 | package Mojolicious::Plugin::MoreTagHelpers; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use base 'Mojolicious::Plugin'; | ||
| 7 | |||
| 8 | use Mojo::ByteStream; | ||
| 9 | |||
| 10 | sub register { | ||
| 11 | my ($self, $app) = @_; | ||
| 12 | |||
| 13 | $app->renderer->add_helper( | ||
| 14 | select_tag => sub { | ||
| 15 | my ($c, $name, $options, $selected) = @_; | ||
| 16 | $selected ||= ""; | ||
| 17 | |||
| 18 | my $opts = join("", | ||
| 19 | map { | ||
| 20 | qq(<option name="$_") . | ||
| 21 | ($_ eq $selected ? | ||
| 22 | qq(selected="selected") : "") . | ||
| 23 | qq(>$_</option>) | ||
| 24 | } @$options); | ||
| 25 | return Mojo::ByteStream->new(qq(<select name="$name">$opts</select>)); | ||
| 26 | } | ||
| 27 | ); | ||
| 28 | } | ||
| 29 | |||
| 30 | 1; |