private function HamlParser::parseCode in Sassy 7
* Parse code *
Parameters
array line to parse: * @param HamlNode parent node * @return HamlCodeBlockNode
1 call to HamlParser::parseCode()
- HamlParser::parseLine in phamlp/
haml/ HamlParser.php - * Parse a line of Haml into a HamlNode for the document tree *
File
- phamlp/
haml/ HamlParser.php, line 1006
Class
- HamlParser
- HamlParser class. Parses {@link http://haml-lang.com/ Haml} view files. @package PHamlP @subpackage Haml
Code
private function parseCode($line, $parent) {
if (preg_match('/^(if|foreach|for|switch|do|while)\\b(.*)$/', $line[self::HAML_CONTENT], $block)) {
if ($block[1] === 'do') {
$node = new HamlCodeBlockNode('<?php do { ?>', $parent);
$node->doWhile = 'while' . $block[2] . ';';
}
elseif ($block[1] === 'switch') {
$node = new HamlCodeBlockNode("<?php {$line[self::HAML_CONTENT]} {", $parent);
}
else {
$node = new HamlCodeBlockNode("<?php {$line[self::HAML_CONTENT]} { ?>", $parent);
}
}
elseif (strpos($line[self::HAML_CONTENT], 'else') === 0) {
$node = new HamlCodeBlockNode("<?php } {$line[self::HAML_CONTENT]} { ?>", null);
$node->token = $line;
$node->showOutput = $this->showOutput;
$node->showSource = $this->showSource;
$parent
->getLastChild()
->addElse($node);
$this
->addChildren($node, $line);
$node = null;
}
elseif (strpos($line[self::HAML_CONTENT], 'case') === 0) {
$node = new HamlNode(($parent
->hasChildren() ? '<?php ' : '') . "{$line[self::HAML_CONTENT]}: ?>", $parent);
}
else {
$node = new HamlNode("<?php {$line[self::HAML_CONTENT]}; ?>", $parent);
}
return $node;
}