Make some incremental improvements in Diviner

Summary: Gets TOC populated for articles, at least, and fixes a few other things.

Test Plan: {F45474}

Reviewers: chad

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D6144
This commit is contained in:
epriestley
2013-06-06 08:36:51 -07:00
parent 76c8705a27
commit 1433a035c6
11 changed files with 170 additions and 45 deletions

View File

@@ -33,7 +33,7 @@ final class DivinerAtomController extends DivinerController {
return new Aphront404Response();
}
$atom = id(new DivinerAtomQuery())
$symbol = id(new DivinerAtomQuery())
->setViewer($viewer)
->withBookPHIDs(array($book->getPHID()))
->withTypes(array($this->atomType))
@@ -43,31 +43,91 @@ final class DivinerAtomController extends DivinerController {
->needAtoms(true)
->executeOne();
if (!$atom) {
if (!$symbol) {
return new Aphront404Response();
}
$atom = $symbol->getAtom();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName($book->getName())
->setName($book->getShortTitle())
->setHref('/book/'.$book->getName().'/'));
$atom_short_title = $atom->getDocblockMetaValue(
'short',
$symbol->getTitle());
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName($atom->getName()));
->setName($atom_short_title));
$header = id(new PhabricatorHeaderView())->setHeader($atom->getName());
$header = id(new PhabricatorHeaderView())
->setHeader($symbol->getTitle())
->addTag(
id(new PhabricatorTagView())
->setType(PhabricatorTagView::TYPE_STATE)
->setBackgroundColor(PhabricatorTagView::COLOR_BLUE)
->setName($this->renderAtomTypeName($atom->getType())));
$properties = id(new PhabricatorPropertyListView());
$group = $atom->getDocblockMetaValue('group');
if ($group) {
$group_name = $book->getGroupName($group);
} else {
$group_name = null;
}
$properties->addProperty(
pht('Defined'),
$atom->getFile().':'.$atom->getLine());
$field = 'default';
$engine = id(new PhabricatorMarkupEngine())
->setViewer($viewer)
->addObject($symbol, $field)
->process();
$content = $engine->getOutput($symbol, $field);
$toc = $engine->getEngineMetadata(
$symbol,
$field,
PhutilRemarkupEngineRemarkupHeaderBlockRule::KEY_HEADER_TOC,
array());
$document = id(new PHUIDocumentView())
->setBook($book->getTitle(), $group_name)
->setHeader($header)
->appendChild($properties)
->appendChild(
phutil_tag(
'div',
array(
'class' => 'phabricator-remarkup',
),
phutil_safe_html($atom->getContent())));
array(
$content,
)));
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);
}
return $this->buildApplicationPage(
array(
@@ -75,10 +135,14 @@ final class DivinerAtomController extends DivinerController {
$document,
),
array(
'title' => $atom->getName(),
'title' => $symbol->getTitle(),
'dust' => true,
'device' => true,
));
}
private function renderAtomTypeName($name) {
return phutil_utf8_ucwords($name);
}
}