/** * @param \nochso\WriteMe\Placeholder\Call $call * @param string $templateName 'summary', 'short' or 'full' */ public function api(Call $call, $templateName) { $classes = $this->getClasses($call->getDocument()); $template = new Template(); $template->prepare($classes, $call->getDocument()->getFrontmatter()); $call->replace($template->render($templateName . '.php')); }
/** * @param \nochso\WriteMe\Placeholder\Call $call * * @return \nochso\WriteMe\Markdown\HeaderContent[] */ private function getHeaderContents(Call $call) { $changelogPath = $this->findChangelog($call->getDocument()); $changelog = Document::fromFile($changelogPath); $parser = new HeaderParser(); $headerContentList = $parser->extractHeaderContents($changelog); $maxChanges = $this->options->getValue('changelog.max-changes'); $releaseLevel = $this->options->getValue('changelog.release-level'); $changes = 0; /** @var HeaderContent[] $displayHeaders */ $displayHeaders = []; /** @var HeaderContent $headerContent */ foreach ($headerContentList->getHeaders() as $headerContent) { // This header marks a release if ($headerContent->getLevel() === $releaseLevel) { $changes++; // Stop if we reached the max amount of changes. if ($changes > $maxChanges) { break; } $displayHeaders[] = $headerContent; } // Keep adding sub-HeaderContent if we're within a release if ($changes > 0 && $headerContent->getLevel() > $releaseLevel) { $displayHeaders[] = $headerContent; } } return $displayHeaders; }
/** * `@toc.sub@` collects Markdown headers that are **below** the placeholder and on the same or deeper level. * If there's a header above the placeholder, its depth will be used as a minimum depth. * If there's no header above the placeholder, the first header after the placeholder will be used for the minimum depth. * There is currently no maximum depth for `@toc.sub@`. * * e.g. * ```markdown * # ignore me * * @toc.sub@ * ## sub 1 * # ignore me again * ``` * is converted into * * ```markdown * # ignore me * - [sub 1](#sub-1) * ## sub 1 * # ignore me again * ``` * * @param \nochso\WriteMe\Placeholder\Call $call * @param int $maxDepth How many levels of headers you'd like to keep. * Defaults to zero, meaning all sub-headers are kept. */ public function tocSub(Call $call, $maxDepth = 0) { $parser = new Markdown\HeaderParser(); $headerList = $parser->extractHeaders($call->getDocument()); $lines = Multiline::create($call->getDocument()->getContent()); $lineIndex = $lines->getLineIndexByCharacterPosition($call->getStartPositionOfRawCall()); $headers = $headerList->getHeadersBelowLine($lineIndex); if ($maxDepth > 0) { $minDepth = $this->getMinimumDepth($headers); // Filter headers that are relatively too deep $headers = array_filter($headers, function (Markdown\Header $header) use($minDepth, $maxDepth) { return $header->getLevel() - $minDepth < $maxDepth; }); } $toc = $this->formatTOC($headers); $call->replace($toc); }
public function wildcard(Call $call) { $path = $call->getIdentifier(); if ($call->getMethod() !== null) { $path .= '.' . $call->getMethod(); } $value = $call->getDocument()->getFrontmatter()->get($path); if ($value !== null) { $call->replace($value); } }
/** * Travis CI build status. * * @param \nochso\WriteMe\Placeholder\Call $call * @param string|null $userRepository User/repository, e.g. `nochso/writeme`. Defaults to `composer.name` * @param string|null $branch Optional branch name. */ public function badgeTravis(Call $call, $userRepository = null, $branch = null) { if ($userRepository === null) { $userRepository = $call->getDocument()->getFrontmatter()->get('composer.name'); } if ($userRepository === null) { return; } $image = sprintf('https://api.travis-ci.org/%s.svg', $userRepository); if ($branch !== null) { $image .= '?branch=' . $branch; } $url = 'https://travis-ci.org/' . $userRepository; $this->image($call, $image, 'Travis CI build status', $url); }