@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow Diviner to render quasi-documentation

Summary: Take a few more steps forward toward usability.

Test Plan: {F33040}

Reviewers: chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T988

Differential Revision: https://secure.phabricator.com/D4991

+162 -8
+158 -8
src/applications/diviner/renderer/DivinerDefaultRenderer.php
··· 3 3 final class DivinerDefaultRenderer extends DivinerRenderer { 4 4 5 5 public function renderAtom(DivinerAtom $atom) { 6 - return "ATOM: ".$atom->getType()." ".$atom->getName()."!"; 6 + $out = array( 7 + $this->renderAtomTitle($atom), 8 + $this->renderAtomProperties($atom), 9 + $this->renderAtomDescription($atom), 10 + ); 11 + 12 + return phutil_tag( 13 + 'div', 14 + array( 15 + 'class' => 'diviner-atom', 16 + ), 17 + $out); 18 + } 19 + 20 + protected function renderAtomTitle(DivinerAtom $atom) { 21 + $name = $this->renderAtomName($atom); 22 + $type = $this->renderAtomType($atom); 23 + 24 + return phutil_tag( 25 + 'h1', 26 + array( 27 + 'class' => 'atom-title', 28 + ), 29 + array($name, ' ', $type)); 30 + } 31 + 32 + protected function renderAtomName(DivinerAtom $atom) { 33 + return phutil_tag( 34 + 'div', 35 + array( 36 + 'class' => 'atom-name', 37 + ), 38 + $this->getAtomName($atom)); 39 + } 40 + 41 + protected function getAtomName(DivinerAtom $atom) { 42 + if ($atom->getDocblockMetaValue('title')) { 43 + return $atom->getDocblockMetaValue('title'); 44 + } 45 + 46 + return $atom->getName(); 47 + } 48 + 49 + protected function renderAtomType(DivinerAtom $atom) { 50 + return phutil_tag( 51 + 'div', 52 + array( 53 + 'class' => 'atom-name', 54 + ), 55 + $this->getAtomType($atom)); 56 + } 57 + 58 + protected function getAtomType(DivinerAtom $atom) { 59 + return ucwords($atom->getType()); 60 + } 61 + 62 + protected function renderAtomProperties(DivinerAtom $atom) { 63 + $props = $this->getAtomProperties($atom); 64 + 65 + $out = array(); 66 + foreach ($props as $prop) { 67 + list($key, $value) = $prop; 68 + 69 + $out[] = phutil_tag('dt', array(), $key); 70 + $out[] = phutil_tag('dd', array(), $value); 71 + } 72 + 73 + return phutil_tag( 74 + 'dl', 75 + array( 76 + 'class' => 'atom-properties', 77 + ), 78 + $out); 79 + } 80 + 81 + protected function getAtomProperties(DivinerAtom $atom) { 82 + $properties = array(); 83 + $properties[] = array( 84 + pht('Defined'), 85 + $atom->getFile().':'.$atom->getLine(), 86 + ); 87 + 88 + return $properties; 89 + } 90 + 91 + protected function renderAtomDescription(DivinerAtom $atom) { 92 + $text = $this->getAtomDescription($atom); 93 + $engine = $this->getBlockMarkupEngine(); 94 + return phutil_tag( 95 + 'div', 96 + array( 97 + 'class' => 'atom-description', 98 + ), 99 + $engine->markupText($text)); 100 + } 101 + 102 + protected function getAtomDescription(DivinerAtom $atom) { 103 + return $atom->getDocblockText(); 7 104 } 8 105 9 106 public function renderAtomSummary(DivinerAtom $atom) { 10 - return "A lovely atom named ".$atom->getName(); 107 + $text = $this->getAtomSummary($atom); 108 + $engine = $this->getInlineMarkupEngine(); 109 + return phutil_tag( 110 + 'span', 111 + array( 112 + 'class' => 'atom-summary', 113 + ), 114 + $engine->markupText($text)); 115 + } 116 + 117 + protected function getAtomSummary(DivinerAtom $atom) { 118 + if ($atom->getDocblockMetaValue('summary')) { 119 + return $atom->getDocblockMetaValue('summary'); 120 + } 121 + 122 + $text = $this->getAtomDescription($atom); 123 + return PhabricatorMarkupEngine::summarize($text); 11 124 } 12 125 13 126 public function renderAtomIndex(array $refs) { ··· 17 130 18 131 $out = array(); 19 132 foreach ($groups as $group_key => $refs) { 20 - $out[] = '<h1>'.$group_key.'</h1>'; 21 - $out[] = '<ul>'; 133 + $out[] = phutil_tag( 134 + 'h1', 135 + array( 136 + 'class' => 'atom-group-name', 137 + ), 138 + $this->getGroupName($group_key)); 139 + 140 + $items = array(); 22 141 foreach ($refs as $ref) { 23 - $out[] = '<li>'.$ref->getName().' - '.$ref->getSummary().'</li>'; 142 + $items[] = phutil_tag( 143 + 'li', 144 + array( 145 + 'class' => 'atom-index-item', 146 + ), 147 + array( 148 + $ref->getName(), 149 + ' - ', 150 + $ref->getSummary(), 151 + )); 24 152 } 25 - $out[] = '</ul>'; 153 + 154 + $out[] = phutil_tag( 155 + 'ul', 156 + array( 157 + 'class' => 'atom-index-list', 158 + ), 159 + $items); 26 160 } 27 - $out = implode("\n", $out); 28 161 29 - return $out; 162 + return phutil_tag( 163 + 'div', 164 + array( 165 + 'class' => 'atom-index', 166 + ), 167 + $out); 168 + } 169 + 170 + protected function getGroupName($group_key) { 171 + return $group_key; 172 + } 173 + 174 + protected function getBlockMarkupEngine() { 175 + return PhabricatorMarkupEngine::newMarkupEngine(array()); 176 + } 177 + 178 + protected function getInlineMarkupEngine() { 179 + return $this->getBlockMarkupEngine(); 30 180 } 31 181 32 182
+4
src/applications/diviner/workflow/DivinerGenerateWorkflow.php
··· 392 392 $atom_cache = $this->getAtomCache(); 393 393 $atom = $atom_cache->getAtom($node_hash); 394 394 395 + if (!$atom) { 396 + throw new Exception("No such atom with node hash '{$node_hash}'!"); 397 + } 398 + 395 399 $ref = DivinerAtomRef::newFromDictionary($atom['ref']); 396 400 return $ref->toHash(); 397 401 }