3 final class DivinerDefaultRenderer
extends DivinerRenderer
{
5 public function renderAtom(DivinerAtom
$atom) {
7 $this->renderAtomTitle($atom),
8 $this->renderAtomProperties($atom),
9 $this->renderAtomDescription($atom),
15 'class' => 'diviner-atom',
20 protected function renderAtomTitle(DivinerAtom
$atom) {
21 $name = $this->renderAtomName($atom);
22 $type = $this->renderAtomType($atom);
27 'class' => 'atom-title',
29 array($name, ' ', $type));
32 protected function renderAtomName(DivinerAtom
$atom) {
36 'class' => 'atom-name',
38 $this->getAtomName($atom));
41 protected function getAtomName(DivinerAtom
$atom) {
42 if ($atom->getDocblockMetaValue('title')) {
43 return $atom->getDocblockMetaValue('title');
46 return $atom->getName();
49 protected function renderAtomType(DivinerAtom
$atom) {
53 'class' => 'atom-name',
55 $this->getAtomType($atom));
58 protected function getAtomType(DivinerAtom
$atom) {
59 return ucwords($atom->getType());
62 protected function renderAtomProperties(DivinerAtom
$atom) {
63 $props = $this->getAtomProperties($atom);
66 foreach ($props as $prop) {
67 list($key, $value) = $prop;
69 $out[] = phutil_tag('dt', array(), $key);
70 $out[] = phutil_tag('dd', array(), $value);
76 'class' => 'atom-properties',
81 protected function getAtomProperties(DivinerAtom
$atom) {
82 $properties = array();
83 $properties[] = array(
85 $atom->getFile().':'.$atom->getLine(),
91 protected function renderAtomDescription(DivinerAtom
$atom) {
92 $text = $this->getAtomDescription($atom);
93 $engine = $this->getBlockMarkupEngine();
95 $this->pushAtomStack($atom);
96 $description = $engine->markupText($text);
97 $this->popAtomStack();
102 'class' => 'atom-description',
107 protected function getAtomDescription(DivinerAtom
$atom) {
108 return $atom->getDocblockText();
111 public function renderAtomSummary(DivinerAtom
$atom) {
112 $text = $this->getAtomSummary($atom);
113 $engine = $this->getInlineMarkupEngine();
115 $this->pushAtomStack($atom);
116 $summary = $engine->markupText($text);
117 $this->popAtomStack();
122 'class' => 'atom-summary',
127 public function getAtomSummary(DivinerAtom
$atom) {
128 if ($atom->getDocblockMetaValue('summary')) {
129 return $atom->getDocblockMetaValue('summary');
132 $text = $this->getAtomDescription($atom);
133 return PhabricatorMarkupEngine
::summarize($text);
136 public function renderAtomIndex(array $refs) {
137 $refs = msort($refs, 'getSortKey');
139 $groups = mgroup($refs, 'getGroup');
142 foreach ($groups as $group_key => $refs) {
146 'class' => 'atom-group-name',
148 $this->getGroupName($group_key));
151 foreach ($refs as $ref) {
152 $items[] = phutil_tag(
155 'class' => 'atom-index-item',
158 $this->renderAtomRefLink($ref),
167 'class' => 'atom-index-list',
175 'class' => 'atom-index',
180 protected function getGroupName($group_key) {
184 protected function getBlockMarkupEngine() {
185 $engine = PhabricatorMarkupEngine
::newMarkupEngine(array());
187 $engine->setConfig('preserve-linebreaks', false);
188 $engine->setConfig('viewer', new PhabricatorUser());
189 $engine->setConfig('diviner.renderer', $this);
190 $engine->setConfig('header.generate-toc', true);
195 protected function getInlineMarkupEngine() {
196 return $this->getBlockMarkupEngine();
199 public function normalizeAtomRef(DivinerAtomRef
$ref) {
200 if (!strlen($ref->getBook())) {
201 $ref->setBook($this->getConfig('name'));
204 if ($ref->getBook() != $this->getConfig('name')) {
205 // If the ref is from a different book, we can't normalize it.
206 // Just return it as-is if it has enough information to resolve.
207 if ($ref->getName() && $ref->getType()) {
214 $atom = $this->getPublisher()->findAtomByRef($ref);
216 return $atom->getRef();
222 protected function getAtomHrefDepth(DivinerAtom
$atom) {
223 if ($atom->getContext()) {
230 public function getHrefForAtomRef(DivinerAtomRef
$ref) {
233 $atom = $this->peekAtomStack();
235 $depth = $this->getAtomHrefDepth($atom);
238 $href = str_repeat('../', $depth);
240 $book = $ref->getBook();
241 $type = $ref->getType();
242 $name = $ref->getName();
243 $context = $ref->getContext();
245 $href .= $book.'/'.$type.'/';
246 if ($context !== null) {
247 $href .= $context.'/';
249 $href .= $name.'/index.html';
254 protected function renderAtomRefLink(DivinerAtomRef
$ref) {
258 'href' => $this->getHrefForAtomRef($ref),