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 jw...@axkit.org on 2003/06/18 15:42:22 UTC

CVS update: AxKit-XSP-Util

Date:	Wednesday June 18, 2003 @ 13:43
Author:	jwalt

Update of /home/cvs/AxKit-XSP-Util
In directory localhost:/tmp/cvs-serv26009

Modified Files:
	Util.pm 
Log Message:
- add include-html-expr tag


Index: Util.pm
===================================================================
RCS file: /home/cvs/AxKit-XSP-Util/Util.pm,v
retrieving revision 1.17
retrieving revision 1.18
diff -b -u -r1.17 -r1.18
--- Util.pm	2003/01/20 16:19:32	1.17
+++ Util.pm	2003/06/18 12:43:22	1.18
@@ -1,4 +1,4 @@
-# $Id: Util.pm,v 1.17 2003/01/20 16:19:32 matt Exp $
+# $Id: Util.pm,v 1.18 2003/06/18 12:43:22 jwalt Exp $
 
 package AxKit::XSP::Util;
 use strict;
@@ -78,6 +78,22 @@
     }
 }
 
+# insert from a SCALAR
+sub include_html_expr {
+    my ($document, $parent, $frag) = @_;
+    if ($frag || $frag == 0) {
+        my $doc = XML::LibXML->new()->parse_html_string( AxKit::FromUTF8("<html>$frag</html>") ); 
+        if ($doc) {
+            my $root = $doc->getDocumentElement();
+            $root = $document->importNode($root);
+            $parent->appendChild($root);
+        }
+        else {
+            die "Couldn't load or parse expression results";
+        }
+    }
+}
+
 # insert from a local file as plain text
 sub get_file_contents {
     my ($filename) = @_;
@@ -168,6 +184,9 @@
     elsif ($tag eq 'include-expr') {
         return '{ my $_expression = ""'; 
     }
+    elsif ($tag eq 'include-html-expr') {
+        return '{ my $_expression = ""'; 
+    }
     elsif ($tag eq 'name') {
         return '$_file_name = ""';
     }
@@ -197,6 +216,11 @@
         '$document, $parent, $_expression' .
         ");}\n";
     }
+    elsif ($tag eq 'include-html-expr') {
+        return ";\nAxKit::XSP::Util::include_html_expr(\n" .
+        '$document, $parent, $_expression' .
+        ");}\n";
+    }
     elsif ($tag eq 'from-external-encoding') {
         $e->append_to_script(')');
         $e->end_expr();
@@ -311,6 +335,17 @@
     <util:include-expr>
     <xsp:expr>$xml_fragment</xsp:expr>
     </util:include-expr>
+
+=head2 C<<util:include-html-expr>>
+
+Provides a way to include an HTML fragment from a scalar variable. Note
+that this tag may B<only> pass the required  B<expr> argument as a
+child node. The HTML fragment need not be well-formed or valid in any way.
+libxml will try to make the best of anything passed in. Example: 
+
+    <util:include-html-expr>
+    <xsp:expr>$html_fragment</xsp:expr>
+    </util:include-html-expr>
 
 =head2 C<<util:time>>