[limb-svn] r6279 - in 3.x/trunk/limb/macro: src src/tags tests/cases/tags
svn at limb-project.com
svn at limb-project.com
Mon Sep 10 01:46:57 MSD 2007
Author: pachanga
Date: 2007-09-10 01:46:57 +0400 (Mon, 10 Sep 2007)
New Revision: 6279
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6279
Added:
3.x/trunk/limb/macro/src/tags/wrap.tag.php
3.x/trunk/limb/macro/tests/cases/tags/lmbMacroWrapTagTest.class.php
Modified:
3.x/trunk/limb/macro/src/lmbMacroTagInfo.class.php
Log:
-- adding some initial wrap tag tests(they don't pass yet)
Modified: 3.x/trunk/limb/macro/src/lmbMacroTagInfo.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroTagInfo.class.php 2007-09-09 10:06:56 UTC (rev 6278)
+++ 3.x/trunk/limb/macro/src/lmbMacroTagInfo.class.php 2007-09-09 21:46:57 UTC (rev 6279)
@@ -24,10 +24,11 @@
protected $forbid_parsing = false;
protected $forbid_endtag = false;
- function __construct($tag, $class)
+ function __construct($tag, $class, $forbid_endtag = false)
{
$this->tag = $tag;
$this->class = $class;
+ $this->forbid_endtag = $forbid_endtag;
}
function getTag()
Added: 3.x/trunk/limb/macro/src/tags/wrap.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/wrap.tag.php (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/wrap.tag.php 2007-09-09 21:46:57 UTC (rev 6279)
@@ -0,0 +1,76 @@
+<?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
+ */
+
+//temporary includes, make it more flexible later
+lmb_require('limb/macro/src/lmbMacroTagDictionary.class.php');
+lmb_require('limb/macro/src/lmbMacroTagInfo.class.php');
+lmb_require('limb/macro/src/lmbMacroTag.class.php');
+
+lmbMacroTagDictionary :: instance()->register(new lmbMacroTagInfo('wrap', 'lmbMacroWrapTag'), __FILE__);
+
+/**
+ * class lmbMacroWrapTag.
+ *
+ * @package macro
+ * @version $Id$
+ */
+class lmbMacroWrapTag extends lmbMacroTag
+{
+ function preParse($compiler)
+ {
+ $tree_builder = $compiler->getTreeBuilder();
+
+ $file = $this->get('with');
+ $this->_compileSourceFileName($file, $compiler);
+ $this->_makeInsertion($this, $tree_builder);
+ }
+
+ protected function _compileSourceFileName($file, $compiler)
+ {
+ $this->sourcefile = $compiler->getTemplateLocator()->locateSourceTemplate($file);
+
+ if(empty($this->sourcefile))
+ $this->raise('Template source file not found', array('file_name' => $file));
+
+ $compiler->parseTemplate($file, $this);
+ }
+
+ protected function _makeInsertion($wrapper, $tree_builder)
+ {
+ if($insertionId = $this->get('into'))
+ $this->_insert($wrapper, $tree_builder, $insertionId);
+ }
+
+ function _insert($wrapper, $tree_builder, $point)
+ {
+ $this->_insertOrReplace($wrapper, $tree_builder, $point, $replace = false);
+ }
+
+ protected function _insertOrReplace($wrapper, $tree_builder, $point, $replace = false)
+ {
+ $insertionPoint = $wrapper->findChild($point);
+ if(empty($insertionPoint))
+ {
+ $params = array('placeholder' => $point);
+ if($wrapper !== $this)
+ {
+ $params['parent_wrap_tag_file'] = $wrapper->getTemplateFile();
+ $params['parent_wrap_tag_line'] = $wrapper->getTemplateLine();
+ }
+
+ $this->raise('Wrap placeholder not found', $params);
+ }
+
+ if($replace)
+ $insertionPoint->removeChildren();
+
+ $tree_builder->pushCursor($insertionPoint, $this->location_in_template);
+ }
+}
+
Added: 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroWrapTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroWrapTagTest.class.php (rev 0)
+++ 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroWrapTagTest.class.php 2007-09-09 21:46:57 UTC (rev 6279)
@@ -0,0 +1,53 @@
+<?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
+ */
+
+lmb_require('limb/macro/src/lmbMacroTemplate.class.php');
+lmb_require('limb/macro/src/tags/wrap.tag.php');
+lmb_require('limb/fs/src/lmbFs.class.php');
+
+class lmbMacroWrapTagTest extends UnitTestCase
+{
+ function setUp()
+ {
+ lmbFs :: rm(LIMB_VAR_DIR . '/tpl');
+ lmbFs :: mkdir(LIMB_VAR_DIR . '/tpl/compiled');
+ }
+
+ function testSimpleWrap()
+ {
+ $bar = '<%wrap with="foo.html into="slot1"%>Bob<%/wrap%>';
+ $foo = '<p>Hello, <%slot id="slot1"/%></p>';
+
+ $bar_tpl = $this->_createTemplate($bar, 'bar.html');
+ $foo_tpl = $this->_createTemplate($foo, 'foo.html');
+
+ $macro = $this->_createMacro($bar_tpl);
+
+ $out = $macro->render();
+ $this->assertEqual($out, '<p>Hello, Bob</p>');
+ }
+
+ protected function _createMacro($file)
+ {
+ $base_dir = LIMB_VAR_DIR . '/tpl';
+ $cache_dir = LIMB_VAR_DIR . '/tpl/compiled';
+ $macro = new lmbMacroTemplate($file,
+ $cache_dir,
+ new lmbMacroTemplateLocator($base_dir, $cache_dir));
+ return $macro;
+ }
+
+ protected function _createTemplate($code, $name)
+ {
+ $file = LIMB_VAR_DIR . '/tpl/' . $name;
+ file_put_contents($file, $code);
+ return $file;
+ }
+}
+
More information about the limb-svn
mailing list