Example #1
0
 /**
  * @return \nochso\WriteMe\Document
  */
 public function interactiveTemplateToDocument()
 {
     $template = new InteractiveTemplate($this->stdio, $this->placeholders);
     $availableTemplates = $template->getAvailableTemplates();
     $templateIndex = $this->stdio->chooseFromList($availableTemplates, 'Choose an interactive template', true);
     $templateFilepath = $availableTemplates[$templateIndex];
     $filepath = $this->stdio->ask('Filepath of your new customized template', 'WRITEME.md');
     $targetPath = $this->stdio->ask('Filepath to final result file', 'README.md');
     $generatedContent = $template->render($templateFilepath);
     $doc = new Document($generatedContent, $filepath);
     $doc->setFrontmatter($template->getFrontmatter());
     $doc->getFrontmatter()->set('target', $targetPath);
     return $doc;
 }
Example #2
0
 private function askForCustomOptionArray($currentValue, Option $option)
 {
     $da = new DotArray($currentValue);
     $this->stdio->outln($option->getPath());
     $this->stdio->outln($option->getDescription());
     $continue = true;
     while ($continue) {
         $this->stdio->displayList($da->flatten());
         $actions = ['delete', 'clear all', 'add', 'replace', 'skip'];
         $action = $this->stdio->chooseAction($actions);
         switch ($action) {
             case 'delete':
                 $index = $this->stdio->chooseFromList($da->flatten(), 'Item to delete', false);
                 if ($index !== null) {
                     $da->remove($index);
                 }
                 break;
             case 'clear all':
                 $da = new DotArray();
                 break;
             case 'add':
                 $newValue = $this->stdio->ask('Enter value of the new item');
                 $da = new DotArray(array_merge($da->getArray(), [$newValue]));
                 break;
             case 'replace':
                 $index = $this->stdio->chooseFromList($da->flatten(), 'Item to replace', false);
                 if ($index !== null) {
                     $da->set($index, $this->stdio->ask('Enter new value'));
                 }
                 break;
             case 'skip':
                 $continue = false;
                 break;
         }
     }
     $this->frontmatter->set($option->getPath(), $da->getArray());
 }