public function testToAscii() { $str = new StringWrapper('camión'); $this->assertEquals('camion', $str->toAscii()); $str = new StringWrapper('españa'); $this->assertEquals('espana', $str->toAscii()); }
public function onStart(EnvironmentEvent $event) { $renderizer = $event->getRenderizer(); $renderizer->addTwigFilter('slugify', function ($text) { $string = new StringWrapper($text); return $string->slug(); }); }
private function avoidRenderizer($extension, $relativePath) { $strPath = new StringWrapper($relativePath); foreach ($this->params['avoid_renderizer_path'] as $path) { if ($relativePath == $path || $strPath->startWith($path . '/') === true) { return true; } } if (in_array($extension, $this->params['avoid_renderizer_extension']) === true) { return true; } return false; }
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($this->normalizeDirSeparator($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); }
private function convertItem(ItemInterface $item) { $path = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE); if ($item->isBinary() === true) { $item->setPath($path, ItemInterface::SNAPSHOT_PATH_RELATIVE_AFTER_CONVERT); return; } $this->eventDispatcher->dispatch('spress.before_convert', new Event\ContentEvent($item, ItemInterface::SNAPSHOT_RAW, ItemInterface::SNAPSHOT_PATH_RELATIVE)); $result = $this->converterManager->convertItem($item); $str = new StringWrapper($path); $filenameWithoutExtension = $str->deleteSufix($result->getInputExtension()); $newPath = $filenameWithoutExtension . $result->getExtension(); $item->setContent($result->getResult(), ItemInterface::SNAPSHOT_AFTER_CONVERT); $item->setPath($newPath, ItemInterface::SNAPSHOT_PATH_RELATIVE_AFTER_CONVERT); $this->eventDispatcher->dispatch('spress.after_convert', new Event\ContentEvent($item, ItemInterface::SNAPSHOT_AFTER_CONVERT, ItemInterface::SNAPSHOT_PATH_RELATIVE_AFTER_CONVERT)); }
/** * Converts an item. This method uses the SNAPSHOT_PATH_RELATIVE of Item path. * * @param Yosymfony\Spress\Core\DataSource\ItemInterface $item The item * * @return Yosymfony\Spress\Core\ContentManager\Converter\ConverterResult * * @throws RuntimeException If there's no converter for the extension passed */ public function convertItem(ItemInterface $item) { $path = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE); $str = new StringWrapper($path); $extension = $str->getFirstEndMatch($this->textExtensions); if ($extension === '') { $extension = pathinfo($path, PATHINFO_EXTENSION); } return $this->convertContent($item->getContent(), $extension); }