public function test() { $formatContext = new FormatContext('someTemplateId', 'template text', array('a' => 'Some A Value', 'formatter' => 'SOME_FORMATTER')); $this->assertEquals('someTemplateId', $formatContext->templateId()); $this->assertEquals('template text', $formatContext->template()); $this->assertEquals(array('a' => 'Some A Value', 'formatter' => 'SOME_FORMATTER'), $formatContext->data()->export()); $this->assertEquals('SOME_FORMATTER', $formatContext->formatter()); }
protected function massageTemplate(FormatContext $formatContext) { $template = $formatContext->template(); if ($layout = $formatContext->data()->get('layout')) { // Completely remove anything in verbatim sections so that any blocks defined in there will // not trigger the "you've already defined blocks!" check since this is almost certainly // NOT the intention of the source's author. $verbatim = preg_replace('/{%\\s+verbatim\\s+%}(.*?){%\\s+endverbatim\\s+%}/si', '', $template); if (!preg_match_all('/{%\\s+block\\s+(\\w+)\\s+%}(.*?){%\\s+endblock\\s+%}/si', $verbatim, $matches)) { $template = '{% block content %}' . $template . '{% endblock %}'; } $template = '{% extends "' . $layout . '" %}' . $template; } return $template; }