Skip to content

Commit

Permalink
* The great tag breakout!
Browse files Browse the repository at this point in the history
	* Almost all tags are now UserTag definitions. The only exceptions
	  are:

		and bounce goto if label or unless

    * New TagDir directive (default is VENDROOT/code) sets the
	  directory (or directories) which are searched for code definitions
	  set by UserTag and CodeDef.

	* New TagGroup directive establishes groups of ITL tags which can
	  be included.

	  	TagGroup :crufty "banner default ecml html_table onfly sql"

	  The default groups include :core, which contains all of the
	  ITL tags defined in 4.8/early 4.9. The groups are defined
	  in $Vend::Cfg::StdTags and can be undefined if desired
	  with "TagGroup :group".

	* New TagInclude directive allows inclusion of tags (or groups
	  of tags). If a tag is defined as a core tag (with a .coretag
	  or .tag or .ct extension) and is not included, it will not
	  be compiled and placed in the tag map. This is for all catalogs,
	  so if *any* catalog uses a tag it must be included.

	  Examples:

		# Include the base tags
	  	TagInclude :core

		# Not the commerce tags
		TagInclude !:commerce

		# But make sure item-list is included even though
		# it is in :commerce
		TagInclude item-list

		## Double negatives are honored
		TagGroup    :foo "bar !baz buz"
		## With the group above, the below is equivalent
		## to TagInclude !bar baz !buz
		TagInclude !:foo

    * New CodeDef directive allows the setting of filters,
	  order checks, FormAction, ActionMap, ItemAction,
	  and LocaleChange.

			## filters
			CodeDef  mixedcase Filter
			CodeDef  mixedcase Routine <<EOR
			sub {
				my $val = shift;
				## [filter mixedcase]mixed case[/filter]
				## outputs "MiXeD CaSe"
				$val =~ s/(.)(.)/\u$1\l$2/g;
				return $val;
			}
			EOR

			## order checks
			CodeDef  mixedcase OrderCheck
			CodeDef  foo  Routine <<EOR
			sub {
				my ($ref, $var, $val) = @_;
				return (1,$var) if $val eq 'bar';
				return (0,$var, "foo must be bar");
			}
			EOR

	   All work in catalog.cfg; LocaleChange and ItemAction are not
	   global. FormAction, ActionMap, and ItemAction directives
	   are equivalent to their CodeDef equivalents.
  • Loading branch information
