Exemplo n.º 1
0
 /**
  * recurse method
  *
  * @param array  $items
  * @param string $parentId
  */
 protected function recurse($items = [], $parentId = 'root')
 {
     foreach ($items as $item) {
         $link = '#';
         $type = null;
         if (array_key_exists('document', $item)) {
             $type = 'document';
             // remove .md extension if present
             $path = ends_with($item['document'], ['.md']) ? Str::remove($item['document'], '.md') : $item['document'];
             $link = $this->codex->url($this->ref->getProject(), $this->ref->getName(), $path);
         } elseif (array_key_exists('href', $item)) {
             $type = 'href';
             $link = $item['href'];
         }
         $id = md5($item['name'] . $link);
         $node = $this->menu->add($id, $item['name'], $parentId);
         $node->setAttribute('href', $link);
         $node->setAttribute('id', $id);
         if (isset($path)) {
             $node->setMeta('path', $path);
         }
         if (isset($item['icon'])) {
             $node->setMeta('icon', $item['icon']);
         }
         if (isset($item['children'])) {
             $type = 'parent';
         }
         $node->setMeta('type', $type);
         if (isset($item['children'])) {
             $this->recurse($item['children'], $id);
         }
     }
 }
Exemplo n.º 2
0
 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());
 }
Exemplo n.º 3
0
 /**
  * Set the codex value
  *
  * @param \Codex\Contracts\Codex $codex
  *
  * @return CodexTrait
  */
 public function setCodex(Codex $codex)
 {
     $this->codex = $codex;
     if (method_exists($this, 'setContainer')) {
         $this->setContainer($codex->getContainer());
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Handle an incoming request.
  *
  * @param  Request $request
  * @param  Closure $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     try {
         /** @var \Illuminate\Http\Response $response */
         $response = $next($request);
     } catch (Exception $e) {
         $response = $this->handleException($request, $e);
     }
     if ($this->codex->config('dev.enabled', false) === true && $this->codex->config('dev.debugbar', false) === true) {
     }
     $this->codex->config('dev.debugbar', false) && $this->handleDebugbar($response);
     $this->codex->config('dev.hookpoints', false) && $this->handleHookPoints();
     return $response;
 }
Exemplo n.º 5
0
 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);
     }
 }
Exemplo n.º 6
0
 public function register()
 {
     $app = parent::register();
     if ($app['config']->get('codex.http.enabled', false)) {
         $this->registerHttp();
     }
     Codex::extend('auth', CodexAuth::class);
     return $app;
 }
 /**
  * startMiddlewarePlugin method
  *
  * @param Application $app
  */
 protected function startProvideCodexPluginServicePlugin($app)
 {
     $this->onRegister('codex', function ($app) {
         $this->projectConfig($this->project);
         $this->documentAttributes($this->document);
         foreach ($this->views as $k => $v) {
             $this->view($k, $v);
         }
         // todo ex tend
         foreach ($this->routeExclusions as $exclusion) {
             $this->excludeRoute($exclusion);
         }
         foreach ($this->extend as $target => $extensions) {
             foreach ($extensions as $name => $extension) {
                 Codex::registerExtension($target, $name, $extension);
             }
         }
     });
 }
Exemplo n.º 8
0
 /**
  * This will get the configured macros. It merges (if defined) the global config, project config and document attributes.
  *
  * Project macros will overide global macros with the same name.
  * Document macros will overide project macros with the same name.
  * Other then that, everything will be merged/inherited.
  *
  * @return array The collected macros as id(used for regex) > handler(the class string name with @ method callsign)
  */
 protected function getAllMacroDefinitions()
 {
     $tags = $this->codex->config('processors.macros', []);
     $tags = array_merge($tags, $this->project->config('processors.macros', []));
     return array_merge($tags, $this->document->attr('processors.macros', []));
 }
Exemplo n.º 9
0
 /**
  * @Hook("constructed")
  * @param \Codex\Contracts\Codex $codex
  */
 public function codexConstructed(Codex $codex)
 {
     $codex->extend('auth', CodexAuth::class);
 }
Exemplo n.º 10
0
 public function getLinkActions()
 {
     $definitions = $this->codex->config('processors.links', []);
     $definitions = array_merge($definitions, $this->config['links']);
     return array_merge($definitions, $this->document->attr('processors.links', []));
 }
Exemplo n.º 11
0
 protected function render($with = [])
 {
     $view = view($this->codex->view('processors.buttons'), $this->config->except('buttons', 'groups')->all())->with($with);
     return $view->render();
 }
Exemplo n.º 12
0
 protected function registerCodex()
 {
     Codex::registerExtension('codex', 'menus', 'codex.menus');
     Codex::registerExtension('codex', 'theme', 'codex.helpers.theme');
     Codex::registerExtension('codex', 'cache', 'codex.helpers.cache');
     Codex::registerExtension('codex', 'projects', 'codex.projects');
     Codex::registerExtension('codex.project', 'refs', 'codex.refs');
     Codex::registerExtension('codex.ref', 'documents', 'codex.documents');
 }
Exemplo n.º 13
0
 public function getData()
 {
     return \Codex\Codex::getExtenableProperty('extensions');
 }