setContent() public method

public setContent ( $content, $snapshotName )
Esempio n. 1
0
 public function testMultipleSnapshotOfContent()
 {
     $item = new Item('Raw content', 'index.html', []);
     $this->assertEquals('Raw content', $item->getContent(Item::SNAPSHOT_RAW));
     $item->setContent('After convert content', Item::SNAPSHOT_AFTER_CONVERT);
     $this->assertEquals('After convert content', $item->getContent());
     $this->assertEquals('After convert content', $item->getContent(Item::SNAPSHOT_AFTER_CONVERT));
     $this->assertEquals('Raw content', $item->getContent(Item::SNAPSHOT_RAW));
 }
Esempio n. 2
0
 private function processAttributes(Item $item, SplFileInfo $file)
 {
     $attributes = [];
     $attributesFile = $this->getAttributesFilename($file);
     $isItemType = $item->getType() === Item::TYPE_ITEM;
     if ($attributesFile && file_exists($attributesFile)) {
         $contentFile = file_get_contents($attributesFile);
         $attributes = $this->attributeParser->getAttributesFromString($contentFile);
     } elseif (false === $item->isBinary()) {
         $attributes = $this->attributeParser->getAttributesFromFrontmatter($item->getContent());
         $content = $this->attributeParser->getContentFromFrontmatter($item->getContent());
         $item->setContent($content, Item::SNAPSHOT_RAW);
     }
     $fileInfo = new FileInfo($file->getPathname(), $this->params['text_extensions']);
     $avoidRender = $this->avoidRenderizer($fileInfo->getExtension(), $file->getRelativePath());
     if ($isItemType && $avoidRender === true && isset($attributes['avoid_renderizer']) === false) {
         $attributes['avoid_renderizer'] = true;
     }
     $attributes['mtime'] = $this->getModifiedTime($file);
     $attributes['filename'] = $fileInfo->getFilename();
     $attributes['extension'] = $fileInfo->getExtension();
     if ($data = $this->isDateFilename($attributes['filename'])) {
         $attributes['title_path'] = $data[3];
         if (isset($attributes['title']) === false) {
             $attributes['title'] = implode(' ', explode('-', $attributes['title_path']));
         }
         if (isset($attributes['date']) === false) {
             $attributes['date'] = implode('-', [$data[0], $data[1], $data[2]]);
         }
     }
     $str = new StringWrapper($this->normalizeDirSeparator($file->getRelativePath()));
     if ($isItemType && $str->startWith('posts/') === true && array_key_exists('categories', $attributes) === false) {
         $categories = explode('/', $str->deletePrefix('posts/'));
         if ($categories[0] === '') {
             unset($categories[0]);
         }
         $attributes['categories'] = $categories;
     }
     $item->setAttributes($attributes);
 }
Esempio n. 3
0
 private function processAttributes(Item $item, SplFileInfo $file)
 {
     $attributes = [];
     $attributesFile = $this->getAttributesFilename($file);
     if ($attributesFile && file_exists($attributesFile)) {
         $contentFile = file_get_contents($attributesFile);
         $attributes = $this->attributeParser->getAttributesFromString($contentFile);
     } elseif (false === $item->isBinary()) {
         $attributes = $this->attributeParser->getAttributesFromFrontmatter($item->getContent());
         $content = $this->attributeParser->getContentFromFrontmatter($item->getContent());
         $item->setContent($content, Item::SNAPSHOT_RAW);
     }
     $attributes['mtime'] = $this->getModifiedTime($file);
     $attributes['filename'] = $file->getFilename();
     $attributes['extension'] = $file->getExtension();
     if ($data = $this->isDateFilename($file)) {
         $attributes['title_path'] = implode(' ', explode('-', $data[3]));
         if (isset($attributes['title']) === false) {
             $attributes['title'] = $attributes['title_path'];
         }
         if (isset($attributes['date']) === false) {
             $attributes['date'] = implode('-', [$data[0], $data[1], $data[2]]);
         }
     }
     $str = new StringWrapper($file->getRelativePath());
     if ($str->startWith('posts/') === true && array_key_exists('categories', $attributes) === false) {
         $categories = explode('/', $str->deletePrefix('posts/'));
         if ($categories[0] === '') {
             unset($categories[0]);
         }
         $attributes['categories'] = $categories;
     }
     $item->setAttributes($attributes);
 }