perusionmike committed Jan 29, 2002
1 parent fccf511 commit 8f219b4
Show file tree
Hide file tree
Showing 182 changed files with 10,924 additions and 1,893 deletions.
6 changes: 6 additions & 0 deletions code/ActionMap/foo.am
@@ -0,0 +1,6 @@
CodeDef foo ActionMap
CodeDef foo Routine <<EOR
sub {
$CGI->{mv_nextpage} = 'aboutus';
}
EOR
7 changes: 7 additions & 0 deletions code/Filter/lc.filter
@@ -0,0 +1,7 @@
CodeDef lc Filter
CodeDef lc Routine <<EOR
sub {
use locale;
return lc(shift);
}
EOR
11 changes: 11 additions & 0 deletions code/SystemTag/accessories.coretag
@@ -0,0 +1,11 @@
UserTag accessories Order code arg
UserTag accessories addAttr
UserTag accessories attrAlias db table
UserTag accessories attrAlias base table
UserTag accessories attrAlias database table
UserTag accessories attrAlias col column
UserTag accessories attrAlias row code
UserTag accessories attrAlias field column
UserTag accessories attrAlias key code
UserTag accessories PosNumber 2
UserTag accessories MapRoutine Vend::Interpolate::tag_accessories
7 changes: 7 additions & 0 deletions code/SystemTag/area.coretag
@@ -0,0 +1,7 @@
UserTag area Order href arg
UserTag area addAttr
UserTag area Implicit secure secure
UserTag area PosNumber 2
UserTag area replaceAttr form action
UserTag area replaceAttr a href
UserTag area MapRoutine Vend::Interpolate::tag_area
36 changes: 36 additions & 0 deletions code/SystemTag/assign.coretag
@@ -0,0 +1,36 @@
UserTag assign addAttr
UserTag assign PosNumber 0
UserTag assign Routine <<EOR
my %_assignable = (qw/
salestax 1
shipping 1
handling 1
subtotal 1
/);
sub {
my ($opt) = @_;
if($opt->{clear}) {
delete $Vend::Session->{assigned};
return;
}
$Vend::Session->{assigned} ||= {};
for(keys %$opt) {
next unless $_assignable{$_};
my $value = $opt->{$_};
$value =~ s/^\s+//;
$value =~ s/\s+$//;
if($value =~ /^-?\d+\.?\d*$/) {
$Vend::Session->{assigned}{$_} = $value;
}
else {
logError(
"Attempted assign of non-numeric '%s' to %s. Deleted.",
$value,
$_,
);
delete $Vend::Session->{assigned}{$_};
}
}
return;
}
EOR
4 changes: 4 additions & 0 deletions code/SystemTag/attr_list.coretag
@@ -0,0 +1,4 @@
UserTag attr-list Order hash
UserTag attr-list hasEndTag
UserTag attr-list PosNumber 1
UserTag attr-list MapRoutine Vend::Interpolate::tag_attr_list
72 changes: 72 additions & 0 deletions code/SystemTag/banner.coretag
@@ -0,0 +1,72 @@
UserTag banner Order category
UserTag banner addAttr
UserTag banner PosNumber 1
UserTag banner Routine <<EOR
sub {
my ($place, $opt) = @_;

sub tag_weighted_banner {
my ($category, $opt) = @_;
my $dir = catfile($Vend::Cfg->{ScratchDir}, 'Banners');
mkdir $dir, 0777 if ! -d $dir;
if($category) {
my $c = $category;
$c =~ s/\W//g;
$dir .= "/$c";
}
my $statfile = $Vend::Cfg->{ConfDir};
$statfile .= "/status.$Vend::Cat";
my $start_time;
if($opt->{once}) {
$start_time = 0;
}
elsif(! -f $statfile) {
Vend::Util::writefile( $statfile, "banners initialized " . time() . "\n");
$start_time = time();
}
else {
$start_time = (stat(_))[9];
}
my $weight_file = "$dir/total_weight";
initialize_banner_directory($dir, $category, $opt)
if (
! -f $weight_file
or
(stat(_))[9] < $start_time
);
my $n = int( rand( readfile($weight_file) ) );
return Vend::Util::readfile("$dir/$n");
}
return tag_weighted_banner($place, $opt) if $opt->{weighted};

my $table = $opt->{table} || 'banner';
my $r_field = $opt->{r_field} || 'rotate';
my $b_field = $opt->{b_field} || 'banner';
my $sep = $opt->{separator} || ':';
my $delim = $opt->{delimiter} || "{or}";
$place = 'default' if ! $place;
my $totrot;
do {
my $banner_data;
$totrot = tag_data($table, $r_field, $place);
if(! length $totrot) {
# No banner present
unless ($place =~ /$sep/ or $place eq 'default') {
$place = 'default';
redo;
}
}
elsif ($totrot) {
my $current = $::Scratch->{"rotate_$place"}++ || 0;
my $data = tag_data($table, $b_field, $place);
my(@banners) = split /\Q$delim/, $data;
return '' unless @banners;
return $banners[$current % scalar(@banners)];
}
else {
return tag_data($table, $b_field, $place);
}
} while $place =~ s/(.*)$sep.*/$1/;
return;
}
EOR
3 changes: 3 additions & 0 deletions code/SystemTag/calc.coretag
@@ -0,0 +1,3 @@
UserTag calc hasEndTag
UserTag calc Interpolate
UserTag calc MapRoutine Vend::Interpolate::tag_calc
4 changes: 4 additions & 0 deletions code/SystemTag/cart.coretag
@@ -0,0 +1,4 @@
UserTag cart Order name
UserTag cart InvalidateCache
UserTag cart PosNumber 1
UserTag cart MapRoutine Vend::Interpolate::tag_cart
52 changes: 52 additions & 0 deletions code/SystemTag/catch.coretag
@@ -0,0 +1,52 @@
UserTag catch Order label
UserTag catch addAttr
UserTag catch hasEndTag
#UserTag catch Test <<EOT
#EOT
UserTag catch Routine <<EOR
sub {
my ($label, $opt, $body) = @_;
$label = 'default' unless $label;
my $patt;
return pull_else($body)
unless $patt = $Vend::Session->{try}{$label};

$body = pull_if($body);

if ( $opt->{exact} ) {
#----------------------------------------------------------------
# Convert multiple errors to 'or' list and compile it.
# Note also the " at (eval ...)" kludge to strip the line numbers
$patt =~ s/(?: +at +\(eval .+\).+)?\n\s*/|/g;
$patt =~ s/^\s*//;
$patt =~ s/\|$//;
$patt = qr($patt);
#----------------------------------------------------------------
}

my $found;
while ($body =~ s{
\[/
(.+?)
/\]
(.*?)
\[/
(?:\1)?/?
\]}{}sx ) {
my $re;
my $error = $2;
eval {
$re = qr{$1}
};
next if $@;
next unless $patt =~ $re;
$found = $error;
last;
}
$body = $found if $found;

$body =~ s/\s+$//;
$body =~ s/^\s+//;
return $body;
}
EOR
29 changes: 29 additions & 0 deletions code/SystemTag/cgi.coretag
@@ -0,0 +1,29 @@
UserTag cgi Order name
UserTag cgi addAttr
UserTag cgi InvalidateCache
UserTag cgi PosNumber 1
UserTag cgi Routine <<EOR
sub {
my($var, $opt) = @_;
my($value);

local($^W) = 0;
$CGI::values{$var} = $opt->{set} if defined $opt->{set};
$value = defined $CGI::values{$var} ? ($CGI::values{$var}) : '';
if ($value) {
# Eliminate any Interchange tags
$value =~ s~<([A-Za-z]*[^>]*\s+[Mm][Vv]\s*=\s*)~&lt;$1~g;
$value =~ s/\[/&#91;/g;
}
if($opt->{filter}) {
$value = filter_value($opt->{filter}, $value, $var);
$CGI::values{$var} = $value unless $opt->{keep};
}

return '' if $opt->{hide};

$value =~ s/</&lt;/g
unless $opt->{enable_html};
return $value;
}
EOR
5 changes: 5 additions & 0 deletions code/SystemTag/charge.coretag
@@ -0,0 +1,5 @@
UserTag charge Order route
UserTag charge addAttr
UserTag charge InvalidateCache
UserTag charge PosNumber 1
UserTag charge MapRoutine Vend::Payment::charge
31 changes: 31 additions & 0 deletions code/SystemTag/checked.coretag
@@ -0,0 +1,31 @@
UserTag checked Order name value
UserTag checked addAttr
UserTag checked Implicit multiple multiple
UserTag checked Implicit default default
UserTag checked InvalidateCache
UserTag checked PosNumber 2
UserTag checked replaceAttr input checked
UserTag checked Routine <<EOR
sub {
my ($field,$value,$opt) = @_;

$value = 'on' unless defined $value;

my $ref = $opt->{cgi} ? $CGI::values{$field} : $::Values->{$field};
return 'CHECKED' if ! length($ref) and $opt->{default};

if(! $opt->{case}) {
$ref = lc($ref);
$value = lc($value);
}

return 'CHECKED' if $ref eq $value;

if ($opt->{multiple}) {
my $regex = quotemeta $value;
return 'CHECKED' if $ref =~ /(?:^|\0)$regex(?:$|\0)/i;
}

return '';
}
EOR
35 changes: 35 additions & 0 deletions code/SystemTag/control.coretag
@@ -0,0 +1,35 @@
UserTag control Order name default
UserTag control addAttr
UserTag control PosNumber 2
UserTag control Routine <<EOR
sub {
my ($name, $default, $opt) = @_;

use vars qw/$Tmp/;

if(! $name) {
# Here we either reset the index or increment it
# Done this way for speed, no blocks to enter other than top one
if($opt->{space}) {
$::Control = $Tmp->{$opt->{space}} ||= [];
return set_tmp('control_index', 0);
}
else {
($::Scratch->{control_index} = 0, return) if $opt->{reset};
return set_tmp('control_index', ++$::Scratch->{control_index});
}
}

$name = lc $name;
$name =~ s/-/_/g;
$opt ||= {};
if (! defined $default and $opt->{set}) {
$::Control->[$::Scratch->{control_index}]{$name} = $::Scratch->{$name};
return;
}

return defined $::Control->[$::Scratch->{control_index}]{$name}
? ( $::Control->[$::Scratch->{control_index}]{$name} || $default )
: ( length($::Scratch->{$name}) ? ($::Scratch->{$name}) : $default )
}
EOR
26 changes: 26 additions & 0 deletions code/SystemTag/control_set.coretag
@@ -0,0 +1,26 @@
UserTag control-set Order index
UserTag control-set addAttr
UserTag control-set hasEndTag
UserTag control-set PosNumber 1
UserTag control-set Routine <<EOR
# Batch sets a set of controls without affecting Scratch
# Increments the index afterwards unless index is defined
sub {
my ($index, $opt, $body) = @_;

my $inc;
unless($index) {
$index = $::Scratch->{control_index} || 0;
$inc = 1;
}

while($body =~ m{\[([-\w]+)\](.*)\[/\1\]}sg) {
my $name = lc $1;
my $val = $2;
$name =~ s/-/_/g;
$::Control->[$index]{$name} = $val;
}
$::Scratch->{control_index}++;
return;
}
EOR
6 changes: 6 additions & 0 deletions code/SystemTag/counter.coretag
@@ -0,0 +1,6 @@
UserTag counter Order file
UserTag counter addAttr
UserTag counter attrAlias name file
UserTag counter InvalidateCache
UserTag counter PosNumber 1
UserTag counter MapRoutine Vend::Interpolate::tag_counter
10 changes: 10 additions & 0 deletions code/SystemTag/currency.coretag
@@ -0,0 +1,10 @@
UserTag currency Order convert noformat
UserTag currency hasEndTag
UserTag currency Interpolate
UserTag currency PosNumber 2
UserTag currency Routine <<EOR
sub {
my($convert,$noformat,$amount) = @_;
return Vend::Util::currency($amount, $noformat, $convert);
}
EOR
12 changes: 12 additions & 0 deletions code/SystemTag/data.coretag
@@ -0,0 +1,12 @@
UserTag data Order table field key
UserTag data addAttr
UserTag data attrAlias column field
UserTag data attrAlias code key
UserTag data attrAlias base table
UserTag data attrAlias database table
UserTag data attrAlias col field
UserTag data attrAlias row key
UserTag data attrAlias name field
UserTag data Implicit increment increment
UserTag data PosNumber 3
UserTag data MapRoutine Vend::Interpolate::tag_data
14 changes: 14 additions & 0 deletions code/SystemTag/default.coretag
@@ -0,0 +1,14 @@
UserTag default Order name default
UserTag default addAttr
UserTag default InvalidateCache
UserTag default PosNumber 2
UserTag default Routine <<EOR
# Returns the text of a user entered field named VAR.
# Same as tag [value name=name default="string"] except
# returns 'default' if not present
sub {
my($var, $default, $opt) = @_;
$opt->{default} = !(length $default) ? 'default' : $default;
return tag_value($var, $opt);
}
EOR
3 changes: 3 additions & 0 deletions code/SystemTag/description.coretag
@@ -0,0 +1,3 @@
UserTag description Order code base
UserTag description PosNumber 2
UserTag description MapRoutine Vend::Data::product_description

0 comments on commit 8f219b4

Please sign in to comment.