Skip to content

Commit

Permalink
updated Changes and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 24, 2014
1 parent 4f8ccf3 commit f145cfa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
6 changes: 6 additions & 0 deletions Changes
@@ -1,4 +1,10 @@

4.70 2014-01-25
- Improved tag helpers to make data attributes more convenient. (ravengerUA)
%= tag 'div', data => {id => 1, name => 'ok'} => 'some content'
is equivalent to
%= tag 'div', data-id => 1, data-name => 'ok' => 'some content'

4.69 2014-01-24
- Improved router to allow format detection for bridges.

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

our $CODENAME = 'Top Hat';
our $VERSION = '4.69';
our $VERSION = '4.70';

sub AUTOLOAD {
my $self = shift;
Expand Down
11 changes: 4 additions & 7 deletions lib/Mojolicious/Plugin/TagHelpers.pm
Expand Up @@ -213,12 +213,9 @@ sub _tag {

# Attributes
my %attrs = @_;

if ($attrs{data} && ref($attrs{data}) eq 'HASH') {
$attrs{"data-$_"} = $attrs{data}{$_} for sort keys %{$attrs{data}};
delete $attrs{data};
if ((my $data = $attrs{data}) && ref $attrs{data} eq 'HASH') {
$attrs{"data-$_"} = $data->{$_} for keys %{delete $attrs{data}};
}

$tag .= qq{ $_="} . xml_escape($attrs{$_} // '') . '"' for sort keys %attrs;

# Empty element
Expand Down Expand Up @@ -670,23 +667,23 @@ Alias for L</"tag">.
%= tag 'div', id => 'foo'
%= tag div => 'some & content'
%= tag div => (id => 'foo') => 'some & content'
%= tag div => (data => {id => 1, name => 'ok'}) => 'some & content'
%= tag div => begin
some & content
% end
<%= tag div => (id => 'foo') => begin %>some & content<% end %>
%= tag 'div', data => {id => 1, name => 'ok'} => 'some content'
HTML/XML tag generator.
<div />
<div id="foo" />
<div>some &amp; content</div>
<div id="foo">some &amp; content</div>
<div data-id="1" data-name="ok">some &amp; content</div>
<div>
some & content
</div>
<div id="foo">some & content</div>
<div data-id="1" data-name="ok">some content</div>
Very useful for reuse in more specific tag helpers.
Expand Down
12 changes: 6 additions & 6 deletions t/mojolicious/tag_helper_lite_app.t
Expand Up @@ -268,6 +268,8 @@ $t->get_ok('/form/lala?a=2&b=0&c=2&d=3&escaped=1%22+%222')->status_is(200)
</form>
<form action="/form/24" method="post">
<input name="foo" type="text" />
<input data-id="1" data-name="ok" name="foo" type="text" value="1" />
<input data="ok" name="foo" type="text" value="1" />
<input name="foo" type="checkbox" value="1" />
<input checked="checked" name="a" type="checkbox" value="2" />
<input name="b" type="radio" value="1" />
Expand All @@ -282,8 +284,6 @@ $t->get_ok('/form/lala?a=2&b=0&c=2&d=3&escaped=1%22+%222')->status_is(200)
<input id="foo" name="h" type="password" />
<input type="submit" value="Ok!" />
<input id="bar" type="submit" value="Ok too!" />
<input data-id="1" data-name="ok" name="foo" type="text" value="1" />
<input data="ok" name="foo" type="text" value="1" />
</form>
<form action="/">
<input name="foo" />
Expand All @@ -300,6 +300,8 @@ $t->get_ok('/form/lala?c=b&d=3&e=4&f=<5')->status_is(200)->content_is(<<EOF);
</form>
<form action="/form/24" method="post">
<input name="foo" type="text" />
<input data-id="1" data-name="ok" name="foo" type="text" value="1" />
<input data="ok" name="foo" type="text" value="1" />
<input name="foo" type="checkbox" value="1" />
<input name="a" type="checkbox" value="2" />
<input name="b" type="radio" value="1" />
Expand All @@ -312,8 +314,6 @@ $t->get_ok('/form/lala?c=b&d=3&e=4&f=<5')->status_is(200)->content_is(<<EOF);
<input id="foo" name="h" type="password" />
<input type="submit" value="Ok!" />
<input id="bar" type="submit" value="Ok too!" />
<input data-id="1" data-name="ok" name="foo" type="text" value="1" />
<input data="ok" name="foo" type="text" value="1" />
</form>
<form action="/">
<input name="foo" />
Expand Down Expand Up @@ -590,6 +590,8 @@ __DATA__
<% end %>
%= form_for 'form', {test => 24}, method => 'post' => begin
%= text_field 'foo'
%= text_field foo => 1, data => {id => 1, name => 'ok'}
%= text_field foo => 1, data => 'ok'
%= check_box foo => 1
%= check_box a => 2
%= radio_button b => '1'
Expand All @@ -604,8 +606,6 @@ __DATA__
%= password_field 'h', id => 'foo'
%= submit_button 'Ok!'
%= submit_button 'Ok too!', id => 'bar'
%= text_field foo => 1, data => {id => 1, name => 'ok'}
%= text_field foo => 1, data => 'ok'
%= end
<%= form_for '/' => begin %>
<%= input_tag 'foo' %>
Expand Down

0 comments on commit f145cfa

Please sign in to comment.