Permalink
Browse files

add a params "variable" that acts like the param tag

  • Loading branch information...
1 parent 22b20d7 commit ac5f7d51e84f5613eea6febdf79b213e6d63a69e @tonycoz committed Feb 25, 2013
View
@@ -348,6 +348,7 @@ site/cgi-bin/modules/Squirrel/Template/Expr/WrapClass.pm
site/cgi-bin/modules/Squirrel/Template/Expr/WrapCode.pm
site/cgi-bin/modules/Squirrel/Template/Expr/WrapHash.pm
site/cgi-bin/modules/Squirrel/Template/Expr/WrapScalar.pm
+site/cgi-bin/modules/Squirrel/Template/Params.pm
site/cgi-bin/modules/Squirrel/Template/Parser.pm
site/cgi-bin/modules/Squirrel/Template/Processor.pm
site/cgi-bin/modules/Squirrel/Template/Tokenizer.pm
@@ -6,6 +6,7 @@ use Squirrel::Template::Parser;
use Squirrel::Template::Deparser;
use Squirrel::Template::Processor;
use Squirrel::Template::Expr;
+use Squirrel::Template::Params;
use constant MAX_SCOPES => 50;
@@ -19,7 +20,7 @@ BEGIN {
use constant DEBUG_GET_PARMS => 0;
-our $VERSION = "1.023";
+our $VERSION = "1.024";
my %compile_cache;
@@ -509,7 +510,12 @@ sub replace {
local $self->{scopes} = [];
push @{$self->{scopes}}, $vars if $vars;
- push @{$self->{scopes}}, { globals => {} };
+ my $my_scope =
+ {
+ globals => {},
+ params => Squirrel::Template::Params->new(undef, $self, undef),
+ };
+ push @{$self->{scopes}}, $my_scope;
local $self->{scope_contexts} = [];
local $self->{defines} = {};
@@ -849,7 +855,9 @@ can then be replaced on each iteration.
=back
-=head1 The loop variable
+=head1 Special Variables
+
+=head2 The loop variable
Each C<.for> loop defines a C<loop> variable. If you have nested
loops, you can define an alias to the variable, eg:
@@ -905,6 +913,21 @@ list - the list argument to C<.for>.
=back
+=head2 params
+
+This is set to the names and values supplied in a C<wrap> request, so:
+
+ <:= param.name :>
+
+is equivalent to:
+
+ <: param name :>
+
+=head2 globals
+
+C<globals> provides a top-level hash to fill as required. This can be
+used to pass information from an inner-scope back to an outer scope.
+
=head1 OLD TEMPLATE SYNTAX
This is the older template syntax that is retained for compatibility.
@@ -0,0 +1,23 @@
+package Squirrel::Template::Params;
+use strict;
+use base "Squirrel::Template::Expr::WrapBase";
+use Scalar::Util ();
+
+our $VERSION = "1.000";
+
+sub new {
+ my ($class, @rest) = @_;
+
+ my $self = $class->SUPER::new(@rest);
+ Scalar::Util::weaken($self->[1]);
+
+ return $self;
+}
+
+sub call {
+ my ($self, $method, $args) = @_;
+
+ return $self->[1]->tag_param($method);
+}
+
+1;
@@ -97,11 +97,13 @@ TEMPLATE
<:wrap wraptest.tmpl title=>[cat "foo " [str]], menu => 1, showtitle => "abc" :>Alpha
<:param menu:>
<:param showtitle:>
+<:= params.showtitle :>
TEMPLATE
<title>foo ABC</title>
Alpha
1
abc
+abc
OUTPUT
template_test(<<TEMPLATE, <<OUTPUT, "wrap", \%acts, "both");

0 comments on commit ac5f7d5

Please sign in to comment.