Permalink
Browse files

Section "from" attribute implemented.

  • Loading branch information...
1 parent b1da6fd commit 9a1ad33d90a9997b55e4d2e807bc802cd6249a3b @zyxist zyxist committed Jul 17, 2010
@@ -1758,7 +1758,7 @@ public function compileAttribute(Opt_Xml_Attribute $attr)
$found = $this->detectExpressionEngine($attr->getValue());
if($found !== null)
{
- if($found[0] == 'null')
+ if($found[0] == 'null' || $found[0] == 'http' || $found[0] == 'https')
{
$attr->setValue($found[1]);
}
View
@@ -88,7 +88,7 @@ protected function _build($hookName)
return '$_sect'.$section['name'].'_vals = '.$section['datasource'].'; ';
}
- $this->assign('item', $section['name']);
+ $this->assign('item', $section['from']);
$code = '$_sect'.$section['name'].'_vals = &'.$this->get('variable:item');
$ancestors = $this->_getVar('requestedData');
@@ -82,8 +82,8 @@ protected function _build($hookName)
if(!is_null($section['parent']))
{
- $parent = Opt_Instruction_BaseSection::getSection($section['parent']);
- $parent['format']->assign('item', $section['name']);
+ $parent = Opt_Instruction_Section_Abstract::getSection($section['parent']);
+ $parent['format']->assign('item', $section['from']);
return '$_sect'.$section['name'].'_vals = '.$parent['format']->get('section:variable').'; ';
}
elseif(!is_null($section['datasource']))
@@ -50,7 +50,7 @@ protected function _build($hookName)
if($section['parent'] !== null)
{
$parent = Opt_Instruction_Section_Abstract::getSection($section['parent']);
- $parent['format']->assign('item', $section['name']);
+ $parent['format']->assign('item', $section['from']);
$ds = $parent['format']->get('section:variable');
}
elseif($section['datasource'] !== null)
@@ -66,7 +66,7 @@ protected function _build($hookName)
if(!is_null($section['parent']))
{
$parent = Opt_Instruction_Section_Abstract::getSection($section['parent']);
- $parent['format']->assign('item', $section['name']);
+ $parent['format']->assign('item', $section['from']);
if($parent['format']->property('section:useReference'))
{
return '$_sect'.$section['name'].'_vals = &'.$parent['format']->get('section:variable').'; ';
@@ -42,7 +42,7 @@ protected function _build($hookName)
if(($section['parent']) !== null)
{
$parent = Opt_Instruction_BaseSection::getSection($section['parent']);
- $parent['format']->assign('item', $section['name']);
+ $parent['format']->assign('item', $section['from']);
return '$_sect'.$section['name'].'_vals = '.$parent['format']->get('section:variable').'; ';
}
elseif(($section['datasource']) !== null)
@@ -50,7 +50,7 @@ protected function _build($hookName)
if(!is_null($section['parent']))
{
$parent = Opt_Instruction_BaseSection::getSection($section['parent']);
- $parent['format']->assign('item', $section['name']);
+ $parent['format']->assign('item', $section['from']);
$ds = $parent['format']->get('section:variable');
}
elseif(!is_null($section['datasource']))
@@ -59,7 +59,7 @@ protected function _build($hookName)
}
else
{
- $this->assign('item', $section['name']);
+ $this->assign('item', $section['from']);
$ds = $this->get('variable:main');
}
@@ -152,6 +152,7 @@ protected function _sectionCreate(Opt_Xml_Element $node, $attr = NULL, $extraAtt
$section = array(
'name' => $attr->getValue(),
+ 'from' => $attr->getValue(),
'order' => 'asc',
'parent' => NULL,
'datasource' => NULL,
@@ -239,7 +240,7 @@ protected function _sectionStart(Array &$section)
{
$parent = '<em>Datasource</em>';
}
- elseif(!is_null($section['parent']))
+ elseif($section['parent'] !== null)
{
$parent = $section['parent'];
}
@@ -409,11 +410,12 @@ private function _extractSectionAttributes(Opt_Xml_Element $node, $extraAttribut
{
$params = array(
'name' => array(0 => self::REQUIRED, self::ID),
- 'parent' => array(0 => self::OPTIONAL, self::ID_EMP, NULL),
- 'datasource' => array(0 => self::OPTIONAL, self::EXPRESSION, NULL),
+ 'from' => array(0 => self::OPTIONAL, self::ID, null),
+ 'parent' => array(0 => self::OPTIONAL, self::ID_EMP, null),
+ 'datasource' => array(0 => self::OPTIONAL, self::EXPRESSION, null),
'order' => array(0 => self::OPTIONAL, self::ID, 'asc'),
- 'display' => array(0 => self::OPTIONAL, self::EXPRESSION, NULL),
- 'separator' => array(0 => self::OPTIONAL, self::EXPRESSION, NULL),
+ 'display' => array(0 => self::OPTIONAL, self::EXPRESSION, null),
+ 'separator' => array(0 => self::OPTIONAL, self::EXPRESSION, null),
);
// The instruction may add some extra attributes.
@@ -424,6 +426,11 @@ private function _extractSectionAttributes(Opt_Xml_Element $node, $extraAttribut
$this->_extractAttributes($node, $params);
+ if($params['from'] === null)
+ {
+ $params['from'] = $params['name'];
+ }
+
return $params;
} // end _extractSectionAttributes();
@@ -63,7 +63,7 @@ public static function dataProvider()
{
return array(0 =>
// BLOCK
-/* array('Block/block_basic.txt'),
+ array('Block/block_basic.txt'),
array('Block/block_single.txt'),
array('Block/block_arguments.txt'),
array('Block/block_single_args.txt'),
@@ -169,6 +169,8 @@ public static function dataProvider()
array('Section/section_parent.txt'),
array('Section/section_parent_complex.txt'),
array('Section/section_parent_complex2.txt'),
+ array('Section/section_from.txt'),
+ array('Section/section_from_dataformat.txt'),
array('Section/section_datasource.txt'),
array('Section/section_datasource_nested.txt'),
array('Section/section_if_coop.txt'),
@@ -184,15 +186,15 @@ public static function dataProvider()
array('Snippet/snippet_parent.txt'),
array('Snippet/snippet_bug144.txt'),
array('Snippet/snippet_bug144_part2.txt'),
-*/
+
// SWITCH
array('Switch/switch_equals_basic.txt'),
array('Switch/switch_equals_default.txt'),
array('Switch/switch_else.txt'),
array('Switch/switch_equals_nested_tail.txt'),
// TREE
-/* array('Tree/tree_basic.txt'),
+ array('Tree/tree_basic.txt'),
array('Tree/tree_complex.txt'),
array('Tree/tree_else.txt'),
array('Tree/tree_body.txt'),
@@ -202,7 +204,7 @@ public static function dataProvider()
array('Tree/tree_list_loop.txt'),
array('Tree/tree_node_loop.txt'),
array('Tree/tree_different_depth.txt'),
- array('Tree/tree_depth_error.txt'),*/
+ array('Tree/tree_depth_error.txt'),
/*
array('attribute_1.txt'),
array('attribute_2.txt'),
@@ -0,0 +1,36 @@
+Testing section "from" attribute.
+
+>>>>templates/test.tpl
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
+<opt:section name="sect1">
+<opt:section name="foo" from="sect2">
+{$sect1.value} {$foo.value}
+</opt:section>
+</opt:section>
+</opt:root>
+
+>>>>data.php
+$view->sect1 = array(0 =>
+ array('value' => ':sect1-value1:'),
+ array('value' => ':sect1-value2:')
+);
+$view->sect2 = array(0 =>
+ array(0 =>
+ array('value' => ':sect2-value1:'),
+ array('value' => ':sect2-value2:')
+ ),
+ array(0 =>
+ array('value' => ':sect2-value1:'),
+ array('value' => ':sect2-value2:')
+ ),
+);
+
+>>>>expected.txt
+OUTPUT
+
+>>>>result.txt
+:sect1-value1: :sect2-value1:
+:sect1-value1: :sect2-value2:
+:sect1-value2: :sect2-value1:
+:sect1-value2: :sect2-value2:
@@ -0,0 +1,36 @@
+Testing section "from" attribute with data format.
+
+>>>>templates/test.tpl
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
+<opt:section name="sect1">
+<opt:section name="foo" from="sect2">
+{$sect1.value} {$foo.value}
+</opt:section>
+</opt:section>
+</opt:root>
+
+>>>>data.php
+$view->sect1 = array(0 =>
+ array('value' => ':sect1-value1:', 'sect2' =>
+ new ArrayIterator(array(
+ array('value' => ':sect2-value1:'),
+ array('value' => ':sect2-value2:')
+ )),
+ ),
+ array('value' => ':sect1-value2:', 'sect2' =>
+ new ArrayIterator(array(
+ array('value' => ':sect2-value1:'),
+ array('value' => ':sect2-value2:')
+ ))
+ )
+);
+$view->setFormat('foo', 'Objective/Array');
+>>>>expected.txt
+OUTPUT
+
+>>>>result.txt
+:sect1-value1: :sect2-value1:
+:sect1-value1: :sect2-value2:
+:sect1-value2: :sect2-value1:
+:sect1-value2: :sect2-value2:

0 comments on commit 9a1ad33

Please sign in to comment.