Sisyphus repository
Last update: 25 september 2021 | SRPMs: 17344 | Visits: 21959072
en ru br
ALT Linux repos
S:0.1-alt2

Group :: Development/Perl
RPM: perl-Mojolicious-Plugin-TagHelpersExtra

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

pax_global_header00006660000000000000000000000064114514705640014521gustar00rootroot0000000000000052 comment=20259d200edc2e1f8bd309c010e2cc81716e1ede
perl-Mojolicious-Plugin-TagHelpersExtra-0.1/000075500000000000000000000000001145147056400211075ustar00rootroot00000000000000perl-Mojolicious-Plugin-TagHelpersExtra-0.1/.gitignore000064400000000000000000000001501145147056400230730ustar00rootroot00000000000000.*
!.gitignore
!.perltidyrc
*~
blib
Makefile*
!Makefile.PL
META.yml
MANIFEST*
!MANIFEST.SKIP
pm_to_blib
perl-Mojolicious-Plugin-TagHelpersExtra-0.1/.perltidyrc000064400000000000000000000024331145147056400232730ustar00rootroot00000000000000# Perl Best Practices (plus errata) .perltidyrc file
-l=98 # Max line width is 98 cols
-i=4 # Indent level is 4 cols
-ci=4 # Continuation indent is 4 cols
#-st # Output to STDOUT
-se # Errors to STDERR
-vt=2 # Maximal vertical tightness
-cti=0 # No extra indentation for closing brackets
-pt=1 # Medium parenthesis tightness
-bt=1 # Medium brace tightness
-sbt=1 # Medium square bracket tightness
-bbt=1 # Medium block brace tightness
-nsfs # No space before semicolons
-nolq # Don't outdent long quoted strings
-wbb="% + - * / x != == >= <= =~ < > | & **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
# Break before all operators

# Extras/overrides/deviations from Perl Best Practices
--maximum-line-length=78 # Be less generous
--warning-output # Show warnings
--maximum-consecutive-blank-lines=2 # Default is 1
--nohanging-side-comments # Troublesome for commented out code

-isbc # Block comments may only be indented if they have some space characters before the #
-ci=2 # Continuation indent is 2 cols

# We use version control, so just rewrite the file
-b

# For the up-tight folk :)
-pt=2 # High parenthesis tightness
-bt=2 # High brace tightness
-sbt=2 # High square bracket tightness
perl-Mojolicious-Plugin-TagHelpersExtra-0.1/Makefile.PL000064400000000000000000000022001145147056400230530ustar00rootroot00000000000000#!/usr/bin/env perl

# Copyright (C) 2010, Jan Jona Javorsek

use 5.008007;

use strict;
use warnings;

use ExtUtils::MakeMaker;

my ($mm) = $ExtUtils::MakeMaker::VERSION =~ /^([^_]+)/;

WriteMakefile(
NAME => 'Mojolicious::Plugin::TagHelpersExtra',
VERSION_FROM => 'lib/Mojolicious/Plugin/TagHelpersExtra.pm',
ABSTRACT => 'Extra HTML Tag Helpers',
AUTHOR => 'Jan Jona Javorsek <jan.javorsek@guest.arnes.si>',

($mm < 6.3002 ? () : ('LICENSE' => 'artistic_2')),

( $mm < 6.46
? ()
: ( META_MERGE => {
requires => {perl => '5.008007'},
resources => {
license => 'http://dev.perl.org/licenses/',
repository => 'http://github.com/kvorg/mojolicious-plugin-taghelpers-extra'
},
no_index => {directory => [qw/t/]}
},
META_ADD => {
build_requires => {},
configure_requires => {}
},
)
),

PREREQ_PM => {
'Mojo' => '>0.999926',
},
test => {TESTS => 't/*.t t/*/*.t t/*/*/*.t t/*/*/*/*.t'}
);
perl-Mojolicious-Plugin-TagHelpersExtra-0.1/README.pod000064400000000000000000000030201145147056400225430ustar00rootroot00000000000000=head1 NAME

Mojolicious::Plugin::TagHelpersExtra - Extra Tag Helpers Plugin

=head1 SYNOPSIS

# Mojolicious
$self->plugin('tag_helpers_extra');

# Mojolicious::Lite
plugin 'tag_helpers_extra';

=head1 DESCRIPTION

L<Mojolicous::Plugin::TagHelpersExtra> is a collection of additional
HTML5 tag helpers for L<Mojolicious>. Note that this module hopes to
be sublimated into L<Mojolicous::Plugin::TagHelpers> without warning!

See L<Mojolicious/Plugin/TagHelpersExtra> for documentation.

=head2 Helpers

=over 4

=item link_to_here

Generates a link to the current request URL, including any GET query
parameters, and allows addition/deletion/modification of said
parameters.

=item check_box_x

Generates a checkbox input element with value, and parse parameters
according to multiple choices. The attribute 'checked' can be used to
set a default value for the form, to be overruled if a parameter of
the same name is set.

=item radio_x

Generates a radio button input element with value and parse parameters
accoring to multiple choices. The attribute 'checked' can be used to
set a default value for the form, to be overruled if a parameter of
the same name is set.

=item table

Generates a table from a reference to an array of array rows, or,
alternatively, an array ref generating subroutine reference specified
in the C<sub> attribute. Headers, footers, attributes and captions are
supported.

=back

=head1 SEE ALSO

L<Mojolicious::Plugin::TagHelpers>, L<Mojolicious>,
L<Mojolicious::Guides>, L<http://mojolicious.org>.

