You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axkit-dev@xml.apache.org by ma...@apache.org on 2003/07/10 11:50:06 UTC

cvs commit: xml-axkit/lib/Apache/AxKit/Language XSP.pm

matts       2003/07/10 02:50:06

  Modified:    lib/Apache/AxKit/Language XSP.pm
  Log:
  Added attribute-value-interpolate stuff
  Fixed pod to be a bit simpler/cleaner.
  
  Revision  Changes    Path
  1.42      +69 -12    xml-axkit/lib/Apache/AxKit/Language/XSP.pm
  
  Index: XSP.pm
  ===================================================================
  RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Language/XSP.pm,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- XSP.pm	18 Jun 2003 14:11:56 -0000	1.41
  +++ XSP.pm	10 Jul 2003 09:50:06 -0000	1.42
  @@ -681,6 +681,17 @@
           if (exists $attribs{'base-class'}) {
               $e->{XSP_Base_Class} = $attribs{'base-class'};
           }
  +        if (my $i = lc $attribs{'attribute-value-interpolate'}) {
  +            if ($i eq 'no') {
  +                $e->{XSP_No_Attr_Interpolate} = 1;
  +            }
  +            elsif ($i eq 'yes') {
  +                $e->{XSP_No_Attr_Interpolate} = 0;
  +            }
  +            else {
  +                die "Unknown value for attribute-value-interpolate: $i";
  +            }
  +        }
       }
       elsif ($tag eq 'structure') {
       }
  @@ -832,6 +843,43 @@
   
   *makeSingleQuoted = \&Apache::AxKit::Language::XSP::makeSingleQuoted;
   
  +sub _undouble_curlies {
  +    my $value = shift;
  +    $value =~ s/\{\{/\{/g;
  +    $value =~ s/\}\}/\}/g;
  +    return $value;
  +}
  +
  +sub _attr_value_template {
  +    my ($e, $value) = @_;
  +    if ($e->{XSP_No_Attr_Interpolate}) {
  +        return makeSingleQuoted($value);
  +    }
  +    # warn("Transforming: '$value'\n");
  +    return makeSingleQuoted($value) unless $value =~ /{/;
  +    my $output = "''";
  +    while ($value =~ /\G([^{]*){/gc) {
  +        $output .= "." . makeSingleQuoted(_undouble_curlies($1)) if $1;
  +        if ($value =~ /\G{/gc) {
  +            $output .= ".q|{|";
  +            next;
  +        }
  +        # otherwise we're in code now...
  +        $output .= ".do{";
  +        while ($value =~ /\G([^}]*)}/gc) {
  +            $output .= _undouble_curlies($1);
  +            if ($value =~ /\G}/gc) {
  +                $output .= "}";
  +                next;
  +            }
  +            $output .= "}";
  +        }
  +    }
  +    $value =~ /\G(.*)$/gc and $output .= "." . makeSingleQuoted(_undouble_curlies($1));
  +    # warn("Changed to: $output\n");
  +    return $output;
  +}
  +
   sub start_element {
       my ($e, $node) = @_;
   
  @@ -888,8 +936,9 @@
       }
   
       for my $attr (@{$node->{Attributes}}) {
  +        my $value = _attr_value_template($e, $attr->{Value});
           $code .= '$parent->setAttribute('.makeSingleQuoted($attr->{Name}).
  -                ','.makeSingleQuoted($attr->{Value}).");\n";
  +                ",$value);\n";
       }
   
       for my $ns (keys %{$e->{Current_NS}}) {
  @@ -1254,7 +1303,7 @@
   
   =head1 Tag Reference
   
  -=head2 C<<xsp:page>>
  +=head2 C<< <xsp:page> >>
   
   This is the top level element, although it does not have to be. AxKit's
   XSP implementation can process XSP pages even if the top level element
  @@ -1269,7 +1318,15 @@
   this feature, or it creates invalid output, then you can add the
   attribute: C<indent-result="yes">
   
  -=head2 C<<xsp:structure>>
  +By default all non-XSP and non-taglib attributes are interpolated in
  +a similar way to XSLT attributes - by checking for C<{ code }> in the
  +attributes. The C<code> can be any perl code, and is treated exactly
  +the same as having an C<< <xsp:expr>code</xsp:expr> >> in the
  +attribute value. In order to turn this I<off>, simply specify the
  +attribute C<attribute-value-interpolate="no">. The default is C<yes>
  +which enables the interpolation.
  +
  +=head2 C<< <xsp:structure> >>
   
     parent: <xsp:page>
   
  @@ -1277,7 +1334,7 @@
   tags. It defines page-global "things" in the C<<xsp:logic>> and
   C<<xsp:import>> tags.
   
  -=head2 C<<xsp:import>>
  +=head2 C<< <xsp:import> >>
   
     parent: <xsp:structure>
   
  @@ -1287,7 +1344,7 @@
       <xsp:import>DBI</xsp:import>
     </xsp:structure>
   
  -=head2 C<<xsp:logic>>
  +=head2 C<< <xsp:logic> >>
   
     parent: <xsp:structure>, any
   
  @@ -1330,7 +1387,7 @@
   
   The reason is that XSP intrinsically knows about XML!
   
  -=head2 C<<xsp:content>>
  +=head2 C<< <xsp:content> >>
   
     parent: <xsp:logic>
   
  @@ -1347,32 +1404,32 @@
       }
     </xsp:logic>
   
  -=head2 C<<xsp:element>>
  +=head2 C<< <xsp:element> >>
   
   This tag generates an element of name equal to the value in the attribute
   C<name>. Alternatively you can use a child element C<<xsp:name>> to specify
   the name of the element. Text contents of the C<<xsp:element>> are created
   as text node children of the new element.
   
  -=head2 C<<xsp:attribute>>
  +=head2 C<< <xsp:attribute> >>
   
   Generates an attribute. The name of the attribute can either be specified
   in the C<name="..."> attribute, or via a child element C<<xsp:name>>. The
   value of the attribute is the text contents of the tag.
   
  -=head2 C<<xsp:comment>>
  +=head2 C<< <xsp:comment> >>
   
   Normally XML comments are stripped from the output. So to add one back in
   you can use the C<<xsp:comment>> tag. The contents of the tag are the
   value of the comment.
   
  -=head2 C<<xsp:text>>
  +=head2 C<< <xsp:text> >>
   
   Create a plain text node. The contents of the tag are the text node to be
   generated. This is useful when you wish to just generate a text node while
   in an C<<xsp:logic>> section.
   
  -=head2 C<<xsp:expr>>
  +=head2 C<< <xsp:expr> >>
   
   This is probably the most useful, and most important (and also the most
   complex) tag. An expression is some perl code that executes, and the results