Example #1
0
 /**
  * Generates a static page from the given Page object.
  *
  * @param  Page   $page Page object.
  *
  * @return string
  */
 public function generatePage(Page $page)
 {
     if (!$page->getTemplateFile()->isFile()) {
         throw new NotFoundException('Could not find template to render: ' . $page->getTemplateFile()->getPathname());
     }
     $output = $this->templating->render($page->getTemplateName(), array_merge($page->getParameters(), array('_genry_page' => $page)));
     // trigger event
     $event = new PageRendered($page, $output);
     $this->eventManager->trigger($event);
     // update the final output with the output from the event
     $output = $event->getOutput();
     // make sure that the dir the output will be saved, exists
     $outputDir = $page->getOutputFile()->getPath();
     if (!is_dir($outputDir)) {
         mkdir($outputDir, 0755, true);
     }
     file_put_contents($page->getOutputFile()->getPathname(), $output);
     $this->logger->debug('Generated {output} from {template}', array('output' => $page->getOutputName(), 'template' => $page->getTemplateName()));
     return $output;
 }