=cut

perl-Mojolicious-Plugin-TagHelpersExtra-0.1/lib/000075500000000000000000000000001145147056400216555ustar00rootroot00000000000000perl-Mojolicious-Plugin-TagHelpersExtra-0.1/lib/Mojolicious/000075500000000000000000000000001145147056400241515ustar00rootroot00000000000000perl-Mojolicious-Plugin-TagHelpersExtra-0.1/lib/Mojolicious/Plugin/000075500000000000000000000000001145147056400254075ustar00rootroot00000000000000perl-Mojolicious-Plugin-TagHelpersExtra-0.1/lib/Mojolicious/Plugin/TagHelpersExtra.pm000064400000000000000000000405331145147056400310140ustar00rootroot00000000000000package Mojolicious::Plugin::TagHelpersExtra;

use strict;
use warnings;

use base 'Mojolicious::Plugin';

our $VERSION = '0.0001';

use Mojo::ByteStream;

# Clean up cb syntax for tables.
# Improve twisetd cb tests for tables.
# Add nested table example using blocks.

# QUOTE HERE
sub register {
my ($self, $app) = @_;

# Add "link_to_here" helper (with query)
$app->helper(
link_to_here => sub {
my $c = shift;
my $pp = $c->req->params;

# replace
if (defined $_[0] and ref $_[0] eq 'HASH') {
while (my ($param, $value) = each %{$_[0]}) {
$pp->remove($param);
$pp->append($param => $value);
}
shift;
}

# add
elsif (defined $_[0] and ref $_[0] eq 'ARRAY') {
$pp->append(shift @{$_[0]} => shift @{$_[0]}) while @{$_[0]};
shift;
}

# default link text
unless (@_ and ref $_[-1] eq 'CODE') {
my $cb = sub { return 'link' };
push @_, $cb;
}
$self->_tag('a', href => $c->req->url->query($pp), @_);
}
);

# Add "check_box_x" helper
# (with multi support and checked attribute for default)
$app->helper(
check_box_x => sub {
$self->_input_x(
shift, shift,
value => shift,
type => 'checkbox',
@_
);
}
);

# Add "radio_button_x" helper
# (with multi support and checked attribute for default)
$app->helper(
radio_button_x => sub {
$self->_input_x(
shift, shift,
value => shift,
type => 'radio',
@_
);
}
);

# Add "table" helper
$app->helper(
table => sub {
my $c = shift;
my $data = defined $_[0] && ref $_[0] eq 'ARRAY' ? shift : undef;

# Callback (but not sub=> argument)
my $cb =
defined $_[-1]
&& ref($_[-1]) eq 'CODE'
&& (defined $_[-2] and $_[-2] ne 'sub') ? pop @_ : undef;

pop if @_ % 2;
my %attr = @_;

# special attributes
my $caption_text;
$caption_text = $attr{caption} and delete $attr{caption}
if exists $attr{caption};
my $head;
$head = $attr{head} and delete $attr{head}
if exists $attr{head};
my $foot;
$foot = $attr{foot} and delete $attr{foot}
if exists $attr{foot};
my $ch;
$ch = $attr{ch} and delete $attr{ch}
if exists $attr{ch};
my $rh;
$rh = $attr{rh} and delete $attr{rh}
if exists $attr{rh};
my $rcb;
$rcb = $attr{rcb} and delete $attr{rcb}
if exists $attr{rcb};
my $ccb;
$ccb = $attr{ccb} and delete $attr{ccb}
if exists $attr{ccb};
my $sub = sub { return undef; };
$sub = $attr{sub} and delete $attr{sub}
if exists $attr{sub};

# Row callback
my $colcb = sub {
my $row_no = shift;
my $data = shift;
my $tag = shift || 'td';
my $row = '';

for (my $col_no = 0; $col_no < @$data; $col_no++) {
my $attr;
next
if defined $data->[$col_no]
and ref $data->[$col_no] eq 'HASH';
$attr = $data->[$col_no + 1]
if defined $data->[$col_no + 1]
and ref $data->[$col_no + 1] eq 'HASH';
my $t;
$t = 'th'
if ( ($col_no == 0 and defined $rh)
or (defined $row_no and $row_no == 0 and defined $ch)
);
$t ||= $tag;

# Cell callbacks
if (defined $attr->{cb} and ref $attr->{cb} eq 'CODE') {
my $args = {
tag => $t,
row_no => $row_no,
col_no => $col_no,
value => $data->[$col_no],
attributes => $attr ? $attr : {},
};
$args = $attr->{cb}->($args);
if (defined $args) {
$t = $args->{tag};
$data->[$col_no] = $args->{value};
$attr = $args->{attributes};
}
}

# Cell cb
if (defined $ccb and ref $ccb eq 'CODE') {
my $args = {
tag => $t,
row_no => $row_no,
col_no => $col_no,
value => $data->[$col_no],
attributes => $attr ? $attr : {},
};
$args = $ccb->($args);
if (defined $args) {
$t = $args->{tag};
$data->[$col_no] = $args->{value};
$attr = $args->{attributes};
}
}

$row .= $self->_tag($t, %$attr,
sub { return $data->[$col_no] });
}
return "\n$row\n";
};

my $extras = '';
if ($caption_text or $cb) {
$extras .= "\n";
$extras .= $self->_tag(
'caption',
sub {
($caption_text ? $caption_text : '')
. ($caption_text && $cb ? ' ' : '')
. ($cb ? $cb->() : '');
}
);
}
$extras
.= "\n"
. $self->_tag('head', sub { $colcb->(undef, $head, 'th') })
if $head;
$extras
.= "\n"
. $self->_tag('foot', sub { $colcb->(undef, $foot, 'th') })
if $foot;

# Rows
my $rows = $extras;
my $subrow;

for (
my $row_no = 0;
($data ? ($row_no < @$data) : ($subrow = $sub->()));
$row_no++
)
{
my $attr;
my $row;

# Sub returns the whole data?
if ( not $data
and $subrow
and ref $subrow eq 'ARRAY'
and defined $subrow->[0]
and ref $subrow->[0] eq 'ARRAY'
and
(scalar @$subrow > 1 or (ref $subrow->[0][1] ne 'HASH')))
{
$sub = sub { undef; };
$data = $subrow;
}

# Static table data
if (defined $data and defined $data->[$row_no]) {
next if ref $data->[$row_no] ne 'ARRAY'; # attributes
$attr = $data->[$row_no + 1]
if defined $data->[$row_no + 1]
and ref $data->[$row_no + 1] eq 'HASH';
$row = $data->[$row_no];
}

# Iterator callback
else {
last unless $subrow and ref $subrow eq 'ARRAY';

# Single line with attributes
if ($subrow->[0] eq 'ARRAY') {
$row = $subrow->[0];
$attr = $subrow->[1]
if defined $subrow->[1]
and ref $subrow->[1] eq 'HASH';
}

# No attrs
else {
$row = $subrow;
}
}

my $t = 'tr';

# Direct cb
if (defined $attr->{cb} and ref $attr->{cb} eq 'CODE') {
my $args = {
tag => $t,
row_no => $row_no,
col_no => 0,
value => $row,
attributes => $attr ? $attr : {},
};
$args = $attr->{cb}->($args);
if (defined $args) {
$t = $args->{tag};
$row = $args->{value};
$attr = $args->{attributes};
}
}

# Row cb
if (defined $rcb and ref $rcb eq 'CODE') {
my $args = {
tag => $t,
row_no => $row_no,
col_no => 0,
value => $row,
attributes => $attr ? $attr : {},
};
$args = $rcb->($args);
if (defined $args) {
$t = $args->{tag};
$row = $args->{value};
$attr = $args->{attributes};
}
}

$rows .= "\n"
. $self->_tag(
$t,
$attr ? %$attr : (),
sub { $colcb->($row_no, $row) }
);
}

return $self->_tag(
'table', %attr,
sub {
return "$rows\n";
}
);
}
);
}

