Skip to content

Commit

Permalink
call empty macro gives empty
Browse files Browse the repository at this point in the history
  • Loading branch information
zzgab committed Mar 9, 2017
1 parent f7cf36a commit 3c07777
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/figdice/classes/ViewElementTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -824,47 +824,47 @@ private function fig_macro(Context $context) {
* @param Context $context
* @return string
*/
private function fig_call(Context $context) {
//Retrieve the name of the macro to call.
$macroName = $this->figCall;
private function fig_call(Context $context) {
//Retrieve the name of the macro to call.
$macroName = $this->figCall;

//Prepare the arguments to pass to the macro:
//all the non-fig: attributes, evaluated.
$arguments = array();
foreach($this->attributes as $attribName => $attribValue) {
if( ! $context->view->isFigPrefix($attribName) ) {
$value = $this->evaluate($context, $attribValue);
$arguments[$attribName] = $value;
}
}

//Prepare the arguments to pass to the macro:
//all the non-fig: attributes, evaluated.
$arguments = array();
foreach($this->attributes as $attribName => $attribValue) {
if( ! $context->view->isFigPrefix($attribName) ) {
$value = $this->evaluate($context, $attribValue);
$arguments[$attribName] = $value;
}
}

//Fetch the parameters specified as immediate children
//of the macro call : <fig:param name="" value=""/>
$arguments = array_merge($arguments, $this->collectParamChildren($context));

//Fetch the parameters specified as immediate children
//of the macro call : <fig:param name="" value=""/>
$arguments = array_merge($arguments, $this->collectParamChildren($context));
//Retrieve the macro contents.
if(isset($context->view->macros[$macroName])) {
/** @var ViewElementTag $macroElement */
$macroElement = & $context->view->macros[$macroName];
$context->view->pushStackData($arguments);

//Retrieve the macro contents.
if(isset($context->view->macros[$macroName])) {
/** @var ViewElementTag $macroElement */
$macroElement = & $context->view->macros[$macroName];
$context->view->pushStackData($arguments);

// Hide any current iteration during macro invocation
// Hide any current iteration during macro invocation
$context->pushIteration(new Iteration(0));

//Now render the macro contents, but do not take into account the fig:macro
//that its root tag holds.
$result = $macroElement->renderNoMacro($context);
//Now render the macro contents, but do not take into account the fig:macro
//that its root tag holds.
$result = $macroElement->renderNoMacro($context);

// Restore the previous iteration context
// Restore the previous iteration context
$context->popIteration();

$context->view->popStackData();
return $result;
//unset($macroElement->iteration);
}
return '';
}
$context->view->popStackData();
return $result;
}
// Macro not yet defined: empty result for call.
return '';
}

/**
* Returns an array of named values obtained by the immediate :param children of the tag.
Expand Down
21 changes: 21 additions & 0 deletions test/MacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,25 @@ public function testMacroInvokedInsideIterationDoesNotSeePosition()

$this->assertEquals($expected, $rendered);
}

public function testCallAMacroThatDoesNotExistsGivesEmpty()
{
$template = <<<TEMPLATE
<fig>
<span fig:call="macroNotFound" param1="2 + 2">
discarded content
</span>
</fig>
TEMPLATE;

$expected = <<<EXPECTED
<fig>
</fig>
EXPECTED;

$view = new View();
$view->loadString($template);
$this->assertEquals($expected, $view->render());
}
}

0 comments on commit 3c07777

Please sign in to comment.