/** * @covers Cradle\Handlebars\HandlebarsException::forMissingClosing */ public function testForMissingClosing() { $actual = null; $open = [['value' => 'foo', 'line' => 1], ['value' => 'bar', 'line' => 2]]; try { throw HandlebarsException::forMissingClosing($open); } catch (HandlebarsException $e) { $actual = $e->getMessage(); } $expected = 'Missing closing tags for: "foo" on line 1 AND "bar" on line 2'; $this->assertEquals($expected, $actual); }
/** * Transform the template to code * that can be used independently * * @param bool $layout Whether to use the layout or raw code * * @return string */ public function compile($layout = true) { $code = $this->trim($this->source); $reference = new StdClass(); $reference->buffer = ''; $reference->open = []; $callback = $this->getTokenizeCallback($reference); $this->resolve(HandlebarsTokenizer::class, $code)->tokenize($callback); if (count($reference->open)) { throw HandlebarsException::forMissingClosing($reference->open); } if (!$layout) { return $reference->buffer; } return sprintf(self::$layout, $reference->buffer); }