public function testTemplateReentrancy() { $this->parser->assign("a", 1); $parser2 = new HamlParser(); $this->assertEquals(0, count($parser2->getVariables())); $this->assertEquals(1, count($this->parser->getVariables())); $parser2->setSource('= $var'); $this->assertEquals("Hello", $parser2->render(array('var' => "Hello"))); }
/** * Example with many features. * * @author Amadeusz Jasak <*****@*****.**> * @package phpHaml * @subpackage Examples */ require_once './includes/haml/HamlParser.class.php'; $parser = new HamlParser('./tpl', './tmp/haml'); class ConfigModel { public $ID; public $name; public $value; public function __construct($ID, $name, $value) { $this->ID = $ID; $this->name = $name; $this->value = $value; } public function getID() { return $this->ID; } } $models = array(); for ($i = 1; $i <= 100; $i++) { $models[] = new ConfigModel($i, md5($i), md5(uniqid(rand()))); } $parser->assign('models', $models); echo $parser->setFile('example1.haml');
<?php /** * Including by variable * * @author Amadeusz Jasak <*****@*****.**> * @package phpHaml * @subpackage Examples */ require_once './includes/haml/HamlParser.class.php'; $parser = new HamlParser('./tpl', './tmp/haml'); $parser->assign('menu', 'my_menu'); echo $parser->setFile('example9.haml');
/** * Test commas in attribute values */ public function testAttributesDoubleColon() { $this->parser->assign('attrs', array('name' => 'foo', 'style' => 'font-size: 16;')); $this->parser->setSource('%input{ :xml:lang => "en-us", :http-equiv => "Content-Type",:foo => test_scope::hi, $attrs }'); $this->assertEquals('<input name="foo" style="font-size: 16;" foo="hi" http-equiv="Content-Type" xml:lang="en-us" />', $this->parser->fetch()); }
/** * Test content_for_layout.haml */ public function testContentForLayout() { $this->parser->assign('content_for_layout', 'Lorem ipsum dolor sit amet'); $this->parser->setSource($this->getModifiedFile('content_for_layout', array(1 => '!!! Transitional', 6 => ' = $content_for_layout', 8 => ' = $content_for_layout'))); $this->assertEquals($this->getResults('content_for_layout', array(), array('\'' => '"')), $this->parser->fetch() . "\n"); }