sub _input_x {
my $self = shift;
my $c = shift;
my $name = shift;

# Callback
my $cb = defined $_[-1] && ref($_[-1]) eq 'CODE' ? pop @_ : undef;
pop if @_ % 2;

my %attrs = @_;

my $value = $attrs{value};
my %v;
if ($attrs{type} eq 'radio') {
%v = (scalar $c->param($name) => 1) if $c->param($name);
}

# checkbox
else {
%v = map { $_, 1 } ($c->param($name));
}
if (exists $v{$value}) {
$attrs{checked} = 'checked';
}

elsif (scalar $c->param($name)) {
delete $attrs{checked};
}
return $self->_tag('input', name => $name, %attrs, $cb || ());
}

# Stolen from 'Mojolicious::Plugin::TagHelpers'
sub _tag {
my $self = shift;
my $name = shift;

# Callback
my $cb = defined $_[-1] && ref($_[-1]) eq 'CODE' ? pop @_ : undef;
pop if @_ % 2;

# Tag
my $tag = "<$name";

# Attributes
my %attrs = @_;
for my $key (sort keys %attrs) {
my $value = $attrs{$key};
$tag .= qq/ $key="$value"/;
}

# Block
if ($cb) {
$tag .= '>';
$tag .= $cb->();
$tag .= "<\/$name>";
}

# Empty element
else { $tag .= ' />' }

# Prevent escaping
return Mojo::ByteStream->new($tag);
}

1;
__END__

=head1 NAME

Mojolicious::Plugin::TagHelpersExtra - Extra Tag Helpers Plugin

=head1 SYNOPSIS

# Mojolicious
$self->plugin('tag_helpers_extra');

# Mojolicious::Lite
plugin 'tag_helpers_extra';

=head1 DESCRIPTION

L<Mojolicous::Plugin::TagHelpersExtra> is a collection of additional
HTML5 tag helpers for L<Mojolicious>. Note that this module hopes to
be sublimated into L<Mojolicous::Plugin::TagHelpers> without warning!

=head2 Helpers

=over 4

=item link_to_here

<%= link_to_here %>
<%= link_to_here begin %>Reload<% end %>
<%= link_to_here (class => 'link') => begin %>Reload<% end %>
<%= link_to_here { page=>++$self->param('page') } => begin %>Next<% end %>
<%= link_to_here [ colour=>'blue', colour=>'red'] => begin %>More colours<% end %>

Generate link to the current URL, including the query.

Hashref arguments replace, arrayref arguments append query values.

Remaining arguments are used as attribute name/value pairs for the tag.

=item check_box_x

<%= check_box_x 'languages', value => 'perl', checked => 1 %>
<%= check_box_x 'languages', value => 'php' %>
<%= check_box_x 'languages', value => 'pyton' %>
<%= check_box_x 'languages', value => 'ruby' %>

Generate a checkbox input element with value, and parse parameters
according to multiple choices.

