svn: /phd/trunk/ package_generic.xml phpdotnet/phd/Format.php phpdotnet/phd/Index.php phpdotnet/phd/Package/Generic/XHTML.php
phpdotnet/phd/Package/PHP/Web.php

From: Date: Fri, 31 Dec 2010 09:28:38 +0000
Subject: svn: /phd/trunk/ package_generic.xml phpdotnet/phd/Format.php phpdotnet/phd/Index.php phpdotnet/phd/Package/Generic/XHTML.php
phpdotnet/phd/Package/PHP/Web.php
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-7590@lists.php.net to get a copy of this message
bjori Fri, 31 Dec 2010 09:28:38 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=306906 Log: Generate IDs for example, and store their descriptions # Useful for linking to specific examples via irc/email for example # And will make it possible to create an example listing like we have always wanted Changed paths: U phd/trunk/package_generic.xml U phd/trunk/phpdotnet/phd/Format.php U phd/trunk/phpdotnet/phd/Index.php U phd/trunk/phpdotnet/phd/Package/Generic/XHTML.php U phd/trunk/phpdotnet/phd/Package/PHP/Web.php Modified: phd/trunk/package_generic.xml =================================================================== --- phd/trunk/package_generic.xml 2010-12-31 06:54:40 UTC (rev 306905) +++ phd/trunk/package_generic.xml 2010-12-31 09:28:38 UTC (rev 306906) @@ -49,6 +49,7 @@ Allow xml:id on &lt;table&gt; (Richard Quadling) Add class="note" to &lt;note&gt;s generated &lt;blockquote&gt; (Hannes) Generate an ID for &lt;refsect1&gt; (Hannes) + Generate IDS for all &lt;example&gt;s (Hannes) </notes> <contents> Modified: phd/trunk/phpdotnet/phd/Format.php =================================================================== --- phd/trunk/phpdotnet/phd/Format.php 2010-12-31 06:54:40 UTC (rev 306905) +++ phd/trunk/phpdotnet/phd/Format.php 2010-12-31 09:28:38 UTC (rev 306906) @@ -42,6 +42,7 @@ protected $refs = array(); protected $vars = array(); protected $classes = array(); + protected $examples = array(); private static $autogen = array(); @@ -134,11 +135,13 @@ $this->sqlite->createAggregate("refname", array($this, "SQLiteRefname"), array($this, "SQLiteFinal"), 2); $this->sqlite->createAggregate("varname", array($this, "SQLiteVarname"), array($this, "SQLiteFinal"), 2); $this->sqlite->createAggregate("classname", array($this, "SQLiteClassname"), array($this, "SQLiteFinal"), 2); + $this->sqlite->createAggregate("example", array($this, "SQLiteExample"), array($this, "SQLiteFinal"), 1); $this->sqlite->query('SELECT indexes(docbook_id, filename, parent_id, sdesc, ldesc, element, previous, next, chunk) FROM ids'); $this->sqlite->query('SELECT children(docbook_id, parent_id) FROM ids WHERE chunk != 0'); $this->sqlite->query('SELECT refname(docbook_id, sdesc) FROM ids WHERE element=\'refentry\''); $this->sqlite->query('SELECT varname(docbook_id, sdesc) FROM ids WHERE element=\'phpdoc:varentry\''); $this->sqlite->query('SELECT classname(docbook_id, sdesc) FROM ids WHERE element=\'phpdoc:exceptionref\' OR element=\'phpdoc:classref\''); + $this->sqlite->query('SELECT example(docbook_id) FROM ids WHERE element=\'example\' OR element=\'informalexample\''); } public function SQLiteIndex(&$context, $index, $id, $filename, $parent, $sdesc, $ldesc, $element, $previous, $next, $chunk) { @@ -177,6 +180,9 @@ public function SQLiteClassname(&$context, $index, $id, $sdesc) { $this->classes[strtolower($sdesc)] = $id; } + public function SQLiteExample(&$context, $index, $id) { + $this->examples[] = $id; + } public static function SQLiteFinal(&$context) { return $context; @@ -281,6 +287,9 @@ public function getVarnameLink($var) { return isset($this->vars[$var]) ? $this->vars[$var] : null; } + public function getGeneratedExampleID($index) { + return $this->examples[$index]; + } final public function registerElementMap(array $map) { $this->elementmap = $map; } Modified: phd/trunk/phpdotnet/phd/Index.php =================================================================== --- phd/trunk/phpdotnet/phd/Index.php 2010-12-31 06:54:40 UTC (rev 306905) +++ phd/trunk/phpdotnet/phd/Index.php 2010-12-31 09:28:38 UTC (rev 306906) @@ -62,6 +62,7 @@ 'refpurpose' => 'format_ldesc', 'refname' => 'format_sdesc', 'titleabbrev' => 'format_sdesc', + 'example' => 'format_example', ); private $mytextmap = array( @@ -353,6 +354,26 @@ } } + public function format_example($open, $name, $attrs, $props) { + static $n = 0; + + if ($open) { + ++$n; + + if(isset($attrs[Reader::XMLNS_XML]["id"])) { + $id = $attrs[Reader::XMLNS_XML]["id"]; + } + else { + $id = "example-" . $n; + } + + $this->storeInfo($name, $id, $this->currentchunk, false); + return false; + } + + $this->appendID(); + return false; + } public function commit() { if (isset($this->commit) && $this->commit) { $this->db->exec('BEGIN TRANSACTION; '.$this->commit.' COMMIT'); @@ -372,6 +393,7 @@ $dbhtml->setAttribute("filename", false); } } + } Modified: phd/trunk/phpdotnet/phd/Package/Generic/XHTML.php =================================================================== --- phd/trunk/phpdotnet/phd/Package/Generic/XHTML.php 2010-12-31 06:54:40 UTC (rev 306905) +++ phd/trunk/phpdotnet/phd/Package/Generic/XHTML.php 2010-12-31 09:28:38 UTC (rev 306906) @@ -100,7 +100,7 @@ 'envar' => 'span', 'errortype' => 'span', 'errorcode' => 'span', - 'example' => 'format_div', + 'example' => 'format_example', 'formalpara' => 'p', 'fieldsynopsis' => array( /* DEFAULT */ 'format_fieldsynopsis', @@ -1306,6 +1306,17 @@ } return '</b><br />'; } + public function format_example($open, $name, $attrs, $props) { + static $n = 0; + if ($open) { + ++$n; + if (isset($props["id"])) { + return '<div class="' . $name . '" id="' . $props["id"] . '">'; + } + return '<div class="' . $name . '" id="' . $this->getGeneratedExampleId($n-1) . '">'; + } + return '</div>'; + } public function format_example_title($open, $name, $attrs, $props) { if ($props["empty"]) { return ""; Modified: phd/trunk/phpdotnet/phd/Package/PHP/Web.php =================================================================== --- phd/trunk/phpdotnet/phd/Package/PHP/Web.php 2010-12-31 06:54:40 UTC (rev 306905) +++ phd/trunk/phpdotnet/phd/Package/PHP/Web.php 2010-12-31 09:28:38 UTC (rev 306906) @@ -56,6 +56,10 @@ public function update($event, $val = null) { switch($event) { + case Render::FINALIZE: + $this->writeJsonIndex(); + break; + case Render::CHUNK: $this->flags = $val; break; @@ -190,6 +194,19 @@ return "<?php manual_footer(); ?>"; } + protected function writeJsonIndex() { + v("Writing search indexes..", VERBOSE_FORMAT_RENDERING); + $ids = array(); + $desc = array(); + foreach($this->indexes as $id => $index) { + $ids[$index["element"]][] = array($index["sdesc"], $index["filename"]); + $desc[$id] = $index["ldesc"]; + } + file_put_contents($this->getOutputDir() . "search-index.json", json_encode($ids)); + file_put_contents($this->getOutputDir() . "search-description.json", json_encode($desc)); + v("Index written", VERBOSE_FORMAT_RENDERING); + } + } /*

« previous php.doc.cvs (#7590) next »