Example #1
0
 public function writemePlaceholderDocs(Call $call)
 {
     $classes = [];
     foreach ($this->placeholders->toArray() as $placeholder) {
         $classes[get_class($placeholder)] = ReflectionClass::createFromInstance($placeholder);
     }
     $template = new TemplateData();
     $template->setHeaderStartLevel($this->options->getValue('placeholder-docs.header-depth'));
     $template->prepare($classes, $this->placeholders);
     $docs = $template->render('full.php');
     $docs = (new Converter())->escape($docs);
     $call->replace($docs);
 }
 public function testGetMethodsForCall_SpecificPlaceholdersHavePriorityOverPotentialFrontmatter()
 {
     // Frontmatter must not accidentally replace a @toc@ call even though it *theoretically* would be frontmatter.
     $collection = new PlaceholderCollection([new TOC(), new Frontmatter()]);
     $document = new Document("---\ntoc: foo\n---\n@toc@");
     $call = Call::extractFirstCall($document, Placeholder::PRIORITY_FIRST);
     $methods = $collection->getMethodsForCall($call);
     $this->assertCount(0, $methods);
     $tocCall = Call::extractFirstCall($document, Placeholder::PRIORITY_LAST);
     $methods = $collection->getMethodsForCall($tocCall);
     $this->assertCount(1, $methods);
     $this->assertSame(TOC::class, get_class($methods[0]->getPlaceholder()));
 }
Example #3
0
 /**
  * askForCustomPlaceholderOptions interactively.
  *
  * Placeholders know their default options. The user can override these defaults.
  * If the user does not override the defaults, nothing is added to the frontmatter.
  *
  * @param string $placeholderIdentifier Identifier of the placeholder.
  *
  * @return bool True on success. False when the placeholder is not known.
  */
 public function askForCustomPlaceholderOptionList($placeholderIdentifier)
 {
     $placeholder = $this->placeholders->getPlaceholderByClassName($placeholderIdentifier);
     if ($placeholder === null) {
         return false;
     }
     $defaults = $placeholder->getDefaultOptionList();
     $continue = true;
     while ($continue) {
         $numberPathMap = $this->showPlaceholderOptions($defaults);
         $continue = $this->askForCustomOption($numberPathMap, $defaults);
     }
     return true;
 }
Example #4
0
 public function __construct(array $globals = null)
 {
     $this->version = new VersionInfo('writeme', '0.1.0', '<<green>>%s<<reset>> <<yellow>>%s<<reset>>');
     $clif = new CliFactory();
     if ($globals === null) {
         $globals = $GLOBALS;
     }
     $this->context = $clif->newContext($globals);
     $this->stdio = Stdio::create();
     $this->placeholders = new PlaceholderCollection([new Frontmatter(), new TOC(), new API(), new Changelog(), new Badge()]);
     $placeholderDocs = new PlaceholderDocs();
     $placeholderDocs->setPlaceholderCollection($this->placeholders);
     $this->placeholders->add($placeholderDocs);
     $this->converter = new Converter();
 }
Example #5
0
 /**
  * applyPlaceholdersAtPriority by calling only the placeholders that are relevant at a certain priority.
  *
  * @param Document                                          $document     The document to modify.
  * @param int                                               $priority     The priority stage to consider.
  *                                                                        Placeholders are only called when they've
  *                                                                        listed that priority. See
  *                                                                        `Placeholder::getCallPriorities()`
  * @param \nochso\WriteMe\Placeholder\PlaceholderCollection $placeholders
  */
 private function applyPlaceholdersAtPriority(Document $document, $priority, PlaceholderCollection $placeholders)
 {
     $offset = 0;
     $call = Call::extractFirstCall($document, $priority, $offset);
     while ($call !== null) {
         $methods = $placeholders->getMethodsForCall($call);
         $isReplaced = false;
         foreach ($methods as $method) {
             $method->call($call);
             if ($call->isReplaced()) {
                 $isReplaced = true;
                 break;
             }
         }
         if ($isReplaced) {
             // Anything could have changed in content. Start from the beginning.
             $offset = 0;
         } else {
             // The call was skipped by all placeholders. Ignore it at this priority.
             $offset = $call->getEndPositionOfRawCall();
         }
         $call = Call::extractFirstCall($document, $priority, $offset);
     }
 }
Example #6
0
 /**
  * @param \nochso\WriteMe\Interfaces\Placeholder $placeholder
  *
  * @return \nochso\WriteMe\Reflection\Method[]
  */
 public function getMethodsForPlaceholder(Placeholder $placeholder)
 {
     return $this->placeholders->getMethodsForPlaceholder($placeholder);
 }