/**
  * Test attribute reparing. phpHaml can repair:
  *  - value without quotation marks (eg. { :bgcolor => green })
  *  - value without quotation marks followed by colon (same syntax like key eg. { :align => :center }
  */
 public function testAttributeRepair()
 {
     $this->markTestIncomplete();
     return;
     $this->parser->setSource('%b{ :bgcolor => green, :align => :center } Hello, World!');
     $this->assertEquals('<b align="center" bgcolor="green">Hello, World!</b>', $this->parser->fetch());
 }
Example #2
0
 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 #3
0
function haml_layout($file, &$controller)
{
    // –егистраци¤ переменных
    $framework =& $controller->framework;
    $data =& $controller->data;
    $layout =& $controller;
    $fragment =& $controller->fragment;
    // »нициализаци¤ парсера
    // ”казываем расположение шаблонов
    // ”казываем путь, где будут хранитьс¤ скомпилированные шаблоны
    $parser = new HamlParser(LAYOUT_PATH, HAML_COMPILED_TEMPLATES_PATH);
    $parser->setSource(file_get_contents(LAYOUT_PATH . "{$file}.haml"));
    $php_code = $parser->get_php_from_haml();
    // ¬џѕќЋЌ≈Ќ»≈ ЎјЅЋќЌј
    $code = ' ?>' . $php_code . '<?php ';
    $output = '';
    ob_start();
    eval($code);
    $output = ob_get_contents();
    ob_end_clean();
    echo $output;
}
Example #4
0
 /**
  * Create and append line to parent
  *
  * @param string Line
  * @param object Parent parser
  * @return object
  */
 public function createLine($sLine, $parent)
 {
     $oHaml = new HamlParser($this->sPath, $this->bCompile, $parent);
     $oHaml->setSource($sLine);
     $oHaml->iIndent = $parent->iIndent + 1;
     $parent->aChildren[] = $oHaml;
     return $oHaml;
 }
Example #5
0
 /**
  * Create and append line to parent
  *
  * @param string Line
  * @param object Parent parser
  * @param integer Line number
  * @return object
  */
 public function createLine($sLine, $parent, $iLine = null)
 {
     $oHaml = new HamlParser($this->sPath, $this->bCompile, $parent, array('line' => $iLine, 'file' => $this->sFile));
     $oHaml->setSource(rtrim($sLine, "\r"));
     $oHaml->iIndent = $parent->iIndent + 1;
     $parent->aChildren[] = $oHaml;
     return $oHaml;
 }
Example #6
0
 /**
  * Render Haml. Append globals variables
  *
  * Simple way to use Haml
  * <code>
  * echo HamlParser::haml('%strong Hello, World!'); // <strong>Hello, World!</strong>
  * $foo = 'bar'; // This is global variable
  * echo Haml::haml('%strong= "Foo is $foo"'); // <strong>Foo is bar</strong>
  * </code>
  *
  * @param string Haml source
  * @return string xHTML
  */
 public static function haml($sSource)
 {
     static $__haml_parser;
     if (!$__haml_parser) {
         $__haml_parser = new HamlParser();
     }
     $__haml_parser->setSource($sSource);
     $__haml_parser->append($GLOBALS);
     return $__haml_parser->fetch();
 }
Example #7
0
 public function testFrameBorder()
 {
     $this->parser->setSource('%iframe{ :frameBorder => "0" } Hello!!');
     $this->assertEquals('<iframe frameBorder="0">Hello!!</iframe>', $this->parser->fetch());
 }
Example #8
0
 /**
  * Test tag with dash in name
  */
 public function testTagWithDash()
 {
     $this->parser->setSource('%foo-bar Hello, World!');
     $this->assertEquals('<foo-bar>Hello, World!</foo-bar>', $this->parser->fetch());
 }
 /**
  * Test very_basic.haml
  */
 public function testVeryBasic()
 {
     $this->parser->setSource($this->getModifiedFile('very_basic', array(1 => '!!! Transitional')));
     $this->assertEquals($this->getResults('very_basic', array(3 => '  <head></head>')), $this->parser->fetch() . "\n");
 }