Exemplo n.º 1
0
 public function handle(Document $document)
 {
     $this->buttons = new Collection();
     // Merge project and document level config
     $this->config->customMerge($document->attr('buttons', []));
     $html = call_user_func([$this, 'handle' . ucfirst($this->config['type']) . 'Type']);
     $document->setContent($html . $document->getContent());
 }
Exemplo n.º 2
0
 public function run($name, Document $document)
 {
     /** @var Processor $annotation */
     $this->currentDocument = $document;
     $project = $document->getProject();
     $processor = $this->get($name);
     if ($processor->plugin && false === $this->addons->plugins->canRunPlugin($processor->plugin)) {
         throw CodexException::because("Cannot run processor [{$name}] belonging to plugin [{$processor->plugin}] because the plugin can not run. Ensure the plugin is installed and enabled");
     }
     // hook point before can prevent the processor from running
     if (false === $this->hookPoint('addons:processor:before', [$name])) {
         return $processor;
     }
     $instance = $this->getInstance($name);
     $annotation = $processor['annotation'];
     if ($annotation->config !== false) {
         // get default config
         if (!property_exists($instance, $annotation->config)) {
             throw CodexException::because('Config not found for ' . $processor['class']);
         }
         $config = $instance->{$annotation->config};
         $config = array_replace_recursive($config, $project->config('processors.' . $name, []), $document->attr('processors.' . $name, []));
         $instance->{$annotation->config} = new Collection($config);
     }
     if (property_exists($instance, 'codex')) {
         $instance->codex = $document->getCodex();
     }
     if (property_exists($instance, 'project')) {
         $instance->project = $document->getProject();
     }
     if (property_exists($instance, 'document')) {
         $instance->document = $document;
     }
     // hook point after can prevent the processor from running
     if (false === $this->hookPoint('addons:processor:after', [$name, $annotation, $instance])) {
         return $processor;
     }
     $this->app->call([$instance, $annotation->method], compact('document'));
     return $processor;
 }
Exemplo n.º 3
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.º 4
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.º 5
0
 protected function remove(Document $d)
 {
     if ($d->attr('title', false) !== false) {
         $d->setContent(preg_replace($this->config['remove_regex'], '', $d->getContent(), 1));
     }
 }
Exemplo n.º 6
0
 public function printValue($isCloser = false, $key, $default = null)
 {
     return $this->document->attr($key, $default);
 }