public function testReturnedSafeString() { $testinglinkHelper = $this->runtime->getHelper("testinglink"); $result = $testinglinkHelper("https://github.com", "GitHub"); $this->assertInstanceOf(Handlebars\SafeString::class, $result); $this->assertEquals('<a href="https://github.com">GitHub</a>', (string) $result); }
/** * Partially renders the section open tokens * * @param array $node * @param array $open * @return string */ protected function generateOpen(array $node, array &$open) : string { $node['value'] = trim($node['value']); //push in the node, we are going to need this to close $open[] = $node; $argumentList = $this->parseArguments($node['value']); //if it's a value if (is_null($this->runtime->getHelper($argumentList->getName()))) { //run each $node['value'] = 'each ' . $node['value']; $argumentList = $this->parseArguments($node['value']); } $helperGen = array($this, "generateNestedHelper"); $args = array_map(function (Argument $arg) use($helperGen) { if ($arg instanceof HelperArgument) { return $helperGen($arg->getArgumentList(), $arg->getValue()); } return $arg->getValue(); }, $argumentList->getArguments()); $hash = array(); foreach ($argumentList->getNamedArguments() as $key => $value) { $hash[$key] = sprintf(self::BLOCK_OPTIONS_HASH_KEY_VALUE, $key, $value->getValue()); } $args[] = $this->prettyPrint(self::BLOCK_OPTIONS_OPEN, 0, 2) . $this->prettyPrint(sprintf(self::BLOCK_OPTIONS_NAME, $argumentList->getName())) . $this->prettyPrint(sprintf(self::BLOCK_OPTIONS_ARGS, str_replace("'", '\\\'', $node['value']))) . $this->prettyPrint(sprintf(self::BLOCK_OPTIONS_HASH, implode(', \\r\\t', $hash))) . $this->prettyPrint(self::BLOCK_OPTIONS_FN_OPEN) . $this->prettyPrint(self::BLOCK_OPTIONS_FN_BODY_1) . $this->prettyPrint(self::BLOCK_OPTIONS_FN_BODY_2) . $this->prettyPrint(self::BLOCK_OPTIONS_FN_BODY_3) . $this->prettyPrint(self::BLOCK_OPTIONS_FN_BODY_4); return $this->prettyPrint(sprintf(self::BLOCK_ESCAPE_HELPER_OPEN, $argumentList->getName()), -2) . $this->prettyPrint('\\r\\t' . implode(',\\r\\t', $args), 1, 2); }
public function testGetHelper() { $runtime1 = new Handlebars\Runtime(); $runtime2 = new Handlebars\Runtime(false); $this->assertTrue(is_callable($runtime1->getHelper("if"))); $this->assertInstanceOf(Handlebars\Helper\EachHelper::class, $runtime1->getHelper("each")); $this->assertNull($runtime1->getHelper("bar")); $this->assertNull($runtime2->getHelper("if")); }