gwynne Sun Jul 29 09:46:39 2007 UTC Added files: (Branch: GWYNNE_PLAYS_HERE) /phd/formats phpnetchunkedreader.php
Modified files: /phd/formats xhtml.php /phd/include PhDReader.class.php Log: Commit bjori's latest onto a separate branch. The branch was created so that I could mess around with some of my ideas without interfering with the mainstream development until we'd had a chance to discuss and approve them concurrently. http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.7&r2=1.7.2.1&diff_format=u Index: phd/formats/xhtml.php diff -u phd/formats/xhtml.php:1.7 phd/formats/xhtml.php:1.7.2.1 --- phd/formats/xhtml.php:1.7 Sat Jul 28 23:58:06 2007 +++ phd/formats/xhtml.php Sun Jul 29 09:46:39 2007 @@ -1,6 +1,6 @@ <?php -/* $Id: xhtml.php,v 1.7 2007/07/28 23:58:06 gwynne Exp $ +/* $Id: xhtml.php,v 1.7.2.1 2007/07/29 09:46:39 gwynne Exp $ +-------------------------------------------------------------------------+ | Copyright(c) 2007 | | Authors: | @@ -49,16 +49,25 @@ 'orderedlist' => 'ol', 'para' => 'p', 'parameter' => 'span', + 'partintro' => 'div', 'productname' => 'span', 'propname' => 'span', 'property' => 'span', 'proptype' => 'span', + 'section' => 'div', 'simplelist' => 'ul', 'simpara' => 'p', - 'title' => 'h1', + 'title' => array( + /* DEFAULT */ 'h1', + 'refsect1' => 'h3', + 'example' => 'h4', + ), 'year' => 'span', ); - + protected $CURRENT_FUNCTION_ID = ""; + protected $CURRENT_REFERENCE_ID = ""; + protected $functionList = array(); + public function __construct( $file, $encoding = 'utf-8', $options = NULL ) { parent::__construct( $file, $encoding, $options ); } @@ -75,16 +84,29 @@ public function format_refentry( $open ) { if ( $open ) { - return '<div>'; + $this->CURRENT_FUNCTION_ID = $id = $this->getID(); + + return sprintf( '<div id="%s" class="refentry">', $id ); } + $this->CURRENT_FUNCTION_ID = ""; + return "</div>"; + } + public function format_reference( $open ) { + if ( $open ) { + $this->CURRENT_REFERENCE_ID = $id = $this->getID(); + + return sprintf( '<div id="%s" class="reference">', $id ); - echo "</div>"; - if ( $this->hasAttributes && $this->moveToAttributeNs( "id", "http://www.w3.org/XML/1998/namespace" ) ) { - $id = $this->value; } - $content = ob_get_contents(); - ob_clean(); - file_put_contents( "cache/$id.html", $content ); + $content = "</div>"; + $content .= '<ul class="funclist">'; + foreach( $this->functionList as $func => $desc ) { + $content .= sprintf( '<li><a href="function.%1$s.html" class="refentry">%1$s</a></li>', $func ); + } + $content .= "</ul>\n"; + $this->CURRENT_REFERENCE_ID = ""; + $this->functionList = array(); + return $content; } @@ -141,8 +163,26 @@ return $content; } + public function format_refnamediv( $open ) { + $root = $this->name; + + while ( $this->readNode( $root ) ) { + $name = $this->name; + switch( $name ) { + case "refname": + $refname = $this->readContent( $name ); + break; + case "refpurpose": + $refpurpose = $this->readContent( $name ); + break; + } + } + + $this->functionList[ $refname ] = $refpurpose; + return sprintf( '<div class="refnamediv"><span class="refname">%s</span><span class="refpurpose">%s</span></div>', $refname, $refpurpose ); + } - protected function transformFromMap( $open, $name ) { + protected function transormFromMap($open, $tag, $name) { $tag = $this->map[ $name ]; if($open) { http://cvs.php.net/viewvc.cgi/phd/include/PhDReader.class.php?r1=1.6&r2=1.6.2.1&diff_format=u Index: phd/include/PhDReader.class.php diff -u phd/include/PhDReader.class.php:1.6 phd/include/PhDReader.class.php:1.6.2.1 --- phd/include/PhDReader.class.php:1.6 Sat Jul 28 23:58:06 2007 +++ phd/include/PhDReader.class.php Sun Jul 29 09:46:39 2007 @@ -1,6 +1,6 @@ <?php -/* $Id: PhDReader.class.php,v 1.6 2007/07/28 23:58:06 gwynne Exp $ +/* $Id: PhDReader.class.php,v 1.6.2.1 2007/07/29 09:46:39 gwynne Exp $ +-------------------------------------------------------------------------+ | Copyright(c) 2007 | | Authors: | @@ -18,8 +18,12 @@ */ abstract class PhDReader extends XMLReader { + const XMLNS_XML = "http://www.w3.org/XML/1998/namespace"; + const XMLNS_XLINK = "http://www.w3.org/1999/xlinK"; + const XMLNS_PHD = "http://www.php.net/ns/phd"; protected $map = array(); + protected $STACK = array(); public function __construct( $file, $encoding = "utf-8", $options = NULL ) { @@ -42,15 +46,23 @@ public function seek( $id ) { while( parent::read() ) { - if ( $this->nodeType == XMLREADER::ELEMENT && $this->hasAttributes && - $this->moveToAttributeNs( "id", "http://www.w3.org/XML/1998/namespace" ) && $this->value == $id ) { + if ( $this->nodeType === XMLREADER::ELEMENT && $this->hasAttributes && + $this->moveToAttributeNs( "id", self::XMLNS_XML ) && $this->value === $id ) { return $this->moveToElement(); } } return FALSE; } - + public function getID() { + if ( $this->hasAttributes && $this->moveToAttributeNs("id", self::XMLNS_XML) ) { + $id = $this->value; + $this->moveToElement(); + return $id; + } + return ""; + } + /* Go to the next useful node in the file. */ public function nextNode() { @@ -116,7 +128,19 @@ return ""; } + public function notXPath( $tag ) { + $depth = $this->depth; + do { + if ( isset( $tag[ $this->STACK[ --$depth ] ] ) ) { + $tag = $tag[ $this->STACK[ $depth ] ]; + } else { + $tag = $tag[0]; + } + } while ( is_array( $tag ) ); + return $tag; + } + /* Perform a transformation. */ public function transform() { @@ -126,11 +150,21 @@ switch( $type ) { case XMLReader::ELEMENT: + $this->STACK[ $this->depth ] = $name; + case XMLReader::END_ELEMENT: - if( isset( $this->map[ $name ] ) ) { - return $this->transformFromMap( $type == XMLReader::ELEMENT, $name ); - } - return call_user_func( array( $this, "format_${name}" ), $type == XMLReader::ELEMENT ); + $funcname = "format_$name"; + if ( isset( $this->map[ $name ] ) ) { + $tag = $this->map[ $name ]; + if ( is_array( $tag ) ) { + $tag = $this->notXPath( $tag ); + } + if ( strncmp( $tag, "format_", 7 ) ) { + return $this->transormFromMap( $type == XMLReader::ELEMENT, $tag, $name ); + } + $funcname = $tag; + } + return call_user_func( array( $this, $funcname ), $type == XMLReader::ELEMENT ); break; case XMLReader::TEXT: http://cvs.php.net/viewvc.cgi/phd/formats/phpnetchunkedreader.php?view=markup&rev=1.1 Index: phd/formats/phpnetchunkedreader.php +++ phd/formats/phpnetchunkedreader.php