Skip to content

Commit

Permalink
Merge commit 'ed9151c0238dd7f6001ac0e2dfa1f2eb6ff25bbe'
Browse files Browse the repository at this point in the history
  • Loading branch information
William Carr committed May 14, 2015
2 parents e6b9b61 + ed9151c commit 91a1b71
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 4 deletions.
21 changes: 21 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
Revision history for Template::Flute

0.0180 Wed Apr 29 09:33:14 2015 CEST

[BUG FIXES]

* Apply fix for <script> vanishes when inserted with op="hook"
(Stefan Hornburg, GH #99).

[ENHANCEMENTS]

* Add lower_dash filter (William Carr, GH #86).
* Allow usage of method in container's value attribute (William Carr, GH #95).

0.0171 Wed Apr 22 12:12:25 2015 CEST

[BUG FIXES]

* Clear out HTML element in case an empty value is passed for op=hook
(Stefan Hornburg).
* Prevent reparsing of DateTime objects in the date filter
(Stefan Hornburg).

0.0170 Tue Mar 31 22:08:11 2015 CEST

[ENHANCEMENTS]
Expand Down
4 changes: 4 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ lib/Template/Flute/Filter/Eol.pm
lib/Template/Flute/Filter/CountryName.pm
lib/Template/Flute/Filter/JsonVar.pm
lib/Template/Flute/Filter/LanguageName.pm
lib/Template/Flute/Filter/LowerDash.pm
lib/Template/Flute/Filter/NobreakSingle.pm
lib/Template/Flute/Filter/Replace.pm
lib/Template/Flute/Filter/Strip.pm
Expand Down Expand Up @@ -68,6 +69,7 @@ t/filters/currency.t
t/filters/date.t
t/filters/eol.t
t/filters/json.t
t/filters/lowerdash.t
t/filters/multi.t
t/filters/nobreak_single.t
t/filters/strip.t
Expand All @@ -77,6 +79,7 @@ t/values/append.t
t/values/bad_objects.t
t/values/basic.t
t/values/checkboxes.t
t/values/hook-script.t
t/values/input.t
t/values/js.t
t/values/multiple.t
Expand All @@ -95,6 +98,7 @@ t/i18n/01-simple.t
t/containers/basic.t
t/containers/dotted-value.t
t/containers/list.t
t/containers/object.t
t/containers/value.t
t/forms/01-name.t
t/forms/02-link.t
Expand Down
6 changes: 5 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ NAME
Template::Flute - Modern designer-friendly HTML templating Engine

VERSION
Version 0.0170
Version 0.0180

SYNOPSIS
use Template::Flute;
Expand Down Expand Up @@ -854,6 +854,10 @@ FILTERS
JSON to Javascript variable filter, see
Template::Flute::Filter::JsonVar. Requires JSON module.

lower_dash
Replaces spaces with dashes (-) and makes lowercase. see
Template::Flute::Filter::LowerDash.

Filter classes are loaded at runtime for efficiency and to keep the
number of dependencies for Template::Flute as small as possible.

Expand Down
9 changes: 7 additions & 2 deletions lib/Template/Flute.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ Template::Flute - Modern designer-friendly HTML templating Engine
=head1 VERSION
Version 0.0170
Version 0.0180
=cut

our $VERSION = '0.0170';
our $VERSION = '0.0180';

=head1 SYNOPSIS
Expand Down Expand Up @@ -2247,6 +2247,11 @@ Requires L<Locales> module.
JSON to Javascript variable filter, see L<Template::Flute::Filter::JsonVar>.
Requires L<JSON> module.
=item lower_dash
Replaces spaces with dashes (-) and makes lowercase.
see L<Template::Flute::Filter::LowerDash>.
=back
Filter classes are loaded at runtime for efficiency and to keep the
Expand Down
48 changes: 48 additions & 0 deletions lib/Template/Flute/Filter/LowerDash.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package Template::Flute::Filter::LowerDash;

use strict;
use warnings;

use base 'Template::Flute::Filter';

=head1 NAME
Template::Flute::Filter::LowerDash - LowerDashcase filter
=head1 DESCRIPTION
LowerDashcase filter. Replace spaces with dashes and make lowercase.
=head1 METHODS
=head2 filter
LowerDashcase filter.
=cut

sub filter {
my $self = shift;

(my $value = shift) =~ s/\s+/-/g;

return lc($value);
}

=head1 AUTHOR
William Carr (Mr. Maloof), <[email protected]>
=head1 LICENSE AND COPYRIGHT
Copyright 2011 Stefan Hornburg (Racke) <[email protected]>.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut

1;
9 changes: 9 additions & 0 deletions lib/Template/Flute/HTML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ sub hook_html {
my ($parser, $html, $body, @children, @ret, $elt_hook);

unless (defined $value && $value =~ /\S/) {
$elt->cut_children;
return '';
}

Expand All @@ -861,6 +862,14 @@ sub hook_html {

$elt->cut_children();

if (my $head_elt = $html->root->first_child('head')) {
# preserve useful elements like <script> inside HTML snippets (GH #99).
@children = $head_elt->cut_children;
for my $h_elt (@children) {
$h_elt->paste(last_child => $elt);
}
}

my $fc = $html->root()->first_child('body');

if ($elt->gi eq 'select' && $fc->first_child->gi eq 'select') {
Expand Down
38 changes: 37 additions & 1 deletion t/11-value.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use strict;
use warnings;

use Test::More tests => 3;
use Test::More tests => 5;
use Template::Flute;

my ($spec, $html, $flute, $out);
Expand Down Expand Up @@ -68,3 +68,39 @@ $out = $flute->process();
like($out, qr{\Q<select class="available_shipmodes" id="available_shipmodes" name="available_shipmodes"><option cost="" value="">Select Shipping</option></select>\E},
'value op=hook test with select HTML element')
or diag $out;

# value with op=hook and empty value
$spec = q{<specification>
<value name="content" op="hook"/>
</specification>
};

$html = q{<div class="content">CONTENT</div>};

$flute = Template::Flute->new(template => $html,
specification => $spec,
);

$out = $flute->process();

like($out, qr{\Q<div class="content"></div>\E},
'value op=hook test with class and empty value')
or diag $out;

# value with op=hook, HTML child element and empty value
$spec = q{<specification>
<value name="content" op="hook"/>
</specification>
};

$html = q{<div class="content"><p>CONTENT</p></div>};

$flute = Template::Flute->new(template => $html,
specification => $spec,
);

$out = $flute->process();

like($out, qr{\Q<div class="content"></div>\E},
'value op=hook test with class, HTML child element and empty value')
or diag $out;
36 changes: 36 additions & 0 deletions t/filters/lowerdash.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#! perl
#
# Test for lowerdash filter

use strict;
use warnings;
use Test::More tests => 3;

use Template::Flute;

# lowerdash filter
my $xml = <<EOF;
<specification name="filters">
<value name="text" filter="lower_dash" />
</specification>
EOF

my $html = <<EOF;
<div class="text">foo</div>
EOF

my $tests = {
'Red Wine' => 'red-wine',
'Red Wine is Delicious' => 'red-wine-is-delicious',
'Red Wine is Delicious' => 'red-wine-is-delicious',
};
for my $key ( keys %$tests ) {
my $flute = Template::Flute->new(
specification => $xml,
template => $html,
values => { text => $key }
);
my $ret = $flute->process();
ok( $ret =~ m{<div class="text">$tests->{$key}</div>},
qq{lower_dash filter: $ret} );
}
32 changes: 32 additions & 0 deletions t/values/hook-script.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! perl
#
# Test for <script> elements inside HTML snippets insertd with op="hook".

use strict;
use warnings;

use Test::More;
use Template::Flute;

my ($spec, $html, $flute, $out);

# value with op=hook, using class
$spec = q{<specification>
<value name="content" op="hook"/>
</specification>
};

$html = q{<div class="content">CONTENT</div>};

$flute = Template::Flute->new(template => $html,
specification => $spec,
values => {content => q{<script type="text/javascript"></script>}},
);

$out = $flute->process();

like($out, qr{\Q<div class="content"><script type="text/javascript"></script></div>\E},
'value op=hook test with <script> elements inside')
or diag $out;

done_testing;

0 comments on commit 91a1b71

Please sign in to comment.