[Jifty-commit] r2467 - in Template-Declare: lib/Template
lib/Template/Declare
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Jan 5 01:03:23 EST 2007
Author: jesse
Date: Fri Jan 5 01:03:22 2007
New Revision: 2467
Modified:
Template-Declare/ (props changed)
Template-Declare/lib/Template/Declare.pm
Template-Declare/lib/Template/Declare/Tags.pm
Log:
r46767 at pinglin: jesse | 2007-01-05 01:02:30 -0500
* Importing semantics deployed
Modified: Template-Declare/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/lib/Template/Declare.pm (original)
+++ Template-Declare/lib/Template/Declare.pm Fri Jan 5 01:03:22 2007
@@ -7,10 +7,13 @@
use base 'Class::Data::Inheritable';
__PACKAGE__->mk_classdata('roots');
-__PACKAGE__->mk_classdata('imported_paths');
+__PACKAGE__->mk_classdata('templates');
+__PACKAGE__->mk_classdata('private_templates');
+
__PACKAGE__->roots([]);
-__PACKAGE__->imported_paths({});
+__PACKAGE__->templates({});
+__PACKAGE__->private_templates({});
$Template::Declare::VERSION = "0.00_01";
@@ -60,13 +63,37 @@
}
+=head2 import
+
+
+ import Wifty::UI::something under '/something';
+
+
+=cut
+
-sub import { return undef if $_[0] eq 'Template::Declare';
- my $pkg = caller(0);
- warn "$pkg";
- __PACKAGE__->imported_paths({$pkg}->{$_[1]} = $_[0]);
+sub import {
+ return undef if $_[0] eq 'Template::Declare';
+ my $import_into = caller(0);
+ my $import_from = shift;
+ my $prepend_path = shift;
+
+ foreach my $template_name ( @{ __PACKAGE__->templates()->{$import_from} } ) {
+ $import_into->register_template(
+ $prepend_path."/".$template_name,
+ $import_from->_find_template_sub(
+ _template_name_to_sub($template_name)
+ )
+ );
+ }
+ foreach my $template_name ( @{ __PACKAGE__->private_templates()->{$import_from} } ) {
+ my $code = $import_from->_find_template_sub( _template_name_to_private_sub($template_name));
+ warn "HEY NO CODE FOR private template $template_name in $import_from" unless ($code);
+ $import_into->register_private_template(
+ $prepend_path."/".$template_name, $code
+ );
+ }
- warn "$pkg: Importing ".$_[0] . " under ". $_[1];
}
@@ -126,4 +153,36 @@
$template =~ s{/+}{/}g;
return join ('', $prefix,$template);
}
+
+
+sub register_template {
+ my $class = shift;
+ my $template_name = shift;
+ my $code = shift;
+ push @{ __PACKAGE__->templates()->{$class} }, $template_name;
+ _register_template( $class,
+ _template_name_to_sub($template_name), $code )
+
+}
+
+sub register_private_template {
+ my $class = shift;
+ my $template_name = shift;
+ my $code = shift;
+ push @{ __PACKAGE__->private_templates()->{$class} }, $template_name;
+ _register_template( $class, _template_name_to_private_sub($template_name),
+ $code );
+
+}
+
+sub _register_template {
+ my $self = shift;
+ my $class = ref($self) || $self;
+ my $subname = shift;
+ my $coderef = shift;
+ no strict 'refs';
+ *{ $class . '::' . $subname } = $coderef;
+}
+
+
1;
Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm (original)
+++ Template-Declare/lib/Template/Declare/Tags.pm Fri Jan 5 01:03:22 2007
@@ -8,29 +8,30 @@
use Carp;
@EXPORT =
- qw( with template private show get_current_attr attr outs outs_raw in_isolation $self under
- Tr td ); # these two warns the user to use row/cell instead
-
-
-sub under ($) { return shift }
+ qw( with template private show get_current_attr attr outs outs_raw in_isolation $self under
+ Tr td ); # these two warns the user to use row/cell instead
+sub under ($) { return shift }
our $DEPTH = 0;
our %ATTRIBUTES = ();
our $BUFFER = '';
sub Tr (&) {
- die "Tr {...} and td {...} are invalid; use row {...} and cell {...} instead.";
+ die
+ "Tr {...} and td {...} are invalid; use row {...} and cell {...} instead.";
}
sub td (&) {
- die "Tr {...} and td {...} are invalid; use row {...} and cell {...} instead.";
+ die
+ "Tr {...} and td {...} are invalid; use row {...} and cell {...} instead.";
}
sub attr (&;$) {
- my ($code, $out) = @_;
+ my ( $code, $out ) = @_;
my @rv = $code->();
- while (my ($field, $val) = splice(@rv, 0, 2)) {
+ while ( my ( $field, $val ) = splice( @rv, 0, 2 ) ) {
+
# only defined whle in a tag context
append_attr( $field, $val );
}
@@ -38,11 +39,12 @@
}
sub outs_raw {
- $BUFFER .= join( '', grep { defined } @_ );
+ $BUFFER .= join( '', grep {defined} @_ );
return '';
}
+
sub outs {
- $BUFFER .= join( '', map { _escape_utf8($_);} grep { defined } @_ );
+ $BUFFER .= join( '', map { _escape_utf8($_); } grep {defined} @_ );
return '';
}
@@ -63,30 +65,28 @@
if (wantarray) {
return ( $template_class, $template_name, $codesub );
} else {
- *{ $template_class . '::' . Template::Declare::_template_name_to_sub($template_name); } = $codesub;
+ Template::Declare::register_template( $template_class, $template_name,
+ $codesub );
}
}
sub private (@) {
- my $class = shift;
+ my $class = shift;
my $subname = shift;
- my $code = shift;
- {
- no strict 'refs';
- *{ $class .'::' . Template::Declare::_template_name_to_private_sub($subname); } = $code;
- }
+ my $code = shift;
+ Template::Declare::register_private_template( $class, $subname, $code );
}
sub get_current_attr ($) {
$ATTRIBUTES{ $_[0] };
}
-
our %TagAlternateSpelling = (
- tr => 'row',
- td => 'cell',
- base => '', # Currently 'base' has no alternate spellings; simply ignore it
+ tr => 'row',
+ td => 'cell',
+ base =>
+ '', # Currently 'base' has no alternate spellings; simply ignore it
);
sub install_tag {
@@ -103,17 +103,17 @@
no warnings 'redefine';
*$name = sub (&;$) {
local *__ANON__ = $tag;
- if (defined wantarray and not wantarray) {
+ if ( defined wantarray and not wantarray ) {
+
# Scalar context - return a coderef that represents ourselves.
- my @__ = @_;
+ my @__ = @_;
my $_self = $self;
sub {
- local $self = $_self;
+ local $self = $_self;
local *__ANON__ = $tag;
_tag(@__);
};
- }
- else {
+ } else {
_tag(@_);
}
};
@@ -122,13 +122,13 @@
use CGI ();
our %TAGS = (
map { $_ => +{} }
- map { @$_ } @CGI::EXPORT_TAGS{qw/:html2 :html3 :html4 :netscape :form/}
+ map {@$_} @CGI::EXPORT_TAGS{qw/:html2 :html3 :html4 :netscape :form/}
);
install_tag($_) for keys %TAGS;
sub with (@) {
%ATTRIBUTES = ();
- while (my ($key, $val) = splice(@_, 0, 2)) {
+ while ( my ( $key, $val ) = splice( @_, 0, 2 ) ) {
no warnings 'uninitialized';
$ATTRIBUTES{$key} = $val;
}
@@ -195,7 +195,7 @@
wantarray ? () : '';
};
- my $last = join '',map{ ref($_) ? $_ : _escape_utf8($_) } $code->();
+ my $last = join '', map { ref($_) ? $_ : _escape_utf8($_) } $code->();
if ( length($BUFFER) ) {
@@ -263,8 +263,10 @@
if ( ref($template) eq 'CODE' ) {
$callable = $template;
} else {
+
# if we're inside a template, we should show private templates
- $callable = Template::Declare->has_template( $template, $INSIDE_TEMPLATE );
+ $callable = Template::Declare->has_template( $template,
+ $INSIDE_TEMPLATE );
}
# may want to just use the return value of has_template eventually
@@ -280,7 +282,7 @@
}
sub _escape_utf8 {
- my $val =shift;
+ my $val = shift;
use bytes;
no warnings 'uninitialized';
$val =~ s/&/&/g;
More information about the Jifty-commit
mailing list