/** * getOptionListYaml returns a YAML dump of default options. * * @param \nochso\WriteMe\Placeholder\OptionList $optionList * * @return string */ public function getOptionListYaml(OptionList $optionList) { $data = []; foreach ($optionList->getOptions() as $option) { Dot::set($data, $option->getPath(), $option->getDefault()); } return Yaml::dump($data); }
/** * askForCustomOption to override frontmatter. * * @param string[] $numberPathMap * @param \nochso\WriteMe\Placeholder\OptionList $defaults * * @return bool True if you should continue asking. False if nothing was entered. */ private function askForCustomOption($numberPathMap, OptionList $defaults) { $number = $this->stdio->ask('Enter the [number] of the option you want to change (leave empty to continue)', ''); // Empty to continue if ($number === '') { return false; } // Ask again for a valid number if (!isset($numberPathMap[$number])) { return true; } $option = $defaults->getOption($numberPathMap[$number]); $currentValue = $this->frontmatter->get($option->getPath(), $option->getDefault()); // Some options take a list of values if (is_array($currentValue)) { $this->askForCustomOptionArray($currentValue, $option); } else { // Otherwise ask for a single value $this->ask($option->getPath(), $option->getDescription(), $currentValue); } // Ask again for another option return true; }
/** * Prepare options by merging default options with frontmatter. * * @param \nochso\WriteMe\Document $document */ public function prepare(Document $document) { $this->options = $this->getDefaultOptionList(); $this->options->prepare($document->getFrontmatter()); }