Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
support for buffered blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
everzet committed Aug 10, 2010
1 parent 0d829dd commit 6e48d71
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions src/Everzet/Jade/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,37 +461,34 @@ protected function parseExpr()
case 'code':
$tok = $this->advance();
$val = $tok->val;
if ($tok->buffer) {
$buf = sprintf("<?php echo %s ?>\n",
preg_replace(array("/^ */", "/ *$/"), '', $val)
);
} else {
$beg = preg_replace(array("/^ */", "/ *$/"), '', $val);
$end = null;
$indents = $this->getIndentation();
foreach ($this->blocks as $regexp => $close) {
if (preg_match($regexp, $beg)) {
$end = $close;
break;
}
$buf = $tok->buffer ? '<?php echo ' : '<?php ';

$beg = preg_replace(array("/^ */", "/ *$/"), '', $val);
$end = null;
$indents = $this->getIndentation();
foreach ($this->blocks as $regexp => $close) {
if (preg_match($regexp, $beg)) {
$end = $close;
break;
}
$buf = sprintf('<?php %s', $beg);
$this->skipNewlines();
if ('indent' === $this->peek()->type) {
$buf .= (null === $end ? '{' : '') . " ?>\n";
$buf .= $this->parseBlock();
$buf = preg_replace(array("/^ */", "/ *$/"), '', $buf);
$peek = $this->peek();
if ('code' !== $peek->type || false === strpos($peek->val, 'else')) {
$buf .= sprintf("%s<?php %s ?>\n",
$indents,
null === $end ? '}' : $end . ';'
);
}
} else {
$buf .= " ?>\n";
}
$buf .= $beg;
$this->skipNewlines();
if ('indent' === $this->peek()->type) {
$buf .= (null === $end ? '{' : '') . " ?>\n";
$buf .= $this->parseBlock();
$buf = preg_replace(array("/^ */", "/ *$/"), '', $buf);
$peek = $this->peek();
if ('code' !== $peek->type || false === strpos($peek->val, 'else')) {
$buf .= sprintf("%s<?php %s ?>\n",
$indents,
null === $end ? '}' : $end . ';'
);
}
} else {
$buf .= " ?>\n";
}

return $buf;
case 'comment':
$tok = $this->advance();
Expand Down

0 comments on commit 6e48d71

Please sign in to comment.