1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-13 18:32:41 +01:00
phorge-phorge/src/applications/diviner/atomizer/DivinerArticleAtomizer.php
epriestley 57a9c3f07c Improve Diviner handling of paths and remarkup
Summary:
  - Currently, the atomizers don't emit atoms with the right file in all cases. Make them always emit it correctly.
  - Currently, we use absolute paths in some cases and relative paths in other cases. Use them consistently: relative when storing/presenting, absolute when accessing data.
  - Don't preserve linebreaks when marking up documentation (documentation is generally wrapped at 80col, but should not be wrapped in this way when displayed).
  - Markup Diviner link rules (albeit uselesly).

Test Plan:
Before:

{F33044}

After:

{F33045}

Reviewers: chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T988

Differential Revision: https://secure.phabricator.com/D4992
2013-02-17 15:40:44 -08:00

35 lines
966 B
PHP

<?php
final class DivinerArticleAtomizer extends DivinerAtomizer {
protected function executeAtomize($file_name, $file_data) {
$atom = $this->newAtom(DivinerAtom::TYPE_ARTICLE)
->setLine(1)
->setLength(count(explode("\n", $file_data)))
->setLanguage('human');
$block = "/**\n".str_replace("\n", "\n * ", $file_data)."\n */";
$atom->setDocblockRaw($block);
$meta = $atom->getDocblockMeta();
$title = idx($meta, 'title');
if (!strlen($title)) {
$title = pht('Untitled Article "%s"', basename($file_name));
$atom->addWarning("Article has no @title!");
$atom->setDocblockMetaValue('title', $title);
}
// If the article has no @name, use the filename after stripping any
// extension.
$name = idx($meta, 'name');
if (!$name) {
$name = basename($file_name);
$name = preg_replace('/\\.[^.]+$/', '', $name);
}
$atom->setName($name);
return array($atom);
}
}