Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant indentation inside Run block #78

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/MtHaml/NodeVisitor/PhpRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ public function enterTopBlock(Run $node)

if (!$node->isBlock()) {
if (preg_match('~[:;]\s*$~', $content)) {
$this->write(sprintf('<?php %s ?>' , $content));
$this->write(sprintf('<?php %s ?>' , $content), false);
} else {
$this->write(sprintf('<?php %s; ?>' , $content));
$this->write(sprintf('<?php %s; ?>' , $content), false);
}
} else {
$this->write(sprintf('<?php %s { ?>' , $content));
$this->write(sprintf('<?php %s { ?>' , $content), false);
$this->undent();
}
}

Expand All @@ -111,13 +112,14 @@ public function enterMidBlock(Run $node)

$content = $this->trimInlineComments($node->getContent());

$this->write(sprintf('<?php } %s { ?>' , $content));
$this->write(sprintf('<?php } %s { ?>' , $content), false);
}

public function leaveTopBlock(Run $node)
{
if ($node->isBlock()) {
$this->write('<?php } ?>');
$this->write('<?php } ?>', false);
$this->indent();
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/MtHaml/Tests/fixtures/environment/bug28_php.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ echo $env->compileString($parts['HAML'], "$file.haml");
--EXPECT--
<?php if ($a) { ?>
<?php } else { ?>
1
1
<?php } ?>

18 changes: 9 additions & 9 deletions test/MtHaml/Tests/fixtures/environment/php.test
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,26 @@ echo $env->compileString($parts['HAML'], "$file.haml");
<p>everything can be nested in comments</p>
-->
<div id="body"><?php echo " Hey I print something!"; ?></div>
<?php foreach(range(0, 4) as $number) { ?>
<?php echo $number; ?>
<?php } ?>
<?php foreach(range(0, 4) as $number) { ?>
<?php echo $number; ?>
<?php } ?>
Wow.|
<p>
<?php echo "Holy cow " . "multiline " . "tags! " . "A pipe (|) even!" ; ?>
<?php echo count(array(1, 2, 3, "|")); ?>
<?php echo "Holy cow " . "multiline " . "tags! " ; ?>
</p>
<div class="silent">
<?php $foo = "this"; ?>
<?php $foo .= " shouldn't"; ?>
<?php $foo .= " be displayed"; ?>
<?php $foo = "this"; ?>
<?php $foo .= " shouldn't"; ?>
<?php $foo .= " be displayed"; ?>
<?php echo $foo . " but now it should!"; ?>
</div>
= Escape
<ul class="really cool">
<?php foreach(range("a", "f") as $a) { ?>
<li><?php echo $a; ?></li>
<?php } ?>
<?php foreach(range("a", "f") as $a) { ?>
<li><?php echo $a; ?></li>
<?php } ?>
</ul>
<div id="combo" class="of_divs_with_underscore"><?php echo "with this text"; ?></div>
<div id="escaping-test">
Expand Down
18 changes: 9 additions & 9 deletions test/MtHaml/Tests/fixtures/environment/php_blocks.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ echo $env->compileString($parts['HAML'], "$file.haml");

--EXPECT--
<?php if ($a) { ?>
<ul>
<?php foreach($items as $item) { ?>
<li>
<?php echo $item; ?>
</li>
<?php } ?>
</ul>
<?php echo $foo; ?>
<ul>
<?php foreach($items as $item) { ?>
<li>
<?php echo $item; ?>
</li>
<?php } ?>
</ul>
<?php echo $foo; ?>
<?php } else { ?>
no item
no item
<?php } ?>

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ echo $env->compileString($parts['HAML'], "$file.haml");
<?php echo 1 + 2; ?>
<?php echo 1 + 2; ?>
<?php if ($foo) { ?>
.
.
<?php } else { ?>
.
.
<?php } ?>

4 changes: 2 additions & 2 deletions test/MtHaml/Tests/fixtures/environment/try_catch_php.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ echo $env->compileString($parts['HAML'], "$file.haml");

--EXPECT--
<?php try { ?>
<?php echo foo(); ?>
<?php echo foo(); ?>
<?php } catch(\Exception $e) { ?>
bar
bar
<?php } ?>