/**
  * {@inheritdoc}
  */
 public function transform(FileCopyEvent $event)
 {
     $relative_path = str_replace($this->output_path, '', $event->getTarget());
     $site_root = str_repeat('..' . DIRECTORY_SEPARATOR, substr_count($relative_path, DIRECTORY_SEPARATOR));
     $path_parts = pathinfo($relative_path);
     $page_name = $path_parts['filename'];
     $path = explode(DIRECTORY_SEPARATOR, $relative_path, -1);
     $event->data->set('siteroot', $site_root);
     $event->data->set('breadcrumbs', $path);
     $event->data->set('pagename', $page_name);
 }
 /**
  * {@inheritdoc}
  */
 public function transform(FileCopyEvent $event)
 {
     if (!in_array($event->getExtension(), array('md', 'markdown', 'html', 'htm'))) {
         return;
     }
     $fileContent = $event->getContent();
     list($fileContent, $data) = $this->frontmatterReader->parse($fileContent);
     $event->setContent($fileContent);
     foreach ($data as $key => $value) {
         $event->data->set($key, $value);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function transform(FileCopyEvent $event)
 {
     if (!in_array($event->getExtension(), array('htm', 'html'))) {
         return;
     }
     $fileContent = $event->getContent();
     $data = iterator_to_array($event->data);
     $data['content'] = $fileContent;
     // Override template?
     if (isset($data['template'])) {
         $this->template = $data['template'];
     }
     // Render and save
     $output = $this->twig->render($this->template, $data);
     $event->setContent($output);
 }
 /**
  * {@inheritdoc}
  */
 public function transform(FileCopyEvent $event)
 {
     if (!in_array($event->getExtension(), array('sass', 'scss'))) {
         return;
     }
     if (!$this->sass_process_builder->isInstalled()) {
         return;
     }
     $targetFile = $event->getTarget();
     $targetFile = substr($targetFile, 0, 0 - strlen(pathinfo($targetFile, PATHINFO_EXTENSION))) . 'css';
     $event->setTarget($targetFile);
     $process = $this->sass_process_builder->getProcess($event->getSource());
     $process->run();
     $event->setContent($process->getOutput());
 }
 /**
  * {@inheritdoc}
  */
 public function transform(FileCopyEvent $event)
 {
     if (!in_array($event->getExtension(), array('md', 'markdown'))) {
         return;
     }
     $fileContent = $event->getContent();
     // Override template?
     $template = $event->data->get('template')->getOrElse($this->template);
     /* Parse remaining file as markdown */
     $data = iterator_to_array($event->data);
     $data['content'] = $this->markdown->transformMarkdown($fileContent);
     // Render and save
     $output = $this->twig->render($template, $data);
     $targetFile = $event->getTarget();
     $targetFile = substr($targetFile, 0, 0 - strlen(pathinfo($targetFile, PATHINFO_EXTENSION))) . 'html';
     $event->setTarget($targetFile);
     $event->setContent($output);
 }
 public function testsetContent()
 {
     $this->object->setContent('Something else.');
     $this->assertEquals($this->object->getContent(), 'Something else.');
     $this->assertTrue($this->object->isModified());
 }
 public function transform(FileCopyEvent $event)
 {
     $event->setContent(str_replace('ORIGINAL', 'TRANSFORMED', $event->getContent()));
 }
示例#8
0
if ($notfound) {
    $filename = __DIR__ . '/../content/404.html';
}
/* Ensure requested file is actually in the content folder.
 * You'd think I'd do this sooner, but we don't know the actual
 * filename before this point.
 */
$filename = realpath($filename);
if (strpos($filename, realpath(__DIR__ . '/../content')) !== 0) {
    // Attempt to read file outside of content folder
    $filename = __DIR__ . '/../content/404.html';
}
/* Render the file:
 * Dispatch a FileCopyEvent to call transformers on a file, then build a response
 */
$event = new FileCopyEvent($filename, $filename);
$extension = $event->getExtension();
$event = $container->get('event_dispatcher')->dispatch(FilesystemEvents::COPY, $event);
$response = new Response($event->getContent(), 200);
$headers = $event->data->get('headers')->getOrElse(array());
// Special cases
if (isset($headers['location'])) {
    $response = new RedirectResponse($headers['location']);
    unset($headers['location']);
}
if (isset($headers['status'])) {
    $response->setStatusCode($headers['status']);
    unset($headers['status']);
}
// Everything else
foreach ($headers as $key => $value) {