Example #1
0
 /**
  * Construct
  *
  * @param object $resource
  * @return void
  */
 public function __construct(Resource $resource)
 {
     $this->contents = $resource->getContents();
     $parts = preg_split($this->frontMatterRegex, $this->contents, 2, PREG_SPLIT_NO_EMPTY);
     if (count($parts) > 1) {
         $this->parse($parts);
     }
 }
Example #2
0
 public function testDirectory()
 {
     $file = RESOURCE_DIR . '/';
     $relative = str_replace(__DIR__, '', $file);
     $resource = new Resource($file, $relative);
     $this->assertEquals('', $resource->getExtension());
     $this->assertEquals(rtrim($relative, '/'), $resource->getRelativePath());
     $this->assertEquals(rtrim($relative, '/'), $resource->getRelativePath(true));
     $this->assertFalse($resource->isIndexable());
     $this->assertEquals(basename($file), $resource->getFilenameShort(true));
     $this->assertEquals(basename($file), $resource->getFilenameShort(false));
     $this->assertEmpty($resource->getContents());
 }
Example #3
0
 /**
  * Returns the valid creation date of a resource
  *
  * @param object $resource
  * @param array $matter
  * @param string $format
  * @return string
  */
 public function getDate(Resource $resource, array $matter = array(), $format = 'Y-m-d')
 {
     $date = $resource->getCTime();
     if (!empty($matter['date'])) {
         $date = $matter['date'];
     } elseif (preg_match('~^((\\d{4})-(\\d{1,2})-(\\d{1,2})(?:[-_]*))~', $resource->getFilename(), $m)) {
         $date = trim($m['0'], '-_ ');
     }
     if (ctype_digit($date)) {
         $date = date('Y-m-d H:i:s', $date);
     }
     $dateTime = new \DateTime($date);
     return $dateTime->format($format);
 }
Example #4
0
 /** inline {@inheritdoc} */
 public function parseResource(Resource $resource, array $variables = array())
 {
     return $this->parseString($resource->getContents(), $variables);
 }
Example #5
0
 /** inline {@inheritdoc} */
 public function parseResource(Resource $resource, array $variables = array())
 {
     $tpl = $this->twig->loadTemplate($resource->getBasename());
     return $tpl->render($variables);
 }
Example #6
0
 /**
  * Checks if the resource needs to be recompiled
  *
  * @param object $resource
  * @param string $dst
  * @return bool
  */
 protected function needToCompile(Resource $resource, $dst)
 {
     if (!$this->filesystem->exists($dst)) {
         return true;
     }
     $dstResource = new Resource($dst);
     return $resource->getCTime() > $dstResource->getCtime();
 }
Example #7
0
 /**
  * Creates a link from the given resource
  *
  * @param object $resource
  * @return string
  */
 public function fromResource(Resource $resource)
 {
     $file = $resource->getFilenameShort(false);
     $path = $resource->getRelativePath(true);
     return $this->urlizeRecursive($path . '/' . $file);
 }