Mojolicious-Plugin-MostTagHelpers

 view release on metacpan or  search on metacpan

README.pod  view on Meta::CPAN

     %= li 'Shown after one click'
   % end
 % end

 %= incremental ul begin
   %= li 'Always shown'
   %= li 'Shown after one click'
 % end

  <ul>
    <li ms_overlay="1-">Always shown</li>
    <li ms_overlay="2-">Shown after one click</li>
  </ul>

Adds ms_overlay attributes to a sequence of elements with increasing start number.
Note that if passed an html element which has only one element, the attributes will be applied to the children of that attribute.
Because of this, the two templates above result in the same shown output.

=back

=head1 ELEMENTS

This module wraps lots of the HTML tags (though not all) into helpers.
If the helper gets a first argument that starts with C<#> or C<.>, that argument is parsed like a selector.
Note that only one id (the first) will be used if multiple are given.

lib/Mojolicious/Plugin/MostTagHelpers.pm  view on Meta::CPAN

  $text = $text->() if eval { ref $text eq 'CODE' };

  require Mojo::DOM;
  my $dom = Mojo::DOM->new($text);
  $dom->xml(1);
  my $children = $dom->children;
  if ($children->size == 1) {
    $children = $children->[0]->children;
  }
  $children->each(sub{
    $_->{ms_overlay} = $i++ . '-';
  });

  require Mojo::ByteStream;
  return Mojo::ByteStream->new($dom->to_string);
}

1;

__END__

lib/Mojolicious/Plugin/MostTagHelpers.pm  view on Meta::CPAN

     %= li 'Shown after one click'
   % end
 % end

 %= incremental ul begin
   %= li 'Always shown'
   %= li 'Shown after one click'
 % end

  <ul>
    <li ms_overlay="1-">Always shown</li>
    <li ms_overlay="2-">Shown after one click</li>
  </ul>


Adds ms_overlay attributes to a sequence of elements with increasing start number.
Note that if passed an html element which has only one element, the attributes will be applied to the children of that attribute.
Because of this, the two templates above result in the same shown output.

=back

=head1 ELEMENTS

This module wraps lots of the HTML tags (though not all) into helpers.
If the helper gets a first argument that starts with C<#> or C<.>, that argument is parsed like a selector.
Note that only one id (the first) will be used if multiple are given.

t/most_tag_helpers.t  view on Meta::CPAN

  ->text_is('div.find #me' => 'Gotcha');

$t->get_ok('/s')
  ->text_is('#foo' => 'hi')
  ->text_is('.baz' => 'hi')
  ->text_is('.bat' => 'hi')
  ->text_is('#foo.baz.bat' => 'hi')
  ->element_exists_not('#bar');

$t->get_ok('/i_parent')
  ->text_is('li[ms_overlay="1-"]' => 'One')->or($diag)
  ->text_is('li[ms_overlay="2-"]' => 'Two')->or($diag);

$t->get_ok('/i_items')
  ->text_is('li[ms_overlay="1-"]' => 'First')->or($diag)
  ->text_is('li[ms_overlay="2-"]' => 'Second')->or($diag);

$t->get_ok('/empty_element')
  ->text_is('img src="/tst.img"' => '')->or($diag);

done_testing;

__DATA__

@@ index.html.ep



( run in 2.095 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )