[limb-svn] r6335 - in 3.x/trunk/limb/macro: src src/tags tests/cases tests/cases/tags
svn at limb-project.com
svn at limb-project.com
Thu Sep 27 01:21:21 MSD 2007
Author: pachanga
Date: 2007-09-27 01:21:21 +0400 (Thu, 27 Sep 2007)
New Revision: 6335
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6335
Added:
3.x/trunk/limb/macro/src/tags/output.tag.php
3.x/trunk/limb/macro/tests/cases/tags/lmbMacroOutputTagTest.class.php
Modified:
3.x/trunk/limb/macro/src/lmbMacroTagDictionary.class.php
3.x/trunk/limb/macro/src/lmbMacroTagInfo.class.php
3.x/trunk/limb/macro/src/lmbMacroTagParsingState.class.php
3.x/trunk/limb/macro/tests/cases/lmbMacroTagDictionaryTest.class.php
3.x/trunk/limb/macro/tests/cases/lmbMacroTokenizerTest.class.php
Log:
-- adding initial very naive implementation of output tag
Modified: 3.x/trunk/limb/macro/src/lmbMacroTagDictionary.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroTagDictionary.class.php 2007-09-25 11:39:40 UTC (rev 6334)
+++ 3.x/trunk/limb/macro/src/lmbMacroTagDictionary.class.php 2007-09-26 21:21:21 UTC (rev 6335)
@@ -18,6 +18,7 @@
class lmbMacroTagDictionary
{
protected $info = array();
+ protected $output_tag_info;
static protected $instance;
static function instance()
@@ -49,9 +50,30 @@
function findTagInfo($tag)
{
- $tag = strtolower($tag);
- if(isset($this->info[$tag]))
- return $this->info[$tag];
+ if($this->_isOutputTag($tag))
+ return $this->_getOutputTagInfo();
+ else
+ {
+ $tag = strtolower($tag);
+ if(isset($this->info[$tag]))
+ return $this->info[$tag];
+ }
}
+
+ protected function _isOutputTag($tag)
+ {
+ return $tag{0} == '$';
+ }
+
+ protected function _getOutputTagInfo()
+ {
+ if($this->output_tag_info)
+ return $this->output_tag_info;
+
+ //taking first item
+ $this->output_tag_info = reset(lmbMacroTagInfo :: extractFromFile($file = dirname(__FILE__) . '/tags/output.tag.php'));
+ $this->output_tag_info->setFile($file);
+ return $this->output_tag_info;
+ }
}
Modified: 3.x/trunk/limb/macro/src/lmbMacroTagInfo.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroTagInfo.class.php 2007-09-25 11:39:40 UTC (rev 6334)
+++ 3.x/trunk/limb/macro/src/lmbMacroTagInfo.class.php 2007-09-26 21:21:21 UTC (rev 6335)
@@ -68,8 +68,14 @@
{
if(!isset($annotations['tag']))
throw new lmbMacroException("@tag annotation is missing for class '$class'");
+
$tag = $annotations['tag'];
- return new lmbMacroTagInfo($tag, $class);
+ $info = new lmbMacroTagInfo($tag, $class);
+
+ if(isset($annotations['endtag']) && $annotations['endtag'] == 'no')
+ $info->setForbidEndtag(true);
+
+ return $info;
}
static protected function _extractAnnotations($content)
Modified: 3.x/trunk/limb/macro/src/lmbMacroTagParsingState.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroTagParsingState.class.php 2007-09-25 11:39:40 UTC (rev 6334)
+++ 3.x/trunk/limb/macro/src/lmbMacroTagParsingState.class.php 2007-09-26 21:21:21 UTC (rev 6335)
@@ -112,7 +112,7 @@
$tag_node->set($name, $value);
}
}
-
+
protected function _createTagNode($tag_info, $tag)
{
$class = $tag_info->getClass();
Added: 3.x/trunk/limb/macro/src/tags/output.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/output.tag.php (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/output.tag.php 2007-09-26 21:21:21 UTC (rev 6335)
@@ -0,0 +1,27 @@
+<?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/lmbMacroTag.class.php');
+
+/**
+ * class lmbMacroOutputTag.
+ *
+ * @tag $output
+ * @endtag no
+ * @package macro
+ * @version $Id$
+ */
+class lmbMacroOutputTag extends lmbMacroTag
+{
+ function generateContents($code)
+ {
+ $code->writePHP('echo ' . $this->tag . ';');
+ }
+}
+
Modified: 3.x/trunk/limb/macro/tests/cases/lmbMacroTagDictionaryTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/lmbMacroTagDictionaryTest.class.php 2007-09-25 11:39:40 UTC (rev 6334)
+++ 3.x/trunk/limb/macro/tests/cases/lmbMacroTagDictionaryTest.class.php 2007-09-26 21:21:21 UTC (rev 6335)
@@ -29,6 +29,14 @@
$this->assertIsA($dictionary->findTagInfo('testtag'), 'lmbMacroTagInfo');
}
+ function testFindOutputTagInfoSpecialCase()
+ {
+ $dictionary = new lmbMacroTagDictionary();
+ $info = $dictionary->findTagInfo('$var');
+ $this->assertIsA($info, 'lmbMacroTagInfo');
+ $this->assertEqual($info->getClass(), 'lmbMacroOutputTag');
+ }
+
function testRegisterTagInfoOnceOnly()
{
$dictionary = new lmbMacroTagDictionary();
Modified: 3.x/trunk/limb/macro/tests/cases/lmbMacroTokenizerTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/lmbMacroTokenizerTest.class.php 2007-09-25 11:39:40 UTC (rev 6334)
+++ 3.x/trunk/limb/macro/tests/cases/lmbMacroTokenizerTest.class.php 2007-09-26 21:21:21 UTC (rev 6335)
@@ -93,6 +93,15 @@
$this->parser->parse('<%/%>');
}
+ function testOutputTag()
+ {
+ $this->listener->expectOnce('startElement', array('$value', array()));
+ $this->listener->expectNever('characters');
+ $this->listener->expectNever('endElement');
+ $this->listener->expectNever('invalidAttributeSyntax');
+ $this->parser->parse('<%$value%>');
+ }
+
function testElementWithPreContent()
{
$this->listener->expectOnce('characters', array('stuff'));
Added: 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroOutputTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroOutputTagTest.class.php (rev 0)
+++ 3.x/trunk/limb/macro/tests/cases/tags/lmbMacroOutputTagTest.class.php 2007-09-26 21:21:21 UTC (rev 6335)
@@ -0,0 +1,54 @@
+<?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/fs/src/lmbFs.class.php');
+lmb_require('limb/macro/src/lmbMacroTagDictionary.class.php');
+
+//output tag is a special case, it's always registered in lmbMacroTagDictionary
+
+class lmbMacroOutputTagTest extends UnitTestCase
+{
+ function setUp()
+ {
+ lmbFs :: rm(LIMB_VAR_DIR . '/tpl');
+ lmbFs :: mkdir(LIMB_VAR_DIR . '/tpl/compiled');
+ }
+
+ function testSimpleOutput()
+ {
+ $content = '<%$#var%>';
+
+ $tpl = $this->_createTemplate($content, 'tpl.html');
+
+ $macro = $this->_createMacro($tpl);
+ $macro->set('var', 'Foo');
+
+ $out = $macro->render();
+ $this->assertEqual($out, 'Foo');
+ }
+
+ 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