You can use the attribute 'checked' to set a default value for the
form, to be overruled if a parameter of the same name is set.

=item radio_x

<%= radio_x 'languages', value => 'perl', checked => 1 %>
<%= radio_x 'languages', value => 'php' %>
<%= radio_x 'languages', value => 'pyton' %>
<%= radio_x 'languages', value => 'ruby' %>

Generate a radio button input element with value and parse parameters
accoring to multiple choices.

You can use the attribute 'checked' to set a default value for the
form, to be overruled if a parameter of the same name is set.

The syntax is exactly the same as for the C<check_box_x> helper.

=item table

<%= table [
[ qw/Name A B C/ ],
[ 'John', 3, 5, 6 ],
[ 'Mary', 1, 3, 8 ]
],
ch =>1, rh => 1 %>
<%= table [ [ 3, 5, 6 ], [ 1, 3, 8 ] ],
class => 'numbers'
caption => 'Some numbers'%>
<%= table [ [ 3, 5, 6 ], [ 1, 3, 8 ] ]
=> begin %>Some <i>numbers</i>!<% end%>
<%= table [ [ 'John', 3, 5, 6 ], [ 'Mary', 1, 3, 8 ] ],
head => [ qw/Name A B C/ ] %>
<%= table [ [ 'John', 3, , 5 => {class=>'win'}, 6 ],
[ 'Mary', 1, 'N/A' => {colspan=>2} ] => {class=>'incomplete'} ] %>
<%= table head => [ qw/Name A B C/ ] sub => sub { $query->next_line() } %>
<%= table $query->all_lines() class=>'Direct from sub.' %>

Generate a table from a reference to an array of array rows, or,
alternatively, an array ref generating subroutine reference specified
in the C<sub> attribute. The subroutine reference must either return
the whole table, or return one line at a time, returning undef when
done. Note that a direct subroutine will not do, a reference is required.

Attributes are supported, and apply only to the table itself.

There are several special attributes: C<caption> sets the caption for
the table, and is exacly the same as specifying the caption in the
block following the helper. C<head> and C<foot> is used to pass the
header and footer row of the table, respectively. If C<ch>
or C<rh> is set, the first row or column is treated as row/column
header, respectively.

Attributes for the rows and cells are specified as a hash reference,
applying to the previous row or cell element.

There is no support for column groups, nested tables or attributes on
caption, header and footer.

It is possible, however, to modify the default behaviour and even
insert additional tags by declaring callback subroutines as
attributes. Use C<cb> on any row or cell. Use C<rcb> and C<ccb> on the
table to declare row and cell callbacks for every row and cell, to be
used even on caption, header and footer. Every callback gets called
with a hash reference, and should return the same reference modified
or undef for no action:

sub {
my $arg = shift;
my $tag = $arg->{tag}; # rows: tr, head, foot; cells: th, td
my $value = $arg->{value};
my $attrs = $arg->{attributes}; # hash reference
my $attrs = $arg->{row_no}; # undef in head and foot
my $attrs = $arg->{col_no}; # 0 in rows
... do work, modfiying %$arg
return undef if $fail;
return $arg;
}

The generic call back and will get called in both ways, for every cell
and row. The order of execution is: cell attribute callback, cell
callback, row attribute callback, row callback.

Examples:

# Stripes and red negative values with classes
<%= table $data, rcb=> sub {my $x = shift; $x->{attributes}{class} = 'odd' unless $x->{row_no} % 2; return $x; }, ccb=> sub {my $x =shift; $x->{attributes}{class} = 'red' unless $x->{value} >= 0; return $x;} %>

=back

=head1 METHODS

L<Mojolicious::Plugin::TagHelpersExtra> inherits all methods from
L<Mojolicious::Plugin> and implements the following new one:

=head2 C<register>

$plugin->register;

Register helpers in L<Mojolicious> application.

=head1 SEE ALSO

L<Mojolicious::Plugin::TagHelpers>, L<Mojolicious>,
L<Mojolicious::Guides>, L<http://mojolicious.org>.

=cut
perl-Mojolicious-Plugin-TagHelpersExtra-0.1/t/000075500000000000000000000000001145147056400213525ustar00rootroot00000000000000perl-Mojolicious-Plugin-TagHelpersExtra-0.1/t/00-load.t000064400000000000000000000003631145147056400226750ustar00rootroot00000000000000#!perl -T

use Test::More tests => 1;

BEGIN {
use_ok( 'Mojolicious::Plugin::TagHelpersExtra' ) || print "Bail out!
";
}

diag( "Testing Mojolicious::Plugin::TagHelpersExtra $Mojolicious::Plugin::TagHelpersExtra::VERSION, Perl $], $^X" );
perl-Mojolicious-Plugin-TagHelpersExtra-0.1/t/checkbox.t000064400000000000000000000050661145147056400233340ustar00rootroot00000000000000#!/usr/bin/env perl

use strict;
use warnings;

use utf8;

# Disable epoll, kqueue and IPv6
BEGIN { $ENV{MOJO_POLL} = $ENV{MOJO_NO_IPV6} = 1 }

use Mojo::IOLoop;
use Test::More;
use Test::Mojo;

# Make sure sockets are working
plan skip_all => 'working sockets required for this test!'
unless Mojo::IOLoop->new->generate_port;
plan tests => 9;

use Mojolicious::Lite;
plugin 'tag_helpers_extra';

app->log->level('error'); #silence

# GET /
get '/' => 'index';

