[Jifty-commit] r6342 - in Template-Declare/branches/markapl-syntax: . lib/Template lib/Template/Declare lib/Template/Declare/TagSet
Jifty commits
jifty-commit at lists.jifty.org
Sun Feb 15 09:09:07 EST 2009
Author: gugod
Date: Sun Feb 15 09:09:07 2009
New Revision: 6342
Modified:
Template-Declare/branches/markapl-syntax/ (props changed)
Template-Declare/branches/markapl-syntax/Changes
Template-Declare/branches/markapl-syntax/META.yml
Template-Declare/branches/markapl-syntax/Makefile.PL
Template-Declare/branches/markapl-syntax/SIGNATURE
Template-Declare/branches/markapl-syntax/lib/Template/Declare.pm
Template-Declare/branches/markapl-syntax/lib/Template/Declare/Buffer.pm
Template-Declare/branches/markapl-syntax/lib/Template/Declare/TagSet/HTML.pm
Template-Declare/branches/markapl-syntax/lib/Template/Declare/Tags.pm
Template-Declare/branches/markapl-syntax/t/private.t
Template-Declare/branches/markapl-syntax/t/relative-pathing.t
Template-Declare/branches/markapl-syntax/t/subclassing.t
Log:
- Merge /prj/mirror/Template-Declare/trunk to /prj/mirror/Template-Declare/branches/markapl-syntax
Modified: Template-Declare/branches/markapl-syntax/Changes
==============================================================================
--- Template-Declare/branches/markapl-syntax/Changes (original)
+++ Template-Declare/branches/markapl-syntax/Changes Sun Feb 15 09:09:07 2009
@@ -1,3 +1,13 @@
+0.36 - 2009-02-05
+* Hint to the source of the buffer using a 'from' argument. This
+ allows us to inspect the call stack by looking at the buffer stack.
+
+0.35 - 2009-01-20
+* Buffers have been moved to using String::BufferStack, for better
+ interopability with other templating systems. Code which
+ manipulated Template::Declare::Buffer objects by hand may need to be
+ adjusted.
+
0.31_01 - 2008-12-19
* INCOMPATIBLE: there were inconsistency in arguments passing.
show in TD::Tags could pass arguments into template as array
Modified: Template-Declare/branches/markapl-syntax/META.yml
==============================================================================
--- Template-Declare/branches/markapl-syntax/META.yml (original)
+++ Template-Declare/branches/markapl-syntax/META.yml Sun Feb 15 09:09:07 2009
@@ -21,7 +21,8 @@
Class::Accessor::Fast: 0
Class::Data::Inheritable: 0
Class::ISA: 0
+ String::BufferStack: 1.1
perl: 5.8.2
resources:
license: http://dev.perl.org/licenses/
-version: 0.31_01
+version: 0.36
Modified: Template-Declare/branches/markapl-syntax/Makefile.PL
==============================================================================
--- Template-Declare/branches/markapl-syntax/Makefile.PL (original)
+++ Template-Declare/branches/markapl-syntax/Makefile.PL Sun Feb 15 09:09:07 2009
@@ -13,5 +13,6 @@
requires 'Class::Accessor::Fast';
requires 'Class::Data::Inheritable';
requires 'Class::ISA';
+requires 'String::BufferStack' => 1.10;
WriteAll;
Modified: Template-Declare/branches/markapl-syntax/SIGNATURE
==============================================================================
--- Template-Declare/branches/markapl-syntax/SIGNATURE (original)
+++ Template-Declare/branches/markapl-syntax/SIGNATURE Sun Feb 15 09:09:07 2009
@@ -14,11 +14,11 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
-SHA1 cfdff32101d960dbc52c0abe5abaafada9996aae Changes
+SHA1 4ec347a5d20c542cedddfc9d7970c447c847fed3 Changes
SHA1 58642f7ef09571d417e4f5b0ca8eb508b9edb235 MANIFEST
SHA1 6f70228d55d21d8a18d86c6d9acb1a9d5a5504fe MANIFEST.SKIP
-SHA1 e3ae118ffed1940a37837917ad13ec1f692201b3 META.yml
-SHA1 84a7277f9ccd12e4f6d1a619bef2e3721dca45fc Makefile.PL
+SHA1 bacf9729b4c445b2bd0a4590ce7086485c61ed9e META.yml
+SHA1 905f717b7e4d05ccd5848d785a639b64888fb401 Makefile.PL
SHA1 65da83220e6bf55fec475fe014f90ad37a9f4969 README
SHA1 5c9e093b0facca46d50e3c69d5569aa7a98db0b8 inc/Module/Install.pm
SHA1 465acb50b9006ce61f58a7bd02d0bb029ddceaa6 inc/Module/Install/Base.pm
@@ -28,14 +28,14 @@
SHA1 4aa1c578faad51f31e62bed7b28d3d42b88219c3 inc/Module/Install/Metadata.pm
SHA1 d7529d795a1304c88253b26a9089913edf31ae5e inc/Module/Install/Win32.pm
SHA1 2a74aba5a78e7ab2776382e42106ebe941c2ac28 inc/Module/Install/WriteAll.pm
-SHA1 f1238a601c5921e64c3ea5cd85e9928a72c2bb15 lib/Template/Declare.pm
-SHA1 b53e3d035181a549f2666d4a11b3c52923a96d84 lib/Template/Declare/Buffer.pm
+SHA1 dc0d3e1cfe47042f718ef6df509bf2ebcb0026d0 lib/Template/Declare.pm
+SHA1 a44d64624dd8d0ce708a0d056a8945783fd9cd53 lib/Template/Declare/Buffer.pm
SHA1 5b8295d842ccea0a21661583446344733f668879 lib/Template/Declare/TagSet.pm
SHA1 a4b1d4e5e70b6bf928ceb7d6eeb73bc6b2d7d7a9 lib/Template/Declare/TagSet/HTML.pm
SHA1 f95b68b4c50afcd1c66d225556dcfa2b2f18e619 lib/Template/Declare/TagSet/RDF.pm
SHA1 4899124cdf56c12fcc7ac1a2b3d99910ed5b8bbb lib/Template/Declare/TagSet/RDF/EM.pm
SHA1 460ab0856c8aea75c81e8cb1e5fb287515b1b2bf lib/Template/Declare/TagSet/XUL.pm
-SHA1 7477a520aa2ea47100e0594b6f2eba2750b4767a lib/Template/Declare/Tags.pm
+SHA1 0e53d539095fd778f59fc02ae9cd9f9a713d4385 lib/Template/Declare/Tags.pm
SHA1 7b2832c140109b23ba669db59e5b357dd1d255ec t/99-pod-coverage.t
SHA1 bb0da54f2b3f2d7955baa41ee458cb3d1887f475 t/99-pod.t
SHA1 8de6d59c7ed7c771f9cdc5e2dbaef0c31c7ab439 t/MyTagSet.pm
@@ -58,15 +58,15 @@
SHA1 cd8bf27d877bc26640f99947821c9d874aa8239b t/overloaded.t
SHA1 6af119980cb391b086c0f66d4037ca59b06b2363 t/pitfalls.t
SHA1 fb01850a459d3d340bdf688271d14fc55db321e3 t/postprocessor.t
-SHA1 0c00d095bb6ff6fd9d493e8c2ae0f45aa002072b t/private.t
+SHA1 6918ecf012a81e66852543d87f93aac95fa05dd9 t/private.t
SHA1 a580daf468f50f09a7828ac57f9d738e6f1f4558 t/relative-aliasing.t
-SHA1 1e57d39c4b40cd19e14efd93179d87b78e8d54e9 t/relative-pathing.t
+SHA1 179841125b5c89ad35063d9a1da823b8c2dbe3a1 t/relative-pathing.t
SHA1 7a95f27648a60084863ca8db7140f2b601794267 t/rt-37622.t
SHA1 de23aec78ebc456083d8df85cf11d520bb03544f t/self.t
SHA1 c09c579c74578fbcb9ede55ed634f7052c35580e t/siblings.t
SHA1 0183f5c550973540a4f2d275317350664ae94762 t/similar-aliases.t
SHA1 613d76b8b76c74002da8dff2866539b991b0505a t/smart_tag_wrapper.t
-SHA1 adc48b3337a1f468555afbb6bc9f69eda0eca46a t/subclassing.t
+SHA1 863b6d22ad80e7a9b770221d5384146ab6ca5859 t/subclassing.t
SHA1 5bf9c06c76830580e6c402ccea5755201a363a5f t/subtemplates.t
SHA1 44f81200ec38ebf8bc9c836e34942f70990e7207 t/tag_sub_list.t
SHA1 bab73f849bd1251f55e8b933a12ea7a8f3f2d44a t/tagset_html.t
@@ -82,7 +82,7 @@
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
-iEYEARECAAYFAklLC4IACgkQvH6dkeDZaS9+yACeNP9uXDP5lcbs2P8mcT0TAagP
-r/AAninY5heB1NliP9NwFBXr3YNVAAOx
-=RGVA
+iEYEARECAAYFAkmLVCYACgkQMflWJZZAbqDi+ACggAa/Eqa6nZ/cwHOSpAEPQNsj
+COkAnjSfOczGtdZXhioiCp2zam6BduJ4
+=2B8H
-----END PGP SIGNATURE-----
Modified: Template-Declare/branches/markapl-syntax/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/branches/markapl-syntax/lib/Template/Declare.pm (original)
+++ Template-Declare/branches/markapl-syntax/lib/Template/Declare.pm Sun Feb 15 09:09:07 2009
@@ -6,8 +6,9 @@
package Template::Declare;
use Template::Declare::Buffer;
use Class::ISA;
+use String::BufferStack;
-our $VERSION = "0.31_01";
+our $VERSION = "0.36";
use base 'Class::Data::Inheritable';
__PACKAGE__->mk_classdata('roots');
@@ -16,7 +17,7 @@
__PACKAGE__->mk_classdata('alias_metadata');
__PACKAGE__->mk_classdata('templates');
__PACKAGE__->mk_classdata('private_templates');
-__PACKAGE__->mk_classdata('buffer_stack');
+__PACKAGE__->mk_classdata('buffer');
__PACKAGE__->mk_classdata('imported_into');
__PACKAGE__->mk_classdata('around_template');
@@ -26,10 +27,10 @@
__PACKAGE__->alias_metadata( {} );
__PACKAGE__->templates( {} );
__PACKAGE__->private_templates( {} );
-__PACKAGE__->buffer_stack( [] );
+__PACKAGE__->buffer( String::BufferStack->new );
__PACKAGE__->around_template( undef );
-__PACKAGE__->new_buffer_frame();
+*String::BufferStack::data = \&String::BufferStack::buffer;
use vars qw/$TEMPLATE_VARS/;
@@ -351,20 +352,11 @@
}
sub new_buffer_frame {
- my $buffer = Template::Declare::Buffer->new();
- unshift @{ __PACKAGE__->buffer_stack }, $buffer;
-
+ __PACKAGE__->buffer->push( private => 1 );
}
sub end_buffer_frame {
- shift @{ __PACKAGE__->buffer_stack };
-}
-
-sub buffer {
- my $res = __PACKAGE__->buffer_stack->[0];
- Carp::confess( __PACKAGE__ . "->buffer called with no buffer" )
- unless $res;
- return $res;
+ __PACKAGE__->buffer->pop;
}
=head2 show TEMPLATE_NAME
Modified: Template-Declare/branches/markapl-syntax/lib/Template/Declare/Buffer.pm
==============================================================================
--- Template-Declare/branches/markapl-syntax/lib/Template/Declare/Buffer.pm (original)
+++ Template-Declare/branches/markapl-syntax/lib/Template/Declare/Buffer.pm Sun Feb 15 09:09:07 2009
@@ -2,33 +2,21 @@
use strict;
package Template::Declare::Buffer;
-use base 'Class::Accessor::Fast';
-__PACKAGE__->mk_accessors('data');
-
-sub append {
- no warnings 'uninitialized';
- # stringify first as it can be overloaded object
- # that changes our buffer
- my $append = "$_[1]";
- $_[0]->data( $_[0]->data . $append );
-};
-
-sub clear {
- my $self = shift;
- $self->data('');
-};
+sub new {
+ die "Template::Declare::Buffer is deprecated!";
+}
1;
__END__
=head1 NAME
-Template::Declare::Buffer - manage output buffer
+Template::Declare::Buffer - deprecated
=head1 DESCRIPTION
-We use this class to manage the output buffer used by L<Template::Declare>.
+This class is deprecated; buffers in Template::Declare are now managed by L<String::BufferStack>.
=head1 SEE ALSO
Modified: Template-Declare/branches/markapl-syntax/lib/Template/Declare/TagSet/HTML.pm
==============================================================================
--- Template-Declare/branches/markapl-syntax/lib/Template/Declare/TagSet/HTML.pm (original)
+++ Template-Declare/branches/markapl-syntax/lib/Template/Declare/TagSet/HTML.pm Sun Feb 15 09:09:07 2009
@@ -9,6 +9,7 @@
tr => 'row',
td => 'cell',
base => 'html_base',
+ q => 'quote',
);
sub get_alternate_spelling {
Modified: Template-Declare/branches/markapl-syntax/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/branches/markapl-syntax/lib/Template/Declare/Tags.pm (original)
+++ Template-Declare/branches/markapl-syntax/lib/Template/Declare/Tags.pm Sun Feb 15 09:09:07 2009
@@ -593,19 +593,12 @@
C<outs> HTML-encodes its arguments and appends them to C<Template::Declare>'s output buffer.
-
-=cut
-
-#sub outs { outs_raw( map { _postprocess($_); } grep {defined} @_ ); }
-
=head2 outs_raw STUFF
C<outs_raw> appends its arguments to C<Template::Declare>'s output buffer without doing any HTML escaping.
=cut
-#sub outs_raw { Template::Declare->buffer->append( join( '', grep {defined} @_ )); return ''; }
-
sub outs { _outs( 0, @_ ); }
sub outs_raw { _outs( 1, @_ ); }
@@ -613,11 +606,9 @@
my $raw = shift;
my @phrases = (@_);
- my $return_data = (defined wantarray and not wantarray)? 1 : 0;
- Template::Declare->new_buffer_frame if $return_data;
+ Template::Declare->buffer->push( private => (defined wantarray and not wantarray), from => "T::D outs" );
foreach my $item ( grep {defined} @phrases ) {
-
my $returned = ref($item) eq 'CODE'
? $item->()
: $raw
@@ -625,8 +616,7 @@
: _postprocess($item);
Template::Declare->buffer->append( $returned );
}
- return '' unless $return_data;
- return Template::Declare->end_buffer_frame->data;
+ return Template::Declare->buffer->pop;
}
@@ -767,9 +757,9 @@
sub smart_tag_wrapper (&) {
my $coderef = shift;
- my $buf = "\n";
- Template::Declare->new_buffer_frame;
+ Template::Declare->buffer->append("\n");
+ Template::Declare->buffer->push( from => "T::D tag wrapper");
my %attr = %ATTRIBUTES;
%ATTRIBUTES = (); # prevent leakage
@@ -778,18 +768,9 @@
map { ref($_) ? $_ : _postprocess($_) } #
$coderef->(%attr);
-
- if ( length( Template::Declare->buffer->data ) ) {
-
- # We concatenate to force scalarization when $last or
- # $Template::Declare->buffer is solely a Jifty::Web::Link
- $buf .= Template::Declare->buffer->data;
- } elsif ( length $last ) {
- $buf .= $last;
- }
-
- Template::Declare->end_buffer_frame;
- Template::Declare->buffer->append($buf);
+ my $has_content = Template::Declare->buffer->length;
+ Template::Declare->buffer->pop;
+ Template::Declare->buffer->append( "$last" ) if not $has_content and length $last;
return '';
}
@@ -808,13 +789,15 @@
$tag = $tagset->namespace . ":$tag"
if defined $tagset->namespace;
- my $buf = "\n" . ( " " x $TAG_NEST_DEPTH ) . "<$tag"
- . join( '',
- map { qq{ $_="} . ( $ATTRIBUTES{$_} || '' ) . qq{"} }
- sort keys %ATTRIBUTES );
-
- my $had_content = 0;
+ Template::Declare->buffer->append(
+ "\n"
+ . ( " " x $TAG_NEST_DEPTH ) . "<$tag"
+ . join( '',
+ map { qq{ $_="} . ( $ATTRIBUTES{$_} || '' ) . qq{"} }
+ sort keys %ATTRIBUTES )
+ );
+ my $attrs = "";
{
no warnings qw( uninitialized redefine once );
@@ -837,42 +820,30 @@
my $field = shift;
my $val = shift;
- $buf .= ' ' . $field . q{="} . _postprocess($val, 1) . q{"};
+ $attrs .= ' ' . $field . q{="} . _postprocess($val, 1) . q{"};
wantarray ? () : '';
};
local $TAG_NEST_DEPTH = $TAG_NEST_DEPTH + 1;
%ATTRIBUTES = ();
- Template::Declare->new_buffer_frame;
+ Template::Declare->buffer->push( private => 1, from => "T::D tag $tag" );
my $last = join '', map { ref($_) && $_->isa('Template::Declare::Tag') ? $_ : _postprocess($_) } $code->();
-
- if ( length( Template::Declare->buffer->data ) ) {
-
-# We concatenate to force scalarization when $last or $Template::Declare->buffer is solely a Jifty::Web::Link
- $buf .= '>' . Template::Declare->buffer->data;
- $had_content = 1;
- } elsif ( length $last ) {
- $buf .= '>' . $last;
- $had_content = 1;
- } else {
- $had_content = 0;
- }
-
- Template::Declare->end_buffer_frame;
-
+ Template::Declare->buffer->append("$last") if not Template::Declare->buffer->length and length $last;
}
+ my $content = Template::Declare->buffer->pop;
+ Template::Declare->buffer->append($attrs);
- if ($had_content) {
- $buf .= "\n" . ( " " x $TAG_NEST_DEPTH ) if ( $buf =~ /\>$/ );
- $buf .= "</$tag>";
+ if (length $content) {
+ Template::Declare->buffer->append(">$content");
+ Template::Declare->buffer->append("\n" . ( " " x $TAG_NEST_DEPTH )) if $content =~ /\</;
+ Template::Declare->buffer->append("</$tag>");
} elsif ( $tagset->can_combine_empty_tags($tag) ) {
- $buf .= " />";
+ Template::Declare->buffer->append(" />");
} else {
# Otherwise we supply a closing tag.
- $buf .= "></$tag>";
+ Template::Declare->buffer->append("></$tag>");
}
- Template::Declare->buffer->append($buf);
return ( ref($more_code) && $more_code->isa('CODE') )
? $more_code->()
: '';
@@ -904,7 +875,7 @@
# if we're inside a template, we should show private templates
if ( caller->isa('Template::Declare') ) {
- _show_template( $template, 1, \@_ );
+ _show_template( $template, 1, \@_ );
return Template::Declare->buffer->data;
} else {
show_page( $template, @_);
@@ -912,47 +883,48 @@
}
-
-
sub show_page {
- my $template = shift;
+ my $template = shift;
my $args = \@_;
- my $return_data = defined wantarray();
-
- # if we're inside a template, we should show private templates
- Template::Declare->new_buffer_frame if $return_data;
- _show_template( $template, 0, $args );
- %ELEMENT_ID_CACHE = (); # We're done. we can clear the cache
- return undef unless $return_data;
-
- return Template::Declare->end_buffer_frame->data;
+ if (defined wantarray) {
+ Template::Declare->buffer->push( private => 1, from => "T::D path $template" );
+ _show_template( $template, 0, $args );
+ %ELEMENT_ID_CACHE = ();
+ return Template::Declare->buffer->pop;
+ } else {
+ Template::Declare->buffer->push( from => "T::D path $template" );
+ _show_template( $template, 0, $args );
+ %ELEMENT_ID_CACHE = ();
+ Template::Declare->buffer->pop;
+ return undef;
+ }
}
-sub _resolve_relative_template_path {
+sub _resolve_template_path {
my $template = shift;
- return $template if ( $template =~ '^\/' );
- my $parent = current_template();
-
- my @parent = split( '/', $parent );
- my @template = split( '/', $template );
-
- @template = grep { $_ !~ /^\.$/} @template; # Get rid of "." entries
-
- # Let's find out how many levels they want to pop up
- my @uplevels = grep { /^\.\.$/ } @template;
- @template = grep { $_ !~ /^\.\.$/ } @template;
-
-
+ my @parts;
+ if ( substr($template, 0, 1) ne '/' ) {
+ # relative
+ @parts = split '/', current_template();
+ # Get rid of the parent's template name
+ pop @parts;
+ }
- pop @parent; # Get rid of the parent's template name
- pop @parent for @uplevels;
- return (join( '/', @parent, @template ) );
+ foreach ( split '/', $template ) {
+ if ( $_ eq '..' ) {
+ pop @parts;
+ }
+ # Get rid of "." and empty entries by the way
+ elsif ( $_ ne '.' && $_ ne '' ) {
+ push @parts, $_;
+ }
+ }
+ return join '/', @parts;
}
-
=head2 current_template
Returns the absolute path of the current template
@@ -968,9 +940,8 @@
my $template = shift;
my $inside_template = shift;
my $args = shift;
- local @TEMPLATE_STACK = @TEMPLATE_STACK;
- $template = _resolve_relative_template_path($template);
- push @TEMPLATE_STACK, $template;
+ $template = _resolve_template_path($template);
+ local @TEMPLATE_STACK = (@TEMPLATE_STACK, $template);
my $callable =
( ref($template) && $template->isa('Template::Declare::Tag') )
@@ -1112,11 +1083,10 @@
my $self = shift;
if ( defined wantarray ) {
- Template::Declare->new_buffer_frame;
+ Template::Declare->buffer->push( private => 1, from => "T::D stringify" );
my $returned = $self->();
- return (Template::Declare->end_buffer_frame->data . $returned);
+ return Template::Declare->buffer->pop . $returned;
} else {
-
return $self->();
}
}
Modified: Template-Declare/branches/markapl-syntax/t/private.t
==============================================================================
--- Template-Declare/branches/markapl-syntax/t/private.t (original)
+++ Template-Declare/branches/markapl-syntax/t/private.t Sun Feb 15 09:09:07 2009
@@ -84,7 +84,7 @@
{ $simple = ( Template::Declare->show('private-content') ); }
qr/could not be found.*private/,
"got warning";
- is($simple, undef);
+ is($simple, '');
}
Modified: Template-Declare/branches/markapl-syntax/t/relative-pathing.t
==============================================================================
--- Template-Declare/branches/markapl-syntax/t/relative-pathing.t (original)
+++ Template-Declare/branches/markapl-syntax/t/relative-pathing.t Sun Feb 15 09:09:07 2009
@@ -29,11 +29,17 @@
div { outs( 'This is a template local to ' . __PACKAGE__ ) };
};
+# test '..' inside template name, not leading, may be it's rare, but people
+# do crazy things
+template 'up_level_inside/test' => sub { show('local/../local') };
+template 'up_level_inside/local' => sub { div { "This is up_level_inside/local" } };
+
+
package main;
use Template::Declare::Tags;
Template::Declare->init( roots => ['Wifty::UI'] );
-use Test::More tests => 23;
+use Test::More tests => 25;
ok( Wifty::UI::aliased_pkg->has_template('local') );
ok( Wifty::UI->has_template('local') );
@@ -63,4 +69,14 @@
like( $simple, qr'Wifty::UI', 'Correct package for '.$template);
}
+{
+ my $simple = ( show('up_level_inside/test') );
+ like( $simple, qr{This is up_level_inside/local} );
+}
+
+{
+ my $simple = ( show('/up_level_inside/any/../local') );
+ like( $simple, qr{This is up_level_inside/local} );
+}
+
1;
Modified: Template-Declare/branches/markapl-syntax/t/subclassing.t
==============================================================================
--- Template-Declare/branches/markapl-syntax/t/subclassing.t (original)
+++ Template-Declare/branches/markapl-syntax/t/subclassing.t Sun Feb 15 09:09:07 2009
@@ -78,8 +78,8 @@
{ $simple = ( show('does_not_exist') ); }
qr/could not be found.*private/,
"got warning";
- unlike( ($simple||'') , qr'This is my content' );
- is ($simple,undef);
+ unlike( $simple , qr'This is my content' );
+ is ($simple,'');
}
{
More information about the Jifty-commit
mailing list