Skip to content

Commit

Permalink
BlockMacros: fixed triming of block [Closes #83]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 25, 2015
1 parent 6088f8b commit 2466f32
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Latte/Macros/BlockMacros.php
Expand Up @@ -289,7 +289,7 @@ public function macroBlockEnd(MacroNode $node, PhpWriter $writer)
if ($node->name === 'snippetArea') {
$node->content .= '<?php return FALSE; ?>';
}
$this->namedBlocks[$node->data->name] = $tmp = rtrim(ltrim($node->content, "\n"), " \t");
$this->namedBlocks[$node->data->name] = $tmp = preg_replace('#^\n+|(?<=\n)[ \t]+\z#', '', $node->content);
$node->content = substr_replace($node->content, $node->openingCode . "\n", strspn($node->content, "\n"), strlen($tmp));
$node->openingCode = '<?php ?>';
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Latte/expected/macros.inheritance.child2.html
Expand Up @@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>Homepage</title>
<title>Homepage </title>
</head>

<body>
Expand Down
5 changes: 2 additions & 3 deletions tests/Latte/expected/macros.inheritance.child2.phtml
Expand Up @@ -9,8 +9,7 @@ list($_b, $_g, $_l) = $template->initialize('%[a-z0-9]+%', 'html')
// block content
//
if (!function_exists($_b->blocks['content'][] = '_%[a-z0-9]+%_content')) { function _%[a-z0-9]+%_content($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v
?> <h1><?php call_user_func(reset($_b->blocks['title']), $_b, get_defined_vars()) ?>
</h1>
?> <h1><?php call_user_func(reset($_b->blocks['title']), $_b, get_defined_vars()) ?></h1>

<ul>
<?php $iterations = 0; foreach ($people as $person) { ?>
Expand All @@ -24,7 +23,7 @@ if (!function_exists($_b->blocks['content'][] = '_%[a-z0-9]+%_content')) { funct
// block title
//
if (!function_exists($_b->blocks['title'][] = '_%[a-z0-9]+%_title')) { function _%[a-z0-9]+%_title($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v
?>Homepage<?php
?>Homepage <?php
}}

//
Expand Down

0 comments on commit 2466f32

Please sign in to comment.