# Test
my $client = app->client;
my $t = Test::Mojo->new;

# GET / default
$t->get_ok('/')->status_is(200)->content_is(<<EOF);
<!doctype html><html>
<head>
<title>Test</title>
</head>
<body><form action="/" method="get">
<p>
<input checked="checked" name="test" type="checkbox" value="default">Default</input>
<input checked="checked" name="test" type="checkbox" value="alternate">Alternate</input>
<input name="test" type="checkbox" value="thelast" />
<input type="submit" value="Test" />
</p>
</form>
</body>
</html>
EOF
# GET / query
$t->get_ok('/?test=alternate')->status_is(200)->content_is(<<EOF);
<!doctype html><html>
<head>
<title>Test</title>
</head>
<body><form action="/" method="get">
<p>
<input name="test" type="checkbox" value="default">Default</input>
<input checked="checked" name="test" type="checkbox" value="alternate">Alternate</input>
<input name="test" type="checkbox" value="thelast" />
<input type="submit" value="Test" />
</p>
</form>
</body>
</html>
EOF

# GET / query with multiple values
$t->get_ok('/?test=alternate&test=thelast')->status_is(200)->content_is(<<EOF);
<!doctype html><html>
<head>
<title>Test</title>
</head>
<body><form action="/" method="get">
<p>
<input name="test" type="checkbox" value="default">Default</input>
<input checked="checked" name="test" type="checkbox" value="alternate">Alternate</input>
<input checked="checked" name="test" type="checkbox" value="thelast" />
<input type="submit" value="Test" />
</p>
</form>
</body>
</html>
EOF


__DATA__
@@ index.html.ep
% layout 'main';
<%= form_for '/' => (method => 'get') => begin %>
<%= tag 'p' => begin %>
<%= check_box_x 'test', 'default', checked => 'checked' => begin %>Default<% end %>
<%= check_box_x 'test', 'alternate', checked => 'checked' => begin %>Alternate<% end %>
<%= check_box_x 'test', 'thelast' %>
<%= submit_button 'Test' %>
<% end %>
<% end %>

@@ layouts/main.html.ep
<!doctype html><html>
<head>
<title>Test</title>
</head>
<body><%== content %></body>
</html>
perl-Mojolicious-Plugin-TagHelpersExtra-0.1/t/linktohere.t000064400000000000000000000043311145147056400237040ustar00rootroot00000000000000#!/usr/bin/env perl

use strict;
use warnings;

use utf8;

# Disable epoll, kqueue and IPv6
BEGIN { $ENV{MOJO_POLL} = $ENV{MOJO_NO_IPV6} = 1 }

use Mojo::IOLoop;
use Test::More;
use Test::Mojo;

# Make sure sockets are working
plan skip_all => 'working sockets required for this test!'
unless Mojo::IOLoop->new->generate_port;
plan tests => 9;

use Mojolicious::Lite;
plugin 'tag_helpers_extra';

app->log->level('error'); #silence

# GET /
get '/' => 'index';

# Test
my $client = app->client;
my $t = Test::Mojo->new;

# GET / default
$t->get_ok('/?page=3')->status_is(200)->content_is(<<EOF);
<!doctype html><html>
<head>
<title>Test</title>
</head>
<body>
<a href="/?page=3">link</a>
<a href="/?page=3">Reload</a>
<a class="link" href="/?page=3">Reload</a>
<a href="/?page=4">Next</a>
<a href="/?page=4&colour=blue&colour=red">More colours</a>
</body>
</html>
EOF

# GET / query
$t->get_ok('/?page=3&colour=yellow')->status_is(200)->content_is(<<EOF);
<!doctype html><html>
<head>
<title>Test</title>
</head>
<body>
<a href="/?page=3&colour=yellow">link</a>
<a href="/?page=3&colour=yellow">Reload</a>
<a class="link" href="/?page=3&colour=yellow">Reload</a>
<a href="/?colour=yellow&page=4">Next</a>
<a href="/?colour=yellow&page=4&colour=blue&colour=red">More colours</a>
</body>
</html>
EOF

# GET / query with multiple values
$t->get_ok('/?page=3&page=5')->status_is(200)->content_is(<<EOF);
<!doctype html><html>
<head>
<title>Test</title>
</head>
<body>
<a href="/?page=3&page=5">link</a>
<a href="/?page=3&page=5">Reload</a>
<a class="link" href="/?page=3&page=5">Reload</a>
<a href="/?page=4">Next</a>
<a href="/?page=4&colour=blue&colour=red">More colours</a>
</body>
</html>
EOF


__DATA__
@@ index.html.ep
% layout 'main';
<% my $newpage = $self->param('page'); $newpage++; %>
<%= link_to_here %>
<%= link_to_here begin %>Reload<% end %>
<%= link_to_here class => 'link' => begin %>Reload<% end %>
<%= link_to_here { page => $newpage } => begin %>Next<% end %>
<%= link_to_here [ colour => 'blue', colour => 'red'] => begin %>More colours<% end %>

@@ layouts/main.html.ep
<!doctype html><html>
<head>
<title>Test</title>
</head>
<body><%== content %></body>
</html>
perl-Mojolicious-Plugin-TagHelpersExtra-0.1/t/manifest.t000064400000000000000000000004641145147056400233510ustar00rootroot00000000000000#!perl -T

use strict;
use warnings;
use Test::More;

unless ( $ENV{RELEASE_TESTING} ) {
plan( skip_all => "Author tests not required for installation" );
}

