[Jifty-commit] r2346 - Template-Declare/lib/Template/Declare
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Dec 8 10:00:56 EST 2006
Author: audreyt
Date: Fri Dec 8 10:00:54 2006
New Revision: 2346
Modified:
Template-Declare/lib/Template/Declare/Tags.pm
Log:
* Semicolon is now optional in T::D declarators:
p { }
p { }
p { }
Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm (original)
+++ Template-Declare/lib/Template/Declare/Tags.pm Fri Dec 8 10:00:54 2006
@@ -76,7 +76,22 @@
no strict 'refs';
no warnings 'redefine';
- *$name = sub (&) { local *__ANON__ = $tag; _tag(@_) };
+ *$name = sub (&;$) {
+ local *__ANON__ = $tag;
+ if (defined wantarray and not wantarray) {
+ # Scalar context - return a coderef that represents ourselves.
+ my @__ = @_;
+ my $_self = $self;
+ sub {
+ local $self = $_self;
+ local *__ANON__ = $tag;
+ _tag(@__);
+ };
+ }
+ else {
+ _tag(@_);
+ }
+ };
}
use CGI ();
@@ -97,6 +112,7 @@
sub _tag {
my $code = shift;
+ my $more_code = shift;
my (
$package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask
@@ -155,8 +171,7 @@
};
- my $last = $code->();
-
+ my $last = join '', $code->();
if (length($BUFFER)) {
@@ -177,19 +192,21 @@
$BUFFER .= "\n" . ( " " x $DEPTH ) if ( $buf =~ /\n/ );
$BUFFER .= "</$tag>";
}
+ elsif ($tag =~ m{\A(?: base | meta | link | hr | br | param | img | area | input | col )\z}x) {
+ # EMPTY tags can close themselves.
+ $BUFFER .= $buf." />";
+ }
else {
- # We should, in theory, default to <tag /> rather than <tag></tag> if there's no content,
- # but until all we output is strict XHTML, "<iframe src='...' />" and "<a name='...' />"
- # are rendered incorrectly by gecko -- they require the use of an explicit closing tag
- # So intead of the correct treatment:
- #
- # $BUFFER .= $buf." />";
- #
- # we supply a closing tag for now:
- #
+ # Otherwise we supply a closing tag.
$BUFFER .= $buf."></$tag>";
}
- return '';
+
+ if ($more_code) {
+ $more_code->();
+ }
+ else {
+ return '';
+ }
}
=head2 show [$class or $object] [$template_name or $template_coderef]
@@ -203,7 +220,13 @@
=cut
sub show {
- local $self = shift if ( $_[0]->isa('Template::Declare') );
+ my $saved_self;
+
+ if ( $_[0]->isa('Template::Declare') ) {
+ $saved_self = $self;
+ $self = shift;
+ }
+
my $template = shift;
my $buf = '';
@@ -226,6 +249,10 @@
$buf = $BUFFER;
}
+ # Restore the old $self if we were called in an OO style, but only
+ # if there were already an $self before we enter the call.
+ $self = $saved_self if $saved_self;
+
$BUFFER .= $buf;
return $buf;
}
More information about the Jifty-commit
mailing list