[limb-svn] r6262 - in 3.x/trunk/limb/wact: src/compiler/compile_tree_node src/compiler/expression/node src/tags/list tests/cases/compiler/expression tests/cases/tags/list
svn at limb-project.com
svn at limb-project.com
Wed Sep 5 17:14:39 MSD 2007
Author: serega
Date: 2007-09-05 17:14:39 +0400 (Wed, 05 Sep 2007)
New Revision: 6262
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6262
Added:
3.x/trunk/limb/wact/src/tags/list/first_row.prop.php
3.x/trunk/limb/wact/src/tags/list/last_row.prop.php
Modified:
3.x/trunk/limb/wact/src/compiler/compile_tree_node/WactCompileTreeNode.class.php
3.x/trunk/limb/wact/src/compiler/expression/node/WactDataBindingExpressionNode.class.php
3.x/trunk/limb/wact/src/tags/list/total_items.prop.php
3.x/trunk/limb/wact/tests/cases/compiler/expression/WactDataBindingExpressionNodeTest.class.php
3.x/trunk/limb/wact/tests/cases/tags/list/WactListTagsTest.class.php
Log:
-- WactCompileTreeNode :: getParent() method added.
-- FirstRow and LastRow properties added for <list:item> tag
-- Now it's possible to use parent modifier ("^") with property modifier (":") in DBEs. {$^:Property} - means "output "Property" property from parent tag (not parent datasource!)
Modified: 3.x/trunk/limb/wact/src/compiler/compile_tree_node/WactCompileTreeNode.class.php
===================================================================
--- 3.x/trunk/limb/wact/src/compiler/compile_tree_node/WactCompileTreeNode.class.php 2007-09-05 08:30:37 UTC (rev 6261)
+++ 3.x/trunk/limb/wact/src/compiler/compile_tree_node/WactCompileTreeNode.class.php 2007-09-05 13:14:39 UTC (rev 6262)
@@ -2,9 +2,9 @@
/*
* Limb PHP Framework
*
- * @link http://limb-project.com
+ * @link http://limb-project.com
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
/**
@@ -286,6 +286,11 @@
return $result;
}
+ function getParent()
+ {
+ return $this->parent;
+ }
+
/**
* Returns a root DataSource
*/
Modified: 3.x/trunk/limb/wact/src/compiler/expression/node/WactDataBindingExpressionNode.class.php
===================================================================
--- 3.x/trunk/limb/wact/src/compiler/expression/node/WactDataBindingExpressionNode.class.php 2007-09-05 08:30:37 UTC (rev 6261)
+++ 3.x/trunk/limb/wact/src/compiler/expression/node/WactDataBindingExpressionNode.class.php 2007-09-05 13:14:39 UTC (rev 6262)
@@ -2,9 +2,9 @@
/*
* Limb PHP Framework
*
- * @link http://limb-project.com
+ * @link http://limb-project.com
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
/**
@@ -27,6 +27,7 @@
protected $expression_analyzed = FALSE;
+ protected $is_property = false;
protected $property;
protected $php_variable = false;
@@ -74,6 +75,10 @@
protected function _findRealContext()
{
$this->processed_expression = $this->original_expression;
+
+ if(strpos($this->processed_expression, ":") !== false)
+ $this->is_property = true;
+
do
{
$modifier = $this->processed_expression{0};
@@ -104,7 +109,11 @@
// parent context
if ($modifier == "^")
{
- $this->datasource_context = $this->datasource_context->getParentDataSource();
+ if($this->is_property)
+ $this->datasource_context = $this->datasource_context->getParentDataSource();
+ else
+ $this->datasource_context = $this->datasource_context->getParent();
+
$this->processed_expression = substr($this->processed_expression, 1);
continue;
}
Added: 3.x/trunk/limb/wact/src/tags/list/first_row.prop.php
===================================================================
--- 3.x/trunk/limb/wact/src/tags/list/first_row.prop.php (rev 0)
+++ 3.x/trunk/limb/wact/src/tags/list/first_row.prop.php 2007-09-05 13:14:39 UTC (rev 6262)
@@ -0,0 +1,46 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+/**
+ * @property FirstRow
+ * @tag_class WactListItemTag
+ * @package wact
+ * @version $Id$
+ */
+class WactListRowFirstRowProperty extends WactCompilerProperty
+{
+ protected $temp_var;
+ protected $has_increment = FALSE;
+
+ function generateScopeEntry($code)
+ {
+ $this->temp_var = $code->getTempVarRef();
+ $ListList = $this->context->findParentByClass('WactListListTag');
+ $code->writePHP($this->temp_var . ' = ' . $ListList->getComponentRefCode() . '->getOffset();' . "\n");
+ }
+
+ function generatePreStatement($code_writer)
+ {
+ if (!$this->has_increment)
+ {
+ $this->hasIncrement = TRUE;
+ $code_writer->writePHP($this->temp_var . '++;');
+ }
+ }
+
+ function generateExpression($code)
+ {
+ if(!$this->has_increment)
+ $this->has_increment = TRUE;
+
+ $code->writePHP('(('.$this->temp_var .' == 1)?1:0)');
+ }
+}
+
+
Added: 3.x/trunk/limb/wact/src/tags/list/last_row.prop.php
===================================================================
--- 3.x/trunk/limb/wact/src/tags/list/last_row.prop.php (rev 0)
+++ 3.x/trunk/limb/wact/src/tags/list/last_row.prop.php 2007-09-05 13:14:39 UTC (rev 6262)
@@ -0,0 +1,50 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+/**
+ * @property LastRow
+ * @tag_class WactListItemTag
+ * @package wact
+ * @version $Id$
+ */
+class WactListRowLastRowProperty extends WactCompilerProperty
+{
+ protected $temp_var;
+ protected $count_var;
+ protected $has_increment = FALSE;
+
+ function generateScopeEntry($code)
+ {
+ $this->temp_var = $code->getTempVarRef();
+ $this->count_var = $code->getTempVarRef();
+
+ $ListList = $this->context->findParentByClass('WactListListTag');
+
+ $code->writePHP($this->temp_var . ' = ' . $ListList->getComponentRefCode() . '->getOffset();' . "\n");
+ $code->writePHP($this->count_var . ' = ' . $ListList->getComponentRefCode() . '->count();' . "\n");
+ }
+
+ function generatePreStatement($code_writer)
+ {
+ if (!$this->has_increment)
+ {
+ $this->hasIncrement = TRUE;
+ $code_writer->writePHP($this->temp_var . '++;');
+ }
+ }
+
+ function generateExpression($code)
+ {
+ if(!$this->has_increment)
+ $this->has_increment = TRUE;
+
+ $ListList = $this->context->findParentByClass('WactListListTag');
+ $code->writePHP('(('.$this->temp_var .' == '. $this->count_var . ')'.'?1:0)');
+ }
+}
Modified: 3.x/trunk/limb/wact/src/tags/list/total_items.prop.php
===================================================================
--- 3.x/trunk/limb/wact/src/tags/list/total_items.prop.php 2007-09-05 08:30:37 UTC (rev 6261)
+++ 3.x/trunk/limb/wact/src/tags/list/total_items.prop.php 2007-09-05 13:14:39 UTC (rev 6262)
@@ -13,7 +13,7 @@
* @package wact
* @version $Id$
*/
-class WactPagerTotalItemsProperty extends WactCompilerProperty
+class WactListTotalItemsProperty extends WactCompilerProperty
{
function generateExpression($code)
{
Modified: 3.x/trunk/limb/wact/tests/cases/compiler/expression/WactDataBindingExpressionNodeTest.class.php
===================================================================
--- 3.x/trunk/limb/wact/tests/cases/compiler/expression/WactDataBindingExpressionNodeTest.class.php 2007-09-05 08:30:37 UTC (rev 6261)
+++ 3.x/trunk/limb/wact/tests/cases/compiler/expression/WactDataBindingExpressionNodeTest.class.php 2007-09-05 13:14:39 UTC (rev 6262)
@@ -2,9 +2,9 @@
/*
* Limb PHP Framework
*
- * @link http://limb-project.com
+ * @link http://limb-project.com
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
require_once 'limb/wact/src/compiler/templatecompiler.inc.php';
@@ -76,6 +76,19 @@
$this->assertEqual($DBE->getFieldName(), 'Test');
}
+ function testAnalizeExpressionWithTagPropertySymbolAndParentModifier()
+ {
+ $root = new WactCompileTreeRootNode();
+ $root->registerProperty('Test', $property = new WactConstantProperty('value'));
+
+ $context = new WactCompileTreeRootNode();
+ $context->parent = $root;
+
+ $DBE = new WactDataBindingExpressionNode('^:Test', $context);
+ $DBE->prepare();
+ $this->assertEqual($DBE->getValue(), 'value');
+ }
+
function testAnalizePathExpression()
{
$parent = new WactCompileTreeRootNode();
Modified: 3.x/trunk/limb/wact/tests/cases/tags/list/WactListTagsTest.class.php
===================================================================
--- 3.x/trunk/limb/wact/tests/cases/tags/list/WactListTagsTest.class.php 2007-09-05 08:30:37 UTC (rev 6261)
+++ 3.x/trunk/limb/wact/tests/cases/tags/list/WactListTagsTest.class.php 2007-09-05 13:14:39 UTC (rev 6262)
@@ -305,7 +305,7 @@
function testListTotalItemsProperty()
{
- $template = '<list:LIST id="test">{$:TotalItems}</list:LIST>';
+ $template = '<list:LIST id="test"><list:item>{$:TotalItems}</list:item></list:LIST>';
$this->registerTestingTemplate('/tags/list/list-total-items.html', $template);
$page = $this->initTemplate('/tags/list/list-total-items.html');
@@ -313,7 +313,8 @@
$list = $page->getChild('test');
$list->registerDataSet($this->founding_fathers);
$output = $page->capture();
- $this->assertEqual($output, "3");
+ $this->assertEqual($output, "333");
+ die();
}
function testListFrom()
@@ -543,6 +544,29 @@
$this->assertEqual($page->capture(), 'John:Pavel');
}
+ function testListFillTagWithDynamicUpToAttribute()
+ {
+ $template = '<list:LIST id="test">'.
+ '<list:ITEM>{$name}'.
+ '<list:SEPARATOR every="{$#step}">++</list:SEPARATOR>'.
+ '<list:SEPARATOR>:</list:SEPARATOR>'.
+ '</list:ITEM>'.
+ '<list:FILL upto="{$#step}">{$items_left}</list:FILL>'.
+ '</list:LIST>';
+
+ $this->registerTestingTemplate('/tags/list/list_fill_tag_with_dynamic_upto.html', $template);
+
+ $page = $this->initTemplate('/tags/list/list_fill_tag_with_dynamic_upto.html');
+ $page->set('step', 3);
+
+ $list = $page->getChild('test');
+ $list->registerDataSet(array(array('name' => 'John'), array('name' => 'Pavel'),
+ array('name' => 'Peter'), array('name' => 'Harry')));
+
+ $this->assertEqual($page->capture(), 'John:Pavel:Peter++Harry2');
+ }
+
+
function testListSeparatorInNestedList()
{
$template = '<list:LIST id="base">'.
@@ -589,5 +613,29 @@
$output = $page->capture();
$this->assertEqual($output, "Ivan-Ivanov|Peter-Petrov|");
}
+
+ function testListFirstRowProperty()
+ {
+ $template = '<list:LIST id="test"><list:ITEM>{$FirstRow}:{$First}-</list:ITEM></list:LIST>';
+
+ $this->registerTestingTemplate('/tags/list/list_first_row_property.html', $template);
+ $page = $this->initTemplate('/tags/list/list_first_row_property.html');
+ $page->setChildDataset('test', $this->founding_fathers);
+
+ $output = $page->capture();
+ $this->assertEqual($output, "1:George-0:Alexander-0:Benjamin-");
+ }
+
+ function testListLastRowProperty()
+ {
+ $template = '<list:LIST id="test"><list:ITEM>{$LastRow}:{$First}-</list:ITEM></list:LIST>';
+
+ $this->registerTestingTemplate('/tags/list/list_last_row_property.html', $template);
+ $page = $this->initTemplate('/tags/list/list_last_row_property.html');
+ $page->setChildDataset('test', $this->founding_fathers);
+
+ $output = $page->capture();
+ $this->assertEqual($output, "0:George-0:Alexander-1:Benjamin-");
+ }
}
More information about the limb-svn
mailing list