[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DivinerDefaultRenderer extends DivinerRenderer { 4 5 public function renderAtom(DivinerAtom $atom) { 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 95 $this->pushAtomStack($atom); 96 $description = $engine->markupText($text); 97 $this->popAtomStack($atom); 98 99 return phutil_tag( 100 'div', 101 array( 102 'class' => 'atom-description', 103 ), 104 $description); 105 } 106 107 protected function getAtomDescription(DivinerAtom $atom) { 108 return $atom->getDocblockText(); 109 } 110 111 public function renderAtomSummary(DivinerAtom $atom) { 112 $text = $this->getAtomSummary($atom); 113 $engine = $this->getInlineMarkupEngine(); 114 115 $this->pushAtomStack($atom); 116 $summary = $engine->markupText($text); 117 $this->popAtomStack(); 118 119 return phutil_tag( 120 'span', 121 array( 122 'class' => 'atom-summary', 123 ), 124 $summary); 125 } 126 127 public function getAtomSummary(DivinerAtom $atom) { 128 if ($atom->getDocblockMetaValue('summary')) { 129 return $atom->getDocblockMetaValue('summary'); 130 } 131 132 $text = $this->getAtomDescription($atom); 133 return PhabricatorMarkupEngine::summarize($text); 134 } 135 136 public function renderAtomIndex(array $refs) { 137 $refs = msort($refs, 'getSortKey'); 138 139 $groups = mgroup($refs, 'getGroup'); 140 141 $out = array(); 142 foreach ($groups as $group_key => $refs) { 143 $out[] = phutil_tag( 144 'h1', 145 array( 146 'class' => 'atom-group-name', 147 ), 148 $this->getGroupName($group_key)); 149 150 $items = array(); 151 foreach ($refs as $ref) { 152 $items[] = phutil_tag( 153 'li', 154 array( 155 'class' => 'atom-index-item', 156 ), 157 array( 158 $this->renderAtomRefLink($ref), 159 ' - ', 160 $ref->getSummary(), 161 )); 162 } 163 164 $out[] = phutil_tag( 165 'ul', 166 array( 167 'class' => 'atom-index-list', 168 ), 169 $items); 170 } 171 172 return phutil_tag( 173 'div', 174 array( 175 'class' => 'atom-index', 176 ), 177 $out); 178 } 179 180 protected function getGroupName($group_key) { 181 return $group_key; 182 } 183 184 protected function getBlockMarkupEngine() { 185 $engine = PhabricatorMarkupEngine::newMarkupEngine(array()); 186 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); 191 192 return $engine; 193 } 194 195 protected function getInlineMarkupEngine() { 196 return $this->getBlockMarkupEngine(); 197 } 198 199 public function normalizeAtomRef(DivinerAtomRef $ref) { 200 if (!strlen($ref->getBook())) { 201 $ref->setBook($this->getConfig('name')); 202 } 203 204 if ($ref->getBook() != $this->getConfig('name')) { 205 // If the ref is from a different book, we can't normalize it. Just return 206 // it as-is if it has enough information to resolve. 207 if ($ref->getName() && $ref->getType()) { 208 return $ref; 209 } else { 210 return null; 211 } 212 } 213 214 $atom = $this->getPublisher()->findAtomByRef($ref); 215 if ($atom) { 216 return $atom->getRef(); 217 } 218 219 return null; 220 } 221 222 protected function getAtomHrefDepth(DivinerAtom $atom) { 223 if ($atom->getContext()) { 224 return 4; 225 } else { 226 return 3; 227 } 228 } 229 230 public function getHrefForAtomRef(DivinerAtomRef $ref) { 231 $depth = 1; 232 233 $atom = $this->peekAtomStack(); 234 if ($atom) { 235 $depth = $this->getAtomHrefDepth($atom); 236 } 237 238 $href = str_repeat('../', $depth); 239 240 $book = $ref->getBook(); 241 $type = $ref->getType(); 242 $name = $ref->getName(); 243 $context = $ref->getContext(); 244 245 $href .= $book.'/'.$type.'/'; 246 if ($context !== null) { 247 $href .= $context.'/'; 248 } 249 $href .= $name.'/index.html'; 250 251 return $href; 252 } 253 254 protected function renderAtomRefLink(DivinerAtomRef $ref) { 255 return phutil_tag( 256 'a', 257 array( 258 'href' => $this->getHrefForAtomRef($ref), 259 ), 260 $ref->getTitle()); 261 } 262 263 264 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |