[Jifty-commit] r2339 - in Template-Declare: t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Dec 6 11:01:33 EST 2006
Author: audreyt
Date: Wed Dec 6 11:01:26 2006
New Revision: 2339
Modified:
Template-Declare/lib/Template/Declare/Tags.pm
Template-Declare/t/arg-declaration-styles.t
Log:
* Template::Declare::Tags: Support for all five style (all mixable):
div {{ id is 'moose' } span { 'Hi!' } };
div { attr { id is 'moose' } span { 'Hi!' } };
div { attr { id => 'moose' } span { 'Hi!' } };
div { attr { id is 'moose' }; span { 'Hi!' } };
div { attr { id => 'moose' }; span { 'Hi!' } };
The old style is still supported as well:
with(id => 'moose'), div { span { 'Hi!' } };
Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm (original)
+++ Template-Declare/lib/Template/Declare/Tags.pm Wed Dec 6 11:01:26 2006
@@ -20,14 +20,16 @@
die "Tr {...} and td {...} are invalid; use row {...} and cell {...} instead.";
}
-sub attr {
- while (my $field = shift @_) {
- my $val = shift @_;
+sub attr (&;$) {
+ my ($code, $out) = @_;
+ my @rv = $code->();
+ while (my ($field, $val) = splice(@rv, 0, 2)) {
# only defined whle in a tag context
append_attr( $field, $val );
}
- '';
+ $out;
}
+
sub outs {
$BUFFER .= join( '', grep { defined } @_ );
return '';
@@ -86,12 +88,11 @@
sub with (@) {
%ATTRIBUTES = ();
- while (@_) {
- my $key = shift || '';
- my $val = shift || '';
+ while (my ($key, $val) = splice(@_, 0, 2)) {
+ no warnings 'uninitialized';
$ATTRIBUTES{$key} = $val;
}
- '';
+ wantarray ? () : '';
}
sub _tag {
@@ -132,6 +133,13 @@
# Squash empty values, but not '0' values
my $val = join(' ', grep {defined $_ && $_ ne ''} @_);
+ append_attr($field,$val);
+ };
+
+ local *append_attr = sub {
+ my $field = shift;
+ my $val = shift;
+
use bytes;
$val =~ s/&/&/g;
$val =~ s/</</g;
@@ -141,15 +149,9 @@
$val =~ s/"/"/g;
$val =~ s/'/'/g;
- append_attr($field,$val);
- ''
- };
-
- local *append_attr = sub {
- my $field = shift;
- my $val = shift;
$buf .= qq[ $field="$val"];
- '';
+
+ wantarray ? () : '';
};
Modified: Template-Declare/t/arg-declaration-styles.t
==============================================================================
--- Template-Declare/t/arg-declaration-styles.t (original)
+++ Template-Declare/t/arg-declaration-styles.t Wed Dec 6 11:01:26 2006
@@ -20,19 +20,26 @@
}
};
-
template content_explicit => sub {
div {
- attr( id => 'body');
+ attr { id is 'body' }
outs('This is my content');
}
};
-template content_mixed => sub {
+template content_mixed1 => sub {
+ div {
+ { class is 'text'}
+ attr { style => 'red', id is 'body' }
+ outs('This is my red body text');
+ }
+};
+
+template content_mixed2 => sub {
with ( class => 'text'), div {
{ id is 'body'}
- attr ( style => 'red' );
+ attr { style => 'red' }; # Semicolon is intentional here
outs('This is my red body text');
}
};
@@ -52,25 +59,25 @@
template content_attrs => sub {
div {
- attr ( class => 'text', id => 'body', style => 'red' );
+ attr { class => 'text', id => 'body', style => 'red' }
outs('This is my red body text');
}
};
package Template::Declare::Tags;
-use Test::More tests => 33;
+use Test::More tests => 39;
use HTML::Lint;
our $self;
local $self = {};
bless $self, 'TestApp::UI';
-for (qw(content content_curly content_explicit)){
+for (qw(content content_curly content_explicit)){
local $Template::Declare::Tags::BUFFER;
ok_content(show($_),$_);
}
-for (qw(content_mixed content_attrs content_withs content_curlies)){
+for (qw(content_mixed1 content_mixed2 content_attrs content_withs content_curlies)){
local $Template::Declare::Tags::BUFFER;
ok_multicontent(show($_),$_);
}
More information about the Jifty-commit
mailing list