Path: blob/master/src/applications/diffusion/view/DiffusionReadmeView.php
12242 views
<?php12final class DiffusionReadmeView extends DiffusionView {34private $path;5private $content;67public function setPath($path) {8$this->path = $path;9return $this;10}1112public function getPath() {13return $this->path;14}1516public function setContent($content) {17$this->content = $content;18return $this;19}2021public function getContent() {22return $this->content;23}2425/**26* Get the markup language a README should be interpreted as.27*28* @param string Local README path, like "README.txt".29* @return string Best markup interpreter (like "remarkup") for this file.30*/31private function getReadmeLanguage($path) {32$path = phutil_utf8_strtolower($path);33if ($path == 'readme') {34return 'remarkup';35}3637$ext = last(explode('.', $path));38switch ($ext) {39case 'remarkup':40case 'md':41return 'remarkup';42case 'rainbow':43return 'rainbow';44case 'txt':45default:46return 'text';47}48}495051public function render() {52$readme_path = $this->getPath();53$readme_name = basename($readme_path);54$interpreter = $this->getReadmeLanguage($readme_name);55require_celerity_resource('diffusion-readme-css');5657$content = $this->getContent();5859$class = null;60switch ($interpreter) {61case 'remarkup':62// TODO: This is sketchy, but make sure we hit the markup cache.63$markup_object = id(new PhabricatorMarkupOneOff())64->setEngineRuleset('diffusion-readme')65->setContent($content);66$markup_field = 'default';6768$content = id(new PhabricatorMarkupEngine())69->setViewer($this->getUser())70->addObject($markup_object, $markup_field)71->process()72->getOutput($markup_object, $markup_field);7374$engine = $markup_object->newMarkupEngine($markup_field);7576$readme_content = $content;77$class = 'ml';78break;79case 'rainbow':80$content = id(new PhutilRainbowSyntaxHighlighter())81->getHighlightFuture($content)82->resolve();83$readme_content = phutil_escape_html_newlines($content);8485require_celerity_resource('syntax-highlighting-css');86$class = 'remarkup-code ml';87break;88default:89case 'text':90$readme_content = phutil_escape_html_newlines($content);91$class = 'ml';92break;93}9495$readme_content = phutil_tag(96'div',97array(98'class' => $class,99),100$readme_content);101102$header = id(new PHUIHeaderView())103->setHeader($readme_name)104->addClass('diffusion-panel-header-view');105106return id(new PHUIObjectBoxView())107->setHeader($header)108->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)109->addClass('diffusion-mobile-view')110->appendChild($readme_content)111->addClass('diffusion-readme-view');112}113114}115116117