public function testRepeatObjectChildNodes() { $data = new stdclass(); $data->list = []; $one = new stdclass(); $one->name = 'One'; $one->id = '1'; $data->list[] = $one; $two = new stdclass(); $two->name = 'Two'; $two->id = '2'; $data->list[] = $two; $three = new stdclass(); $three->name = 'Three'; $three->id = '3'; $data->list[] = $three; $template = '<template name=""> <ul> <li> <h2>header</h2> <span>TEST1</span> </li> </ul> </template>'; $css = 'ul li {repeat: data(list);} ul li h2 {content: iteration(id)} ul li span {content: iteration(name); }'; $template = new \CDS\Builder($template, $css, $data); $this->assertEquals($this->stripTabs('<ul> <li> <h2>1</h2> <span>One</span> </li><li> <h2>2</h2> <span>Two</span> </li><li> <h2>3</h2> <span>Three</span> </li> </ul>'), $this->stripTabs($template->output())); }
echo benchmark(function () { //Get a new instance of $topics each time to avoid maphper caching $topics = getTopics(); $template = new \CDS\Builder(file_get_contents('template.xml'), 'topics.cds', $topics); $output = $template->output(); }); echo "\n\n"; echo 'Benchmarking tpl:'; echo benchmark(function () { //Get a new instance of $topics each time to avoid maphper caching $topics = getTopics(); $data = ['topics' => $topics]; extract($data); ob_start(); require 'template.php'; $output = ob_get_clean(); }); echo "\n\n"; echo 'Bechmkaring cached output:'; echo benchmark(function () { //Get a new instance of $topics each time to avoid maphper caching if (is_file('tmp/template.cache')) { $output = file_get_contents('tmp/template.cache'); } else { $topics = getTopics(); $template = new \CDS\Builder(file_get_contents('template.xml'), 'topics.cds', $topics); $output = $template->output(); file_put_contents('tmp/template.cache', $output); } }); echo "\n\n";