private function publishIndex()
 {
     $index = $this->getPublishCache()->getIndex();
     $refs = array();
     foreach ($index as $hash => $dictionary) {
         $refs[$hash] = DivinerAtomRef::newFromDictionary($dictionary);
     }
     $content = $this->getRenderer()->renderAtomIndex($refs);
     $path = implode(DIRECTORY_SEPARATOR, array($this->getConfig('root'), 'docs', $this->getConfig('name'), 'index.html'));
     Filesystem::writeFile($path, $content);
 }
 public function didMarkupText()
 {
     $engine = $this->getEngine();
     $key = self::KEY_RULE_ATOM_REF;
     $data = $engine->getTextMetadata($key, array());
     $renderer = $engine->getConfig('diviner.renderer');
     foreach ($data as $token => $ref_dict) {
         $ref = DivinerAtomRef::newFromDictionary($ref_dict);
         $title = $ref->getTitle();
         $href = null;
         if ($renderer) {
             // Here, we're generating documentation. If possible, we want to find
             // the real atom ref so we can render the correct default title and
             // render invalid links in an alternate style.
             $ref = $renderer->normalizeAtomRef($ref);
             if ($ref) {
                 $title = nonempty($ref->getTitle(), $ref->getName());
                 $href = $renderer->getHrefForAtomRef($ref);
             }
         } else {
             // Here, we're generating comment text or something like that. Just
             // link to Diviner and let it sort things out.
             $href = id(new PhutilURI('/diviner/find/'))->setQueryParams(array('book' => $ref->getBook(), 'name' => $ref->getName(), 'type' => $ref->getType(), 'context' => $ref->getContext(), 'jump' => true));
         }
         // TODO: This probably is not the best place to do this. Move it somewhere
         // better when it becomes more clear where it should actually go.
         if ($ref) {
             switch ($ref->getType()) {
                 case 'function':
                 case 'method':
                     $title = $title . '()';
                     break;
             }
         }
         if ($this->getEngine()->isTextMode()) {
             if ($href) {
                 $link = $title . ' <' . PhabricatorEnv::getProductionURI($href) . '>';
             } else {
                 $link = $title;
             }
         } else {
             if ($href) {
                 if ($this->getEngine()->isHTMLMailMode()) {
                     $href = PhabricatorEnv::getProductionURI($href);
                 }
                 $link = $this->newTag('a', array('class' => 'atom-ref', 'href' => $href), $title);
             } else {
                 $link = $this->newTag('span', array('class' => 'atom-ref-invalid'), $title);
             }
         }
         $engine->overwriteStoredText($token, $link);
     }
 }
 private function getEdges($node_hash)
 {
     $atom_cache = $this->getAtomCache();
     $atom = $atom_cache->getAtom($node_hash);
     $refs = array();
     // Make the atom depend on its own symbol, so that all atoms with the same
     // symbol are dirtied (e.g., if a codebase defines the function `f()`
     // several times, all of them should be dirtied when one is dirtied).
     $refs[DivinerAtomRef::newFromDictionary($atom)->toHash()] = true;
     foreach (array_merge($atom['extends'], $atom['links']) as $ref_dict) {
         $ref = DivinerAtomRef::newFromDictionary($ref_dict);
         if ($ref->getBook() == $atom['book']) {
             $refs[$ref->toHash()] = true;
         }
     }
     return array_keys($refs);
 }
Esempio n. 4
0
 public static function newFromDictionary(array $dictionary)
 {
     $atom = id(new DivinerAtom())->setBook(idx($dictionary, 'book'))->setType(idx($dictionary, 'type'))->setName(idx($dictionary, 'name'))->setFile(idx($dictionary, 'file'))->setLine(idx($dictionary, 'line'))->setHash(idx($dictionary, 'hash'))->setLength(idx($dictionary, 'length'))->setContext(idx($dictionary, 'context'))->setLanguage(idx($dictionary, 'language'))->setParentHash(idx($dictionary, 'parentHash'))->setDocblockRaw(idx($dictionary, 'docblockRaw'))->setProperties(idx($dictionary, 'properties'));
     foreach (idx($dictionary, 'warnings', array()) as $warning) {
         $atom->addWarning($warning);
     }
     foreach (idx($dictionary, 'childHashes', array()) as $child) {
         $atom->addChildHash($child);
     }
     foreach (idx($dictionary, 'extends', array()) as $extends) {
         $atom->addExtends(DivinerAtomRef::newFromDictionary($extends));
     }
     return $atom;
 }
 public function findAtomByRef(DivinerAtomRef $ref)
 {
     if ($ref->getBook() != $this->getConfig('name')) {
         return null;
     }
     if ($this->atomNameMap === null) {
         $name_map = array();
         foreach ($this->getPublishCache()->getIndex() as $hash => $dict) {
             $name_map[$dict['name']][$hash] = $dict;
         }
         $this->atomNameMap = $name_map;
     }
     $name = $ref->getName();
     if (empty($this->atomNameMap[$name])) {
         return null;
     }
     $candidates = $this->atomNameMap[$name];
     foreach ($candidates as $key => $dict) {
         $candidates[$key] = DivinerAtomRef::newFromDictionary($dict);
         if ($ref->getType()) {
             if ($candidates[$key]->getType() != $ref->getType()) {
                 unset($candidates[$key]);
             }
         }
         if ($ref->getContext()) {
             if ($candidates[$key]->getContext() != $ref->getContext()) {
                 unset($candidates[$key]);
             }
         }
     }
     // If we have exactly one uniquely identifiable atom, return it.
     if (count($candidates) == 1) {
         return $this->getAtomFromNodeHash(last_key($candidates));
     }
     return null;
 }