Author: dr
Date: Fri Oct 5 11:55:48 2007
New Revision: 6367
Log:
- Implemented XHTML visitor comment
Modified:
trunk/Tree/review.txt
trunk/Tree/src/options/visitor_xhtml.php
trunk/Tree/src/visitors/xhtml.php
trunk/Tree/tests/visitor.php
Modified: trunk/Tree/review.txt
==============================================================================
--- trunk/Tree/review.txt [iso-8859-1] (original)
+++ trunk/Tree/review.txt [iso-8859-1] Fri Oct 5 11:55:48 2007
@@ -8,7 +8,10 @@
'PDOException: SQLSTATE[HY000]: General error: 942 OCIStmtExecute:
ORA-00942: table or view does not exist'.
-[ ] XHTML visitor: the hightlight class applies to the whole subtree - is it
correct?
+[X] XHTML visitor: the hightlight class applies to the whole subtree - is it
correct?
+
+ It was, but I added an option to make both subtrees and just nodes
+ highlighted now.
[ ] Files missing __get() and __set() ($this->properties is accessed directly):
- Tree/src/backends/memory.php
@@ -45,8 +48,9 @@
Other points
------------
-[ ] Allow the / char to be changed in the nested set implementation, and add a
check
- for this char in used IDs when creating a new node.
+[ ] Issue #11444: Allow the / char to be changed in the nested set
+ implementation, and add a check for this char in used IDs when creating
a
+ new node.
[ ] Check how we can use node names paths to retrieve items.
@@ -58,5 +62,3 @@
[ ] Check example from Alex, and add them to docs if useful.
-[ ] Issue #11444: Clarify the use of '/' for ID naming in Trees
-
Modified: trunk/Tree/src/options/visitor_xhtml.php
==============================================================================
--- trunk/Tree/src/options/visitor_xhtml.php [iso-8859-1] (original)
+++ trunk/Tree/src/options/visitor_xhtml.php [iso-8859-1] Fri Oct 5 11:55:48
2007
@@ -22,6 +22,8 @@
* The ID that should be set on the top level <ul> tag.
* @property array(string) $highlightNodeIds
* Which IDs should have the 'highlight' CSS class added.
+ * @property array(string) $subtreeHighlightNodeIds
+ * Which subtree IDs should have the 'highlight' CSS class added.
*
* @package Tree
* @version //autogentag//
@@ -44,6 +46,7 @@
$this->displayRootNode = false;
$this->xmlId = null;
$this->highlightNodeIds = array();
+ $this->subtreeHighlightNodeIds = array();
parent::__construct( $options );
}
@@ -81,6 +84,7 @@
break;
case 'highlightNodeIds':
+ case 'subtreeHighlightNodeIds':
if ( !is_array( $value ) )
{
throw new ezcBaseValueException( $name, $value,
'array(string)' );
Modified: trunk/Tree/src/visitors/xhtml.php
==============================================================================
--- trunk/Tree/src/visitors/xhtml.php [iso-8859-1] (original)
+++ trunk/Tree/src/visitors/xhtml.php [iso-8859-1] Fri Oct 5 11:55:48 2007
@@ -91,9 +91,10 @@
* @param mixed $data
* @return string
*/
- protected function formatData( $data )
- {
- return $data;
+ protected function formatData( $data, $highlight )
+ {
+ $data = htmlspecialchars( $data );
+ return $highlight ? "<div class=\"highlight\">$data</div>" : $data;
}
/**
@@ -167,7 +168,7 @@
$path = htmlspecialchars( $this->options->basePath . '/' .
join( '/', $path ) );
$text .= str_repeat( ' ', $level + 2 );
- $data = htmlspecialchars( $this->formatData( $child[1] ) );
+ $data = $this->formatData( $child[1], in_array( $child[0],
$this->options->highlightNodeIds ) );
$linkStart = $linkEnd = '';
if ( $this->options->addLinks )
@@ -177,7 +178,7 @@
}
$highlightPart = '';
- if ( in_array( $child[0], $this->options->highlightNodeIds ) )
+ if ( in_array( $child[0],
$this->options->subtreeHighlightNodeIds ) )
{
$highlightPart = ' class="highlight"';
}
Modified: trunk/Tree/tests/visitor.php
==============================================================================
--- trunk/Tree/tests/visitor.php [iso-8859-1] (original)
+++ trunk/Tree/tests/visitor.php [iso-8859-1] Fri Oct 5 11:55:48 2007
@@ -474,13 +474,13 @@
self::assertSame( $expected, $visitor->__toString() );
}
- public function testVisitorXHTMLHighlightNodes()
+ public function testVisitorXHTMLSubtreeHighlightNodes()
{
$tree = ezcTreeMemory::create( new ezcTreeMemoryDataStore() );
$this->addTestData( $tree );
$options = new ezcTreeVisitorXHTMLOptions;
- $options->highlightNodeIds = array( 'Nomascus', 'Eastern Black Crested
Gibbon' );
+ $options->subtreeHighlightNodeIds = array( 'Nomascus', 'Eastern Black
Crested Gibbon' );
$options->addLinks = false;
$visitor = new ezcTreeVisitorXHTML( $options );
@@ -518,6 +518,50 @@
self::assertSame( $expected, $visitor->__toString() );
}
+ public function testVisitorXHTMLHighlightNodes()
+ {
+ $tree = ezcTreeMemory::create( new ezcTreeMemoryDataStore() );
+ $this->addTestData( $tree );
+
+ $options = new ezcTreeVisitorXHTMLOptions;
+ $options->highlightNodeIds = array( 'Nomascus', 'Eastern Black Crested
Gibbon' );
+ $options->addLinks = false;
+ $visitor = new ezcTreeVisitorXHTML( $options );
+
+ $tree->fetchNodeById( 'Hylobatidae' )->accept( $visitor );
+ $expected = <<<END
+ <ul>
+ <li>Hylobates
+ <ul>
+ <li>Lar Gibbon</li>
+ <li>Agile Gibbon</li>
+ <li>Müller's Bornean Gibbon</li>
+ <li>Silvery Gibbon</li>
+ <li>Pileated Gibbon</li>
+ <li>Kloss's Gibbon</li>
+ </ul>
+ </li>
+ <li>Hoolock
+ <ul>
+ <li>Western Hoolock Gibbon</li>
+ <li>Eastern Hoolock Gibbon</li>
+ </ul>
+ </li>
+ <li>Symphalangus</li>
+ <li><div class="highlight">Nomascus</div>
+ <ul>
+ <li>Black Crested Gibbon</li>
+ <li><div class="highlight">Eastern Black Crested Gibbon</div></li>
+ <li>White-cheecked Crested Gibbon</li>
+ <li>Yellow-cheecked Gibbon</li>
+ </ul>
+ </li>
+ </ul>
+
+END;
+ self::assertSame( $expected, $visitor->__toString() );
+ }
+
public static function suite()
{
return new PHPUnit_Framework_TestSuite( "ezcTreeVisitorTest" );
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components