Skip to content

Commit

Permalink
Expressions in attributes (#6)
Browse files Browse the repository at this point in the history
Improve code coverage, cleanup dead code
  • Loading branch information
kylekatarnls committed Jun 25, 2016
1 parent 7663210 commit 392261f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/Jade/Compiler/CodeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ protected function parseBetweenSeparators()
return substr(
$input,
$offset,
isset($end) ? $end[1] - $offset : strlen($input)
isset($end)
? $end[1] - $offset
: strlen($input)
);
};

Expand Down
6 changes: 5 additions & 1 deletion src/Jade/Compiler/CommonUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public static function addDollarIfNeeded($call)
if ($call === 'undefined') {
return 'null';
}
if ($call[0] !== '$' && $call[0] !== '\\' && !preg_match('#^(?:' . CompilerConfig::VARNAME . '\\s*\\(|(?:null|false|true)(?![a-z]))#i', $call)) {
if (
!in_array(substr($call, 0, 1), array('$', '\\')) &&
!preg_match('#^(?:' . CompilerConfig::VARNAME . '\\s*\\(|(?:null|false|true)(?![a-z]))#i', $call) &&
preg_match('#^' . CompilerConfig::VARNAME . '#', $call)
) {
$call = '$' . $call;
}

Expand Down
19 changes: 0 additions & 19 deletions src/Jade/Compiler/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Jade\Compiler;

use Jade\Nodes\Block;
use Jade\Nodes\BlockComment;
use Jade\Nodes\CaseNode;
use Jade\Nodes\Comment;
use Jade\Nodes\Doctype;
Expand Down Expand Up @@ -185,24 +184,6 @@ protected function visitComment(Comment $comment)
}
}

/**
* @param Nodes\BlockComment $comment
*/
protected function visitBlockComment(BlockComment $comment)
{
if (!$comment->buffer) {
return;
}

list($open, $close) = strlen($comment->value) && 0 === strpos(trim($comment->value), 'if')
? array('[' . trim($comment->value) . ']>', '<![endif]')
: array($comment->value, '');

$this->buffer('<!--' . $open);
$this->visit($comment->block);
$this->buffer($close . '-->');
}

/**
* @param $node
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/templates/attrs.expressions.html
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<p answear="42"></p>
<p answear="42"></p>
<p answear="bar"></p>
<p answear="bar"></p>
3 changes: 3 additions & 0 deletions tests/templates/attrs.expressions.jade
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
$ob = (object) array('foo' => array());
$ob->foo['bar'] = new FooClass();
p(answear=ob->foo["bar"]->met())
p(answear=(ob->foo["bar"]->met()))
p(answear=substr("foobar", strlen("foo")))
p(answear=substr("foobar", strlen(strtoupper("F") . "oo")))

0 comments on commit 392261f

Please sign in to comment.