public function handle(Document $document) { if ($this->config['remove_from_document']) { $this->remove($document); } $html = view($this->codex->view($this->config['view']), $document->getAttributes())->render(); $document->setContent($html . $document->getContent()); }
public function handle(Menu $menu, $project, $ref) { $project = $project instanceof Project ? $project : $this->codex->projects->get($project); $ref = $ref instanceof Ref ? $ref : $project->refs->get($ref); $this->menu = $menu; $this->project = $project; $this->ref = $ref; $menu->setView($this->codex->view('menus.sidebar')); $this->menu->clear(); $items = $ref->config('menu', []); if (!is_array($items)) { throw CodexException::invalidMenuConfiguration(": menu.yml in [{$this}]"); } $this->recurse($items); }
public function handle(Document $document) { $content = $document->getContent(); $total = preg_match_all($this->config['regex'], $content, $matches); // create root // for each header // create node // if header nr is same as previous, assign to same parent as previous // if header nr is lower then previous, check parent header nr, if header nr lower then parent nr, check parent, etc // if header nr is higher then previous, assign as previous child // Generate TOC Tree from HTML $prevSize = 0; $prevNode = $rootNode = $this->createHeaderNode(0, 'root'); for ($h = 0; $h < $total; $h++) { $original = $matches[0][$h]; $size = (int) $matches[1][$h]; $text = $matches[2][$h]; if (in_array($size, $this->config['disable'], true)) { continue; } $node = $this->createHeaderNode($size, $text); if ($size === $prevSize) { $prevNode->getParent()->addChild($node); $node->setParent($prevNode->getParent()); } elseif ($size < $prevSize) { $parentNode = $prevNode->getParent(); while (true) { if ($size === $parentNode->getValue()->getSize()) { $parentNode->getParent()->addChild($node); $node->setParent($parentNode->getParent()); break; } if ($parentNode === $rootNode) { break; } $parentNode = $parentNode->getParent(); } } elseif ($size > $prevSize) { $prevNode->addChild($node); $node->setParent($prevNode); } $node->getValue()->setSlug($slug = $this->makeSlug($text)); $link = ''; if ($this->config['header_link_show'] === true) { $link = "<p><a name=\"{$slug}\" class=\"{$this->config['header_link_class']}\"></a></p>"; } $replacement = "{$link}<h{$size}>{$text}</h{$size}>"; $content = str_replace($original, $replacement, $content); $prevSize = $size; $prevNode = $node; } $view = $this->codex->view($this->config['view']); $toc = $this->view->make($view, $this->config)->with('items', $rootNode->getChildren())->render(); $this->addScript(); if (count($this->nodes) >= (int) $this->config['minimum_nodes']) { $document->setContent("<ul class=\"{$this->config['list_class']}\">{$toc}</ul>" . $content); } }
protected function render($with = []) { $view = view($this->codex->view('processors.buttons'), $this->config->except('buttons', 'groups')->all())->with($with); return $view->render(); }