2014-12-31 11:54:52 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DiffusionReadmeView extends DiffusionView {
|
|
|
|
|
|
|
|
private $path;
|
|
|
|
private $content;
|
|
|
|
|
|
|
|
public function setPath($path) {
|
|
|
|
$this->path = $path;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPath() {
|
|
|
|
return $this->path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setContent($content) {
|
|
|
|
$this->content = $content;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getContent() {
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the markup language a README should be interpreted as.
|
|
|
|
*
|
|
|
|
* @param string Local README path, like "README.txt".
|
|
|
|
* @return string Best markup interpreter (like "remarkup") for this file.
|
|
|
|
*/
|
|
|
|
private function getReadmeLanguage($path) {
|
|
|
|
$path = phutil_utf8_strtolower($path);
|
|
|
|
if ($path == 'readme') {
|
|
|
|
return 'remarkup';
|
|
|
|
}
|
|
|
|
|
|
|
|
$ext = last(explode('.', $path));
|
|
|
|
switch ($ext) {
|
|
|
|
case 'remarkup':
|
|
|
|
case 'md':
|
|
|
|
return 'remarkup';
|
|
|
|
case 'rainbow':
|
|
|
|
return 'rainbow';
|
|
|
|
case 'txt':
|
|
|
|
default:
|
|
|
|
return 'text';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
$readme_path = $this->getPath();
|
|
|
|
$readme_name = basename($readme_path);
|
|
|
|
$interpreter = $this->getReadmeLanguage($readme_name);
|
2015-04-08 09:41:56 -07:00
|
|
|
require_celerity_resource('diffusion-readme-css');
|
2014-12-31 11:54:52 -08:00
|
|
|
|
|
|
|
$content = $this->getContent();
|
|
|
|
|
|
|
|
$class = null;
|
|
|
|
switch ($interpreter) {
|
|
|
|
case 'remarkup':
|
|
|
|
// TODO: This is sketchy, but make sure we hit the markup cache.
|
|
|
|
$markup_object = id(new PhabricatorMarkupOneOff())
|
|
|
|
->setEngineRuleset('diffusion-readme')
|
|
|
|
->setContent($content);
|
|
|
|
$markup_field = 'default';
|
|
|
|
|
|
|
|
$content = id(new PhabricatorMarkupEngine())
|
|
|
|
->setViewer($this->getUser())
|
|
|
|
->addObject($markup_object, $markup_field)
|
|
|
|
->process()
|
|
|
|
->getOutput($markup_object, $markup_field);
|
|
|
|
|
|
|
|
$engine = $markup_object->newMarkupEngine($markup_field);
|
|
|
|
$toc = PhutilRemarkupHeaderBlockRule::renderTableOfContents($engine);
|
|
|
|
if ($toc) {
|
|
|
|
$toc = phutil_tag_div(
|
|
|
|
'phabricator-remarkup-toc',
|
|
|
|
array(
|
|
|
|
phutil_tag_div(
|
|
|
|
'phabricator-remarkup-toc-header',
|
|
|
|
pht('Table of Contents')),
|
|
|
|
$toc,
|
|
|
|
));
|
|
|
|
$content = array($toc, $content);
|
|
|
|
}
|
|
|
|
|
|
|
|
$readme_content = $content;
|
2015-04-08 09:41:56 -07:00
|
|
|
$class = null;
|
2014-12-31 11:54:52 -08:00
|
|
|
break;
|
|
|
|
case 'rainbow':
|
|
|
|
$content = id(new PhutilRainbowSyntaxHighlighter())
|
|
|
|
->getHighlightFuture($content)
|
|
|
|
->resolve();
|
|
|
|
$readme_content = phutil_escape_html_newlines($content);
|
|
|
|
|
|
|
|
require_celerity_resource('syntax-highlighting-css');
|
2015-04-08 09:41:56 -07:00
|
|
|
$class = 'remarkup-code ml';
|
2014-12-31 11:54:52 -08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 'text':
|
|
|
|
$readme_content = phutil_escape_html_newlines($content);
|
2015-04-08 09:41:56 -07:00
|
|
|
$class = 'ml';
|
2014-12-31 11:54:52 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-04-08 09:41:56 -07:00
|
|
|
$readme_content = phutil_tag_div($class, $readme_content);
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader($readme_name);
|
2014-12-31 11:54:52 -08:00
|
|
|
|
2015-04-08 09:41:56 -07:00
|
|
|
return id(new PHUIDocumentView())
|
|
|
|
->setFluid(true)
|
|
|
|
->appendChild($readme_content)
|
|
|
|
->addClass('diffusion-readme-view')
|
[Redesign] Move basefont to Lato, remove Source Sans Pro
Summary: Working towards a more unified look and feel. This brings in Lato as a complete base font over Helvetica Neue, as well as removing Source Sans Pro from DocumentView and Conpherence. Design-wise Lato provides the nice readability at larger font sizes that Source Sans Pro did, with the ability to scale down to tables and UI widgets with ease. This gives us one font instead of two, and now Object descriptions and Timeline posts all can benefit from a consistent, readable font.
Test Plan:
Test main UI, smaller elements like tables, menus, DocumentViews, Previews, Conpherence.
{F498135}
{F498136}
Reviewers: btrahan, epriestley
Reviewed By: epriestley
Subscribers: epriestley, Korvin
Differential Revision: https://secure.phabricator.com/D13276
2015-06-13 20:32:45 +01:00
|
|
|
->setHeader($header);
|
2014-12-31 11:54:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|