eval "use Test::CheckManifest 0.9";
plan skip_all => "Test::CheckManifest 0.9 required" if $@;
ok_manifest({filter => [qr/(\..*)|(.*~)|(#.*)/]});
perl-Mojolicious-Plugin-TagHelpersExtra-0.1/t/radio.t000064400000000000000000000047521145147056400226450ustar00rootroot00000000000000#!/usr/bin/env perl

use strict;
use warnings;

use utf8;

# Disable epoll, kqueue and IPv6
BEGIN { $ENV{MOJO_POLL} = $ENV{MOJO_NO_IPV6} = 1 }

use Mojo::IOLoop;
use Test::More;
use Test::Mojo;

# Make sure sockets are working
plan skip_all => 'working sockets required for this test!'
unless Mojo::IOLoop->new->generate_port;
plan tests => 9;

use Mojolicious::Lite;
plugin 'tag_helpers_extra';

app->log->level('error'); #silence

# GET /
get '/' => 'index';

# Test
my $client = app->client;
my $t = Test::Mojo->new;

# GET / default
$t->get_ok('/')->status_is(200)->content_is(<<EOF);
<!doctype html><html>
<head>
<title>Test</title>
</head>
<body><form action="/" method="get">
<p>
<input checked="checked" name="test" type="radio" value="default">Default</input>
<input name="test" type="radio" value="alternate">Alternate</input>
<input name="test" type="radio" value="thelast" />
<input type="submit" value="Test" />
</p>
</form>
</body>
</html>
EOF
# GET / query
$t->get_ok('/?test=alternate')->status_is(200)->content_is(<<EOF);
<!doctype html><html>
<head>
<title>Test</title>
</head>
<body><form action="/" method="get">
<p>
<input name="test" type="radio" value="default">Default</input>
<input checked="checked" name="test" type="radio" value="alternate">Alternate</input>
<input name="test" type="radio" value="thelast" />
<input type="submit" value="Test" />
</p>
</form>
</body>
</html>
EOF

# GET / query with too many values
$t->get_ok('/?test=alternate&test=thelast')->status_is(200)->content_is(<<EOF);
<!doctype html><html>
<head>
<title>Test</title>
</head>
<body><form action="/" method="get">
<p>
<input name="test" type="radio" value="default">Default</input>
<input checked="checked" name="test" type="radio" value="alternate">Alternate</input>
<input name="test" type="radio" value="thelast" />
<input type="submit" value="Test" />
</p>
</form>
</body>
</html>
EOF


__DATA__
@@ index.html.ep
% layout 'main';
<%= form_for '/' => (method => 'get') => begin %>
<%= tag 'p' => begin %>
<%= radio_button_x 'test', 'default', checked => 'checked' => begin %>Default<% end %>
<%= radio_button_x 'test', 'alternate' => begin %>Alternate<% end %>
<%= radio_button_x 'test', 'thelast' %>
<%= submit_button 'Test' %>
<% end %>
<% end %>

@@ layouts/main.html.ep
<!doctype html><html>
<head>
<title>Test</title>
</head>
<body><%== content %></body>
</html>
perl-Mojolicious-Plugin-TagHelpersExtra-0.1/t/table-cbs.t000064400000000000000000000133301145147056400233730ustar00rootroot00000000000000#!/usr/bin/env perl

use strict;
use warnings;

use utf8;

# Disable epoll, kqueue and IPv6
BEGIN { $ENV{MOJO_POLL} = $ENV{MOJO_NO_IPV6} = 1 }

use Mojo::IOLoop;
use Test::More;
use Test::Mojo;

# Make sure sockets are working
plan skip_all => 'working sockets required for this test!'
unless Mojo::IOLoop->new->generate_port;
plan tests => 3;

use Mojolicious::Lite;
plugin 'tag_helpers_extra';

app->log->level('error'); #silence

{
package Stuff;
our $count = 20;
our $width = 10;
sub stuff {
return undef unless $count--;
return ([map {$count - 15 + $_;} (1 .. $width)]);
} ;
sub new {
my $self = [];
return bless $self, 'Stuff';
}
}

my $stuff = new Stuff;


# GET /
get '/' => sub { shift->render(template=>'index', stuff=>$stuff); } => 'index';

# Test
my $client = app->client;
my $t = Test::Mojo->new;

# GET /
$t->get_ok('/')->status_is(200)->content_is(<<EOF);
<!doctype html><html>
<head>
<title>Test</title>
<style type="text/css">
table { caption-side: bottom; border-collapse: collapse; border-widht: 0pt; }
td { text-align: right; padding-left: .5em; padding-right: .5em;}
td.red { color: red; }
tr.odd { background-color: Lavender; }
</style>
</head>
<body><table class="programmatic">
<caption>Programmatic.</caption>
<tr class="odd">
<td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td><td>11</td><td>12</td><td>13</td><td>14</td>
</tr>
<tr>
<td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td><td>11</td><td>12</td><td>13</td>
</tr>
<tr class="odd">
<td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td><td>11</td><td>12</td>
</tr>
<tr>
<td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td><td>11</td>
</tr>
<tr class="odd">
<td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td>
</tr>
<tr>
<td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td>
</tr>
<tr class="odd">
<td class="red">-1</td><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td>
</tr>
<tr>
<td class="red">-2</td><td class="red">-1</td><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td>
</tr>
<tr class="odd">
<td class="red">-3</td><td class="red">-2</td><td class="red">-1</td><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td>
</tr>
<tr>
<td class="red">-4</td><td class="red">-3</td><td class="red">-2</td><td class="red">-1</td><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td>
</tr>
<tr class="odd">
<td class="red">-5</td><td class="red">-4</td><td class="red">-3</td><td class="red">-2</td><td class="red">-1</td><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td>
</tr>
<tr>
<td class="red">-6</td><td class="red">-5</td><td class="red">-4</td><td class="red">-3</td><td class="red">-2</td><td class="red">-1</td><td>0</td><td>1</td><td>2</td><td>3</td>
</tr>
<tr class="odd">
<td class="red">-7</td><td class="red">-6</td><td class="red">-5</td><td class="red">-4</td><td class="red">-3</td><td class="red">-2</td><td class="red">-1</td><td>0</td><td>1</td><td>2</td>
</tr>
<tr>
<td class="red">-8</td><td class="red">-7</td><td class="red">-6</td><td class="red">-5</td><td class="red">-4</td><td class="red">-3</td><td class="red">-2</td><td class="red">-1</td><td>0</td><td>1</td>
</tr>
<tr class="odd">
<td class="red">-9</td><td class="red">-8</td><td class="red">-7</td><td class="red">-6</td><td class="red">-5</td><td class="red">-4</td><td class="red">-3</td><td class="red">-2</td><td class="red">-1</td><td>0</td>
</tr>
<tr>
<td class="red">-10</td><td class="red">-9</td><td class="red">-8</td><td class="red">-7</td><td class="red">-6</td><td class="red">-5</td><td class="red">-4</td><td class="red">-3</td><td class="red">-2</td><td class="red">-1</td>
</tr>
<tr class="odd">
<td class="red">-11</td><td class="red">-10</td><td class="red">-9</td><td class="red">-8</td><td class="red">-7</td><td class="red">-6</td><td class="red">-5</td><td class="red">-4</td><td class="red">-3</td><td class="red">-2</td>
</tr>
<tr>
<td class="red">-12</td><td class="red">-11</td><td class="red">-10</td><td class="red">-9</td><td class="red">-8</td><td class="red">-7</td><td class="red">-6</td><td class="red">-5</td><td class="red">-4</td><td class="red">-3</td>
</tr>
<tr class="odd">
<td class="red">-13</td><td class="red">-12</td><td class="red">-11</td><td class="red">-10</td><td class="red">-9</td><td class="red">-8</td><td class="red">-7</td><td class="red">-6</td><td class="red">-5</td><td class="red">-4</td>
</tr>
<tr>
<td class="red">-14</td><td class="red">-13</td><td class="red">-12</td><td class="red">-11</td><td class="red">-10</td><td class="red">-9</td><td class="red">-8</td><td class="red">-7</td><td class="red">-6</td><td class="red">-5</td>
</tr>
</table>
</body>
</html>
EOF

__DATA__
@@ index.html.ep
% layout 'main';
% my $isod = sub {
% my $x = shift;
% $x->{attributes}{class} = 'odd' unless $x->{row_no} % 2;
% return $x;
% }
% my $isneg = sub {
% my $x =shift;
% $x->{attributes}{class} = 'red' unless $x->{value} >= 0;
% return $x;
% }
<%= table class => 'programmatic', $data, rcb=> $isodd , ccb=> $isneg, sub=> sub {$stuff->stuff} => begin %>Programmatic.<% end %>

@@ layouts/main.html.ep
<!doctype html><html>
<head>
<title>Test</title>
<style type="text/css">
table { caption-side: bottom; border-collapse: collapse; border-widht: 0pt; }
td { text-align: right; padding-left: .5em; padding-right: .5em;}
td.red { color: red; }
tr.odd { background-color: Lavender; }
</style>
</head>
<body><%== content %></body>
</html>
perl-Mojolicious-Plugin-TagHelpersExtra-0.1/t/table.t000064400000000000000000000114411145147056400226270ustar00rootroot00000000000000#!/usr/bin/env perl

use strict;
use warnings;

use utf8;

# Disable epoll, kqueue and IPv6
BEGIN { $ENV{MOJO_POLL} = $ENV{MOJO_NO_IPV6} = 1 }

use Mojo::IOLoop;
use Test::More;
use Test::Mojo;

# Make sure sockets are working
plan skip_all => 'working sockets required for this test!'
unless Mojo::IOLoop->new->generate_port;
plan tests => 3;

use Mojolicious::Lite;
plugin 'tag_helpers_extra';

app->log->level('error'); #silence

{
package Stuff;
our $count = 10;
sub stuff {
return undef unless $count--;
return ([$count, qw/X Y Z/]);
} ;
sub new {
my $self = [];
return bless $self, 'Stuff';
}
}

sub whole {
return [[ 1, {class=>'first'}, 2, 3], [4, 5, 6], { class=>'last'}];
}

my $stuff = new Stuff;


# GET /
get '/' => sub { shift->render(template=>'index', stuff=>$stuff); } => 'index';

# Test
my $client = app->client;
my $t = Test::Mojo->new;

# GET /
$t->get_ok('/')->status_is(200)->content_is(<<EOF);
<!doctype html><html>
<head>
<title>Test</title>
</head>
<body><table>
<tr class="rowtitle">
<td>Name</td><td>A</td><td>B</td><td>C</td>
</tr>
<tr>
<td class="celltitle">John</td><td>3</td><td>5</td><td>6</td>
</tr>
<tr>
<td>Mary</td><td>1</td><td>3</td><td>8</td>
</tr>
</table>
<table>
<caption>test</caption>
<tr class="rowtitle">
<td>Name</td><td>A</td><td>B</td><td>C</td>
</tr>
<tr>
<td class="celltitle">John</td><td>3</td><td>5</td><td>6</td>
</tr>
<tr>
<td>Mary</td><td>1</td><td colspan="3">N/A</td>
</tr>
</table>
<table>
<tr class="rowtitle">
<td>Name</td><td>A</td><td>B</td><td>C</td>
</tr>
<tr>
<td class="celltitle">John</td><td>3</td><td>5</td><td>6</td>
</tr>
<tr>
<td>Mary</td><td>1</td><td>3</td><td>8</td>
</tr>
</table>
<table class="test">
<caption>Test. A <i>double</i> test.</caption>
<tr class="rowtitle">
<th>Name</th><th>A</th><th>B</th><th>C</th>
</tr>
<tr>
<th class="celltitle">John</th><td>3</td><td>5</td><td>6</td>
</tr>
<tr>
<th>Mary</th><td>1</td><td>3</td><td>8</td>
</tr>
</table>
<table>
<head>
<th>Name</th><th>A</th><th>B</th><th>C</th>
</head>
<foot>
<th>name</th><th>a</th><th>b</th><th>c</th>
</foot>
<tr>
<td>John</td><td>3</td><td>5</td><td>6</td>
</tr>
<tr>
<td>Mary</td><td>1</td><td>3</td><td>8</td>
</tr>
</table>
<table class="incremental">
<caption>Incremental.</caption>
<tr>
<td>9</td><td>X</td><td>Y</td><td>Z</td>
</tr>
<tr>
<td>8</td><td>X</td><td>Y</td><td>Z</td>
</tr>
<tr>
<td>7</td><td>X</td><td>Y</td><td>Z</td>
</tr>
<tr>
<td>6</td><td>X</td><td>Y</td><td>Z</td>
</tr>
<tr>
<td>5</td><td>X</td><td>Y</td><td>Z</td>
</tr>
<tr>
<td>4</td><td>X</td><td>Y</td><td>Z</td>
</tr>
<tr>
<td>3</td><td>X</td><td>Y</td><td>Z</td>
</tr>
<tr>
<td>2</td><td>X</td><td>Y</td><td>Z</td>
</tr>
<tr>
<td>1</td><td>X</td><td>Y</td><td>Z</td>
</tr>
<tr>
<td>0</td><td>X</td><td>Y</td><td>Z</td>
</tr>
</table>
<table class="failed-incremental">
<caption>Incremental.</caption>
<tr class="rowtitle">
<td>Name</td><td>A</td><td>B</td><td>C</td>
</tr>
<tr>
<td class="celltitle">John</td><td>3</td><td>5</td><td>6</td>
</tr>
<tr>
<td>Mary</td><td>1</td><td>3</td><td>8</td>
</tr>
</table>
<table class="whole">
<caption>Whole.</caption>
<tr>
<td class="first">1</td><td>2</td><td>3</td>
</tr>
<tr class="last">
<td>4</td><td>5</td><td>6</td>
</tr>
</table>
<table class="direct">
<caption>Direct.</caption>
<tr>
<td class="first">1</td><td>2</td><td>3</td>
</tr>
<tr class="last">
<td>4</td><td>5</td><td>6</td>
</tr>
</table>
</body>
</html>
EOF

__DATA__
@@ index.html.ep
% layout 'main';
<%= table [ [ qw/Name A B C/ ] => { class=>'rowtitle' }, [ 'John' => { class=>'celltitle' }, 3, 5, 6 ], [ 'Mary', 1, 3, 8 ] ] %>
<%= table [ [ qw/Name A B C/ ] => { class=>'rowtitle' }, [ 'John' => { class=>'celltitle' }, 3, 5, 6 ], [ 'Mary', 1, 'N/A' => {colspan=>3} ] ], caption => 'test' %>
<%= table [ [ qw/Name A B C/ ] => { class=>'rowtitle' }, [ 'John' => { class=>'celltitle' }, 3, 5, 6 ], [ 'Mary', 1, 3, 8 ] ] => begin %>A <i>nice</i> test.<% end %>
<%= table [ [ qw/Name A B C/ ] => { class=>'rowtitle' }, [ 'John' => { class=>'celltitle' }, 3, 5, 6 ], [ 'Mary', 1, 3, 8 ] ], class => 'test', rh => 1, ch => 1, caption => 'Test.' => begin %>A <i>double</i> test.<% end %>
<%= table [ [ 'John', 3, 5, 6 ], [ 'Mary', 1, 3, 8 ] ], head => [ qw/Name A B C/ ], foot => [ qw/name a b c/ ] %>
<%= table class => 'incremental', sub=> sub {$stuff->stuff} => begin %>Incremental.<% end %>
<%= table [ [ qw/Name A B C/ ] => { class=>'rowtitle' }, [ 'John' => { class=>'celltitle' }, 3, 5, 6 ], [ 'Mary', 1, 3, 8 ] ], class => 'failed-incremental', sub=> sub {$stuff->stuff} => begin %>Incremental.<% end %>
<%= table class => 'whole', sub=> sub { ::whole() } => begin %>Whole.<% end %>
<%= table ::whole(), class => 'direct', => begin %>Direct.<% end %>

@@ layouts/main.html.ep
<!doctype html><html>
<head>
<title>Test</title>
</head>
<body><%== content %></body>
</html>
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin