Ejemplo n.º 1
0
 protected function renderResultList(array $symbols, PhabricatorSavedQuery $query, array $handles)
 {
     assert_instances_of($symbols, 'DivinerLiveSymbol');
     $viewer = $this->requireViewer();
     $list = id(new PHUIObjectItemListView())->setUser($viewer);
     foreach ($symbols as $symbol) {
         $type = $symbol->getType();
         $type_name = DivinerAtom::getAtomTypeNameString($type);
         $item = id(new PHUIObjectItemView())->setHeader($symbol->getTitle())->setHref($symbol->getURI())->addAttribute($symbol->getSummary())->addIcon('none', $type_name);
         $list->addItem($item);
     }
     return $list;
 }
Ejemplo n.º 2
0
 protected function renderAtomList(array $symbols)
 {
     assert_instances_of($symbols, 'DivinerLiveSymbol');
     $list = array();
     foreach ($symbols as $symbol) {
         switch ($symbol->getType()) {
             case DivinerAtom::TYPE_FUNCTION:
                 $title = $symbol->getTitle() . '()';
                 break;
             default:
                 $title = $symbol->getTitle();
                 break;
         }
         $item = id(new DivinerBookItemView())->setTitle($title)->setHref($symbol->getURI())->setSubtitle($symbol->getSummary())->setType(DivinerAtom::getAtomTypeNameString($symbol->getType()));
         $list[] = $item;
     }
     return $list;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getUser();
     $book_name = $request->getURIData('book');
     $atom_type = $request->getURIData('type');
     $atom_name = $request->getURIData('name');
     $atom_context = nonempty($request->getURIData('context'), null);
     $atom_index = nonempty($request->getURIData('index'), null);
     require_celerity_resource('diviner-shared-css');
     $book = id(new DivinerBookQuery())->setViewer($viewer)->withNames(array($book_name))->executeOne();
     if (!$book) {
         return new Aphront404Response();
     }
     $symbol = id(new DivinerAtomQuery())->setViewer($viewer)->withBookPHIDs(array($book->getPHID()))->withTypes(array($atom_type))->withNames(array($atom_name))->withContexts(array($atom_context))->withIndexes(array($atom_index))->withIsDocumentable(true)->needAtoms(true)->needExtends(true)->needChildren(true)->executeOne();
     if (!$symbol) {
         return new Aphront404Response();
     }
     $atom = $symbol->getAtom();
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->setBorder(true);
     $crumbs->addTextCrumb($book->getShortTitle(), '/book/' . $book->getName() . '/');
     $atom_short_title = $atom ? $atom->getDocblockMetaValue('short', $symbol->getTitle()) : $symbol->getTitle();
     $crumbs->addTextCrumb($atom_short_title);
     $header = id(new PHUIHeaderView())->setHeader($this->renderFullSignature($symbol))->addTag(id(new PHUITagView())->setType(PHUITagView::TYPE_STATE)->setBackgroundColor(PHUITagView::COLOR_BLUE)->setName(DivinerAtom::getAtomTypeNameString($atom ? $atom->getType() : $symbol->getType())));
     $properties = new PHUIPropertyListView();
     $group = $atom ? $atom->getProperty('group') : $symbol->getGroupName();
     if ($group) {
         $group_name = $book->getGroupName($group);
     } else {
         $group_name = null;
     }
     $prop_list = new PHUIPropertyGroupView();
     $prop_list->addPropertyList($properties);
     $document = id(new PHUIDocumentView())->setBook($book->getTitle(), $group_name)->setHeader($header)->addClass('diviner-view')->appendChild($prop_list);
     if ($atom) {
         $this->buildDefined($properties, $symbol);
         $this->buildExtendsAndImplements($properties, $symbol);
         $this->buildRepository($properties, $symbol);
         $warnings = $atom->getWarnings();
         if ($warnings) {
             $warnings = id(new PHUIInfoView())->setErrors($warnings)->setTitle(pht('Documentation Warnings'))->setSeverity(PHUIInfoView::SEVERITY_WARNING);
         }
         $document->appendChild($warnings);
     }
     $methods = $this->composeMethods($symbol);
     $field = 'default';
     $engine = id(new PhabricatorMarkupEngine())->setViewer($viewer)->addObject($symbol, $field);
     foreach ($methods as $method) {
         foreach ($method['atoms'] as $matom) {
             $engine->addObject($matom, $field);
         }
     }
     $engine->process();
     if ($atom) {
         $content = $this->renderDocumentationText($symbol, $engine);
         $document->appendChild($content);
     }
     $toc = $engine->getEngineMetadata($symbol, $field, PhutilRemarkupHeaderBlockRule::KEY_HEADER_TOC, array());
     if (!$atom) {
         $document->appendChild(id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_NOTICE)->appendChild(pht('This atom no longer exists.')));
     }
     if ($atom) {
         $document->appendChild($this->buildParametersAndReturn(array($symbol)));
     }
     if ($methods) {
         $tasks = $this->composeTasks($symbol);
         if ($tasks) {
             $methods_by_task = igroup($methods, 'task');
             // Add phantom tasks for methods which have a "@task" name that isn't
             // documented anywhere, or methods that have no "@task" name.
             foreach ($methods_by_task as $task => $ignored) {
                 if (empty($tasks[$task])) {
                     $tasks[$task] = array('name' => $task, 'title' => $task ? $task : pht('Other Methods'), 'defined' => $symbol);
                 }
             }
             $section = id(new DivinerSectionView())->setHeader(pht('Tasks'));
             foreach ($tasks as $spec) {
                 $section->addContent(id(new PHUIHeaderView())->setNoBackground(true)->setHeader($spec['title']));
                 $task_methods = idx($methods_by_task, $spec['name'], array());
                 $inner_box = id(new PHUIBoxView())->addPadding(PHUI::PADDING_LARGE_LEFT)->addPadding(PHUI::PADDING_LARGE_RIGHT)->addPadding(PHUI::PADDING_LARGE_BOTTOM);
                 $box_content = array();
                 if ($task_methods) {
                     $list_items = array();
                     foreach ($task_methods as $task_method) {
                         $atom = last($task_method['atoms']);
                         $item = $this->renderFullSignature($atom, true);
                         if (strlen($atom->getSummary())) {
                             $item = array($item, " — ", $atom->getSummary());
                         }
                         $list_items[] = phutil_tag('li', array(), $item);
                     }
                     $box_content[] = phutil_tag('ul', array('class' => 'diviner-list'), $list_items);
                 } else {
                     $no_methods = pht('No methods for this task.');
                     $box_content = phutil_tag('em', array(), $no_methods);
                 }
                 $inner_box->appendChild($box_content);
                 $section->addContent($inner_box);
             }
             $document->appendChild($section);
         }
         $section = id(new DivinerSectionView())->setHeader(pht('Methods'));
         foreach ($methods as $spec) {
             $matom = last($spec['atoms']);
             $method_header = id(new PHUIHeaderView())->setNoBackground(true);
             $inherited = $spec['inherited'];
             if ($inherited) {
                 $method_header->addTag(id(new PHUITagView())->setType(PHUITagView::TYPE_STATE)->setBackgroundColor(PHUITagView::COLOR_GREY)->setName(pht('Inherited')));
             }
             $method_header->setHeader($this->renderFullSignature($matom));
             $section->addContent(array($method_header, $this->renderMethodDocumentationText($symbol, $spec, $engine), $this->buildParametersAndReturn($spec['atoms'])));
         }
         $document->appendChild($section);
     }
     if ($toc) {
         $side = new PHUIListView();
         $side->addMenuItem(id(new PHUIListItemView())->setName(pht('Contents'))->setType(PHUIListItemView::TYPE_LABEL));
         foreach ($toc as $key => $entry) {
             $side->addMenuItem(id(new PHUIListItemView())->setName($entry[1])->setHref('#' . $key));
         }
         $document->setSideNav($side, PHUIDocumentView::NAV_TOP);
     }
     return $this->buildApplicationPage(array($crumbs, $document), array('title' => $symbol->getTitle()));
 }