Gossamer Forum
Home : Products : Links 2.0 : Customization :

New Parse() for =~

Quote Reply
New Parse() for =~
Has anyone gotten "New Parse() for =~" to work?
(http://www.gossamer-threads.com/...es/Detailed/704.html)

There are absolutely no instructions that I can find and all I get is blank pages Pirate
Code:
=================================
___.__ ~ _____________
\ \\ \ ,, ??? | '\\\\\\
\ \\ \ /< ? | ' ____|_
--\//,- \_. /_____ | '||::::::
o- / \_/ '\ | '||_____|
| \ ' o \'________|_____|
| )- # < ___/____|___\___
`_/'------------| _ ' <<<:|
/________\| |_________'___o_o|
=================================
Quote Reply
Re: [bestfx] New Parse() for =~ In reply to
Check your error log - something may show.
Quote Reply
Re: [Paul] New Parse() for =~ In reply to
In Reply To:
Check your error log - something may show.


The error log says the img files related to the page templates do not exist even though the error link is correct for the image files Crazy :

[Mon Dec 23 23:29:44 2002] [error] [client xx.xx.xx.xxx] File does not exist: /www/b/host/htdocs/links/tpl_images/titel_o.gif"

Here is my sub parse routine from Template.pm

Code:
sub parse {
# ---------------------------------------------------------------
# Parses a template.
#
my ($self, $template) = @_;
my $begin = $self->{'begin'} || quotemeta('<%');
my $end = $self->{'end'} || quotemeta('%>');
my $root = $self->{'ROOT'};

exists $self->{'templates'}{$root}{$template} or ($self->load_template($template) or return undef);
exists $self->{'vars'} or (&error ('NONAMESPACE') and return undef);
$self->{'parsed'}{$template} = '';

my $temp = $self->{'templates'}{$root}{$template};

# Parse includes, do this first so that the includes can include
# template tags.
$temp =~ s#$begin\s*include\s*(.+?)\s*$end#
if (exists $self->{'inc'}{$root}{$1}) { $self->{'inc'}{$root}{$1}; }
else {
if (open (INC, "${$self}{'ROOT'}/$1")) {
$self->{'inc'}{$root}{$1} = join ("", <INC> );
close INC;
$self->{'inc'}{$root}{$1};
}
else {
"Can't find file: ${$self}{'ROOT'}/$1";
}
}
#goe;

# Now go line by line and strip out the unwanted stuff looking for
# if and ifnot tags.
my @lines = split /\n/, $temp;
$temp = ''; my @go = (1,1); my $depth = 1; my $line = '';

LINE: foreach $line (@lines) {
# Init the previous, variable and more strings.
my ($prev, $var, $neg, $more, $orig, $full_comp, $comp, $val) = ('', '', '', '', '', '', '', '');
my $result = 0;

# Check for if tags.
$line =~ s/((.*?)$begin\s*if(not)?\s+(.+?)(\s+(<|>|lt|gt|eq|==|=~)\s*(.+?))?$end(.*))/
# ~rl ^^ Add here
($orig, $prev, $neg, $var, $full_comp, $comp, $val, $more) = ($1, $2, $3, $4, $5, $6, $7, $8);

# We've found an if tag, let's set the depth to see whether we are in print mode or not.
if ($prev !~ m,$begin\s*endif\s*$end,og) {
$go[$depth] and ($temp .= $prev);
if (!$full_comp) {
if ($neg) { ($self->{'vars'}{$var}) ? ($go[++$depth] = 0) : ($go[++$depth] = $go[$depth]) and ""; }
else { ($self->{'vars'}{$var}) ? ($go[++$depth] = $go[$depth]) : ($go[++$depth] = 0) and ""; }
}
else {
$val =~ s,^['"],,; $val =~ s,['"]$,,;
($comp eq 'eq') and ($result = ($self->{'vars'}{$var} eq $val));
($comp eq '==') and ($result = ($self->{'vars'}{$var} == $val));
($comp eq '=~') and ($result = ($self->{'vars'}{$var} =~ $val)); # ~rl Add here
($comp eq 'lt') and ($result = ($self->{'vars'}{$var} lt $val));
($comp eq 'gt') and ($result = ($self->{'vars'}{$var} gt $val));
($comp eq '>') and ($result = ($self->{'vars'}{$var} > $val));
($comp eq '<') and ($result = ($self->{'vars'}{$var} < $val));
if ($neg) { $result ? ($go[++$depth] = 0) : ($go[++$depth] = $go[$depth]) and ""; }
else { $result ? ($go[++$depth] = $go[$depth]) : ($go[++$depth] = 0) and ""; }
}
}
else {
# Oops, there was an endif tag we missed, set the original line back and keep going.
$more = ''; $orig;
}
/oe;
if ($more) { $line = $more; redo LINE; }

# Check for endif tags.
$line =~ s/(.*?)$begin\s*endif\s*$end(.*)/
($prev, $more) = ($1, $2);
$go[$depth] and ($temp .= $prev);
$go[$depth--] = 1;
"";
/oe;
if ($more) { $line = $more; redo LINE; }

# Add the content..
$go[$depth] and ($temp .= "$line\n");
}

# Replace the special variables, we allow code ref mapping.
$temp =~ s/$begin\s*(.+?)\s*$end/
if (exists $self->{'vars'}{$1}) {
ref ($self->{'vars'}{$1}) eq 'CODE' ?
&{$self->{'vars'}{$1}}($self->{'vars'}) : $self->{'vars'}{$1};
}
else { "Unkown Tag: $1"; }
/goe;

$self->{'parsed'}{$template} = $temp;

return $self->{'parsed'}{$template};
}


And I am making my <%if statements like this:

<%if URL =~ 'somesite.com'%> Text <%endif%>

Thanking you in advance for assistance.

Wayne
Code:
=================================
___.__ ~ _____________
\ \\ \ ,, ??? | '\\\\\\
\ \\ \ /< ? | ' ____|_
--\//,- \_. /_____ | '||::::::
o- / \_/ '\ | '||_____|
| \ ' o \'________|_____|
| )- # < ___/____|___\___
`_/'------------| _ ' <<<:|
/________\| |_________'___o_o|
=================================