[limb-svn] r6816 - in 3.x/trunk/limb/macro: src src/compiler src/filters src/tags/core tests/cases/compiler

svn at limb-project.com svn at limb-project.com
Mon Mar 3 12:23:29 MSK 2008


Author: serega
Date: 2008-03-03 12:23:29 +0300 (Mon, 03 Mar 2008)
New Revision: 6816
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6816

Added:
   3.x/trunk/limb/macro/src/filters/default.filter.php
   3.x/trunk/limb/macro/src/filters/lmbMacroDefaultFilter.inc.php
Modified:
   3.x/trunk/limb/macro/src/compiler/lmbMacroExpression.class.php
   3.x/trunk/limb/macro/src/lmbMacroTemplateLocatorSimple.class.php
   3.x/trunk/limb/macro/src/tags/core/insert_into.tag.php
   3.x/trunk/limb/macro/src/tags/core/repeat.tag.php
   3.x/trunk/limb/macro/src/tags/core/slot.tag.php
   3.x/trunk/limb/macro/tests/cases/compiler/lmbMacroOutputExpressionTest.class.php
Log:
-- default filter added.
-- lmbMacroTemplateLocatorSimple fixed to support absolute paths
-- fixed some tags annotations
-- {{macro}} expressions now support index based array access such as $var.0.1 or $var.1.title

Modified: 3.x/trunk/limb/macro/src/compiler/lmbMacroExpression.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/compiler/lmbMacroExpression.class.php	2008-03-03 08:45:31 UTC (rev 6815)
+++ 3.x/trunk/limb/macro/src/compiler/lmbMacroExpression.class.php	2008-03-03 09:23:29 UTC (rev 6816)
@@ -91,6 +91,15 @@
             $item .= '->';
           continue;
         }
+        elseif(strpos($token[1], '.') === 0)
+        {
+          if(!$in_function)
+          {
+            $path_items[] = $item;
+            $item = substr($token[1], 1);
+            continue;
+          }
+        }
         $item .= $token[1];
       }
       else

Added: 3.x/trunk/limb/macro/src/filters/default.filter.php
===================================================================
--- 3.x/trunk/limb/macro/src/filters/default.filter.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/src/filters/default.filter.php	2008-03-03 09:23:29 UTC (rev 6816)
@@ -0,0 +1,21 @@
+<?php 
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ */ 
+
+/**
+ * class lmbMacroDefaultFilter.
+ *
+ * @filter default
+ * @package macro
+ * @version $Id$
+ */ 
+class lmbMacroDefaultFilter extends lmbMacroFunctionBasedFilter
+{
+  protected $function = 'lmb_macro_apply_default';
+  protected $include_file = 'limb/macro/src/filters/lmbMacroDefaultFilter.inc.php';
+} 

Added: 3.x/trunk/limb/macro/src/filters/lmbMacroDefaultFilter.inc.php
===================================================================
--- 3.x/trunk/limb/macro/src/filters/lmbMacroDefaultFilter.inc.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/src/filters/lmbMacroDefaultFilter.inc.php	2008-03-03 09:23:29 UTC (rev 6816)
@@ -0,0 +1,17 @@
+<?php 
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ */ 
+
+function lmb_macro_apply_default($value, $default)
+{
+  if (empty($value) && $value !== "0" && $value !== 0)
+    return $default;
+  else
+    return $value;
+}
+ 

Modified: 3.x/trunk/limb/macro/src/lmbMacroTemplateLocatorSimple.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroTemplateLocatorSimple.class.php	2008-03-03 08:45:31 UTC (rev 6815)
+++ 3.x/trunk/limb/macro/src/lmbMacroTemplateLocatorSimple.class.php	2008-03-03 09:23:29 UTC (rev 6816)
@@ -23,11 +23,25 @@
   }
 
   function locateSourceTemplate($file_name)
-  {                
-    $file_path = $this->config['tpl_scan_dirs'].'/'.$file_name;
-    if(!file_exists($file_path))
-      throw new lmbMacroException('template file not found', array('template' => $file_path));
-    return $file_path;
+  {         
+    if(lmb_is_path_absolute($file_name))
+      return $file_name;
+    
+    if(is_array($this->config['tpl_scan_dirs']))
+      $dirs = $this->config['tpl_scan_dirs'];
+    else
+      $dirs =  array($this->config['tpl_scan_dirs']);
+      
+    foreach($dirs as $dir)
+    {
+      $file_path = $dir . '/' . $file_name;
+      if(lmb_is_path_absolute($file_path) && file_exists($file_path))
+        return $file_path;
+      if($full_path = lmb_resolve_include_path($file_path))
+        return $full_path;
+    }
+    
+    throw new lmbMacroException('template file not found', array('template' => $file_path));
   }
 
   function locateCompiledTemplate($file_name)

Modified: 3.x/trunk/limb/macro/src/tags/core/insert_into.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/insert_into.tag.php	2008-03-03 08:45:31 UTC (rev 6815)
+++ 3.x/trunk/limb/macro/src/tags/core/insert_into.tag.php	2008-03-03 09:23:29 UTC (rev 6816)
@@ -11,7 +11,8 @@
  * class lmbMacroInsertIntoTag.
  *
  * @tag insert:into
- * @aliases into, wrap:into, include:into  
+ * @aliases into, wrap:into, include:into
+ * @req_attributes slot 
  * @package macro
  * @version $Id$
  */

Modified: 3.x/trunk/limb/macro/src/tags/core/repeat.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/repeat.tag.php	2008-03-03 08:45:31 UTC (rev 6815)
+++ 3.x/trunk/limb/macro/src/tags/core/repeat.tag.php	2008-03-03 09:23:29 UTC (rev 6816)
@@ -10,6 +10,7 @@
 /**
  * Repeat a portion of the template several times
  * @tag repeat
+ * @req_attributes times  
  * @package macro
  * @version $Id$
  */

Modified: 3.x/trunk/limb/macro/src/tags/core/slot.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/core/slot.tag.php	2008-03-03 08:45:31 UTC (rev 6815)
+++ 3.x/trunk/limb/macro/src/tags/core/slot.tag.php	2008-03-03 09:23:29 UTC (rev 6816)
@@ -11,6 +11,7 @@
  * class lmbMacroSlotTag.
  *
  * @tag slot
+ * @forbid_end_tag    
  * @package macro
  * @version $Id$
  */

Modified: 3.x/trunk/limb/macro/tests/cases/compiler/lmbMacroOutputExpressionTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/compiler/lmbMacroOutputExpressionTest.class.php	2008-03-03 08:45:31 UTC (rev 6815)
+++ 3.x/trunk/limb/macro/tests/cases/compiler/lmbMacroOutputExpressionTest.class.php	2008-03-03 09:23:29 UTC (rev 6816)
@@ -119,6 +119,18 @@
     $this->assertEqual($out, 'Hey');
   }
 
+  function testChainedOutputWithArrayIndexInPath()
+  {
+    $content = '{$#var.1.title}';
+
+    $macro = $this->_createMacroTemplate($content, 'tpl.html');
+
+    $macro->set('var', array(array('title' => 'First'), array('title' => 'Second')));
+
+    $out = $macro->render();
+    $this->assertEqual($out, 'Second');
+  }
+
   function testBrokenChainOutputForMixedArraysAndObjects()
   {
     $content = '{$#var.foo.bar.baz}';



More information about the limb-svn mailing list