Base class for all Haml nodes.
Esempio n. 1
0
 public function testSetIndentationLevelTemplate()
 {
     $parentNode = new HamlNode("parent");
     $childNode = new HamlNode("  child");
     $childNode2 = new HamlNode("    child");
     $parentNode->addNode($childNode);
     $childNode->addNode($childNode2);
     $parentNode->setIndentationLevel($parentNode->getIndentationLevel() + 2);
     $output = $parentNode->render();
     $this->assertEquals("  parent\n    child\n      child\n", $output);
 }
Esempio n. 2
0
 public function filter(HamlNode $node)
 {
     if ($node === null) {
         throw new Exception('PHP filter: node is null');
     }
     $plainFilter = new PlainFilter();
     $output = $node->getSpaces() . "<?php\n";
     $output .= $plainFilter->filter($node);
     $output .= $node->getSpaces() . "?>";
     return $output . "\n";
 }
Esempio n. 3
0
 public function filter(HamlNode $node)
 {
     if (null === $node) {
         throw new Exception("CssFilter: node is null.");
     }
     $plainFilter = new PlainFilter();
     $output = $node->getSpaces() . "<style type=\"text/css\">\n";
     $oldLevel = $node->getIndentationLevel();
     $node->setIndentationLevel($oldLevel + 2);
     $output .= $plainFilter->filter($node);
     $node->setIndentationLevel($oldLevel);
     $output .= $node->getSpaces() . "</style>";
     return $output . "\n";
 }
Esempio n. 4
0
 public function filter(HamlNode $node)
 {
     if ($node === null) {
         throw new Exception('Javascript filter: node is null');
     }
     $plainFilter = new PlainFilter();
     $output = $node->getSpaces() . "<script type=\"text/javascript\">\n";
     $oldLevel = $node->getIndentationLevel();
     $node->setIndentationLevel($oldLevel + 2);
     $output .= $plainFilter->filter($node);
     $node->setIndentationLevel($oldLevel);
     $output .= $node->getSpaces() . "</script>";
     return $output . "\n";
 }
Esempio n. 5
0
 public function __construct($line, $compiler)
 {
     parent::__construct($line);
     $this->_phpVariable = false;
     $this->_el = new Element($this->getHaml(), $compiler);
     $this->_phpVariable = $this->_el->isPhpVariable();
 }
Esempio n. 6
0
 public function __construct($line)
 {
     parent::__construct($line);
     $parts = explode(' ', trim($line));
     $this->_type = isset($parts[1]) ? strtolower($parts[1]) : '';
     if ('xml' == $this->_type && isset($parts[2])) {
         $this->_encoding = $parts[2];
     }
 }
Esempio n. 7
0
 /**
  * @see IFilter::filter()
  */
 public function filter(HamlNode $node)
 {
     if (null === $node) {
         throw new Exception("MarkdownFilter: node is null.");
     }
     $children = $node->getChildren();
     $output = '';
     $indent = 999999999;
     // gets the lowes indent among the children to set as base
     foreach ($children as $child) {
         if ($indent > ($ind = $child->getIndentationLevel())) {
             $indent = $ind;
         }
     }
     foreach ($children as $childNode) {
         $output .= substr($childNode->getRawHaml(), $indent) . "\n";
     }
     return $this->parser->transform($output);
 }
Esempio n. 8
0
 protected function renderChildrenHaml(HamlNode $node)
 {
     $parent = $node->getParent();
     $haml = $parent !== null ? $parent->getSpaces() . $node->getHaml() : $node->getRawHaml();
     $output = $haml . "\n";
     if ($node->hasChildren()) {
         $children = $node->getChildren();
         for ($i = 0, $count = count($children); $i < $count; ++$i) {
             $output .= $this->renderChildrenHaml($children[$i]);
         }
     }
     return $output;
 }
Esempio n. 9
0
 public function __construct($line)
 {
     parent::__construct($line);
     $this->_line = $line;
     if (!preg_match(TagNode::CODE_PATTERN, $this->_line, $matches)) {
         throw new InvalidTagException('Line does not match the pattern');
     }
     $this->_mode = $matches['mode'];
     $this->_code = $matches['code'];
     if (isset($matches['tag'])) {
         $tag = trim($matches['tag']);
         if (isset($this->_tags[$tag])) {
             $this->_isTag = true;
             $this->_tag = $tag;
             if (!isset($matches['colon'])) {
                 $this->_code .= ':';
             }
         }
     }
     if ($this->_isTag && TagNode::LOUD_MODE == $this->_mode) {
         throw new InvalidTagException('Loud mode is not allowed for the tags ' . join(', ', array_keys($this->_tags)) . '. Use silent mode (-).');
     }
 }
Esempio n. 10
0
 public function __construct($line, FilterContainer $container = null)
 {
     parent::__construct($line);
     $this->_filterContainer = $container;
 }
Esempio n. 11
0
 public function __construct($line)
 {
     parent::__construct($line);
     $this->identifyCommentType();
 }