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 ', ($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 is a collection of additional HTML5 tag helpers for L. Note that this module hopes to be sublimated into L without warning! See L 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 attribute. Headers, footers, attributes and captions are supported. =back =head1 SEE ALSO L, L, L, L. =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 is a collection of additional HTML5 tag helpers for L. Note that this module hopes to be sublimated into L 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 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 numbers!<% 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 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 sets the caption for the table, and is exacly the same as specifying the caption in the block following the helper. C and C is used to pass the header and footer row of the table, respectively. If C or C 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 on any row or cell. Use C and C 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 inherits all methods from L and implements the following new one: =head2 C $plugin->register; Register helpers in L application. =head1 SEE ALSO L, L, L, L. =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(< Test

Default Alternate

EOF # GET / query $t->get_ok('/?test=alternate')->status_is(200)->content_is(< Test

Default Alternate

EOF # GET / query with multiple values $t->get_ok('/?test=alternate&test=thelast')->status_is(200)->content_is(< Test

Default Alternate

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 Test <%== content %> 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(< Test link Reload Reload Next More colours EOF # GET / query $t->get_ok('/?page=3&colour=yellow')->status_is(200)->content_is(< Test link Reload Reload Next More colours EOF # GET / query with multiple values $t->get_ok('/?page=3&page=5')->status_is(200)->content_is(< Test link Reload Reload Next More colours 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 Test <%== content %> 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(< Test

Default Alternate

EOF # GET / query $t->get_ok('/?test=alternate')->status_is(200)->content_is(< Test

Default Alternate

EOF # GET / query with too many values $t->get_ok('/?test=alternate&test=thelast')->status_is(200)->content_is(< Test

Default Alternate

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 Test <%== content %> 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(< Test
Programmatic.
567891011121314
45678910111213
3456789101112
234567891011
12345678910
0123456789
-1012345678
-2-101234567
-3-2-10123456
-4-3-2-1012345
-5-4-3-2-101234
-6-5-4-3-2-10123
-7-6-5-4-3-2-1012
-8-7-6-5-4-3-2-101
-9-8-7-6-5-4-3-2-10
-10-9-8-7-6-5-4-3-2-1
-11-10-9-8-7-6-5-4-3-2
-12-11-10-9-8-7-6-5-4-3
-13-12-11-10-9-8-7-6-5-4
-14-13-12-11-10-9-8-7-6-5
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 Test <%== content %> 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(< Test
NameABC
John356
Mary138
test
NameABC
John356
Mary1N/A
NameABC
John356
Mary138
Test. A double test.
NameABC
John356
Mary138
NameABC nameabc
John356
Mary138
Incremental.
9XYZ
8XYZ
7XYZ
6XYZ
5XYZ
4XYZ
3XYZ
2XYZ
1XYZ
0XYZ
Incremental.
NameABC
John356
Mary138
Whole.
123
456
Direct.
123
456
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 nice 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 double 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 Test <%== content %>