protected function createContent($content) { $dir = new Directory(new Root(new Config(), ''), ''); $obj = new Content($dir, ''); $obj->setContent($content); return $obj; }
public static function fromFile(Content $file, $params, ContentType $contentType) { $page = new static($file->getTitle(), $file->getContent()); $page->setFile($file); $page->setParams($params); $page->setContentType($contentType); return $page; }
protected function createContent($content) { $config = new Config(); $config->setDocumentationDirectory(''); $dir = new Directory(new Root($config), ''); $obj = new Content($dir, ''); $obj->setContent($content); return $obj; }
/** * Get the ContentType able to handle this node * * @param Content $node * @return ContentType */ public function getType(Content $node) { $path = $node->getPath() ?: $node->getName(); $extension = pathinfo($path, PATHINFO_EXTENSION); foreach ($this->types as $type) { if (in_array($extension, $type->getExtensions())) { return $type; } } throw new \RuntimeException("no contentType found for {$path}"); }
public function testGetOrCreatePageExisting() { $directory = new Directory($this->getStaticRoot(), 'dir'); $existingEntry = new Content($directory, 'A_Page.html'); $existingEntry->setContent('-'); $entry = Builder::getOrCreatePage($directory, 'A Page.md'); $this->assertSame($directory, $entry->getParent()); $this->assertSame($existingEntry, $entry); $this->assertEquals('dir/A_Page.html', $entry->getUrl()); $this->assertEquals('A_Page.html', $entry->getUri()); $this->assertInstanceOf('Todaymade\\Daux\\Tree\\Content', $entry); }
/** * @dataProvider providerSort */ public function testSort($list, $expected) { shuffle($list); $directory = new Directory(new Root(new Config(), ''), 'dir'); foreach ($list as $value) { $entry = new Content($directory, $value); $entry->setName($value); } $directory->sort(); $final = []; foreach ($directory->getEntries() as $obj) { $final[] = $obj->getName(); } $this->assertEquals($expected, $final); }
private function findImage($src, $tag, Content $file, $callback) { //for protocol relative or http requests : keep the original one if (substr($src, 0, strlen('http')) === 'http' || substr($src, 0, strlen('//')) === '//') { return $src; } //Get the path to the file, relative to the root of the documentation $url = DauxHelper::getCleanPath(dirname($file->getUrl()) . '/' . $src); //Get any file corresponding to the right one $file = DauxHelper::getFile($this->tree, $url); if ($file === false) { return false; } $result = $callback($src, $this->getAttributes($tag), $file); return $result ?: $src; }
/** * @param Directory $parent * @param SplFileInfo $file * @return Content|Raw */ public static function createContent(Directory $parent, SplFileInfo $file) { $name = static::getName($file->getPathname()); $config = $parent->getConfig(); if (!in_array($file->getExtension(), $config['valid_content_extensions'])) { $uri = static::removeSortingInformations($file->getFilename()); $entry = new Raw($parent, $uri, $file); $entry->setTitle(str_replace('_', ' ', static::removeSortingInformations($name))); $entry->setName($name); return $entry; } $uri = static::removeSortingInformations($name); if ($config->isStatic()) { $uri .= '.html'; } $entry = new Content($parent, $uri, $file); if ($entry->getUri() == $config['index_key']) { if ($parent instanceof Root) { $entry->setTitle($config['title']); } else { $entry->setTitle($parent->getTitle()); } } else { $entry->setTitle(str_replace('_', ' ', static::removeSortingInformations($name))); } $entry->setName($name); return $entry; }
/** * @param Directory $parent * @param string $path * @return Content */ public static function getOrCreatePage(Directory $parent, $path) { $title = static::getName($path); // If the file doesn't have an extension, set .md as a default if (pathinfo($path, PATHINFO_EXTENSION) == '') { $path .= '.md'; } $uri = $slug = DauxHelper::slug($title); if ($parent->getConfig()['mode'] === Daux::STATIC_MODE) { $uri = $slug . ".html"; } if (array_key_exists($uri, $parent->getEntries())) { return $parent->getEntries()[$uri]; } $page = new Content($parent, $uri); $page->setContent("-"); //set an almost empty content to avoid problems if ($title == 'index') { // TODO :: clarify the difference between 'index' and '_index' $page->setName('_index' . pathinfo($path, PATHINFO_EXTENSION)); $page->setTitle($parent->getTitle()); } else { $page->setName($path); $page->setTitle($title); } return $page; }