Remove product literal strings in "pht()", part 18
[phabricator.git] / src / applications / diffusion / view / DiffusionReadmeView.php
blob2f65f5730f665b574190f4587a8898785d47eb8c
1 <?php
3 final class DiffusionReadmeView extends DiffusionView {
5 private $path;
6 private $content;
8 public function setPath($path) {
9 $this->path = $path;
10 return $this;
13 public function getPath() {
14 return $this->path;
17 public function setContent($content) {
18 $this->content = $content;
19 return $this;
22 public function getContent() {
23 return $this->content;
26 /**
27 * Get the markup language a README should be interpreted as.
29 * @param string Local README path, like "README.txt".
30 * @return string Best markup interpreter (like "remarkup") for this file.
32 private function getReadmeLanguage($path) {
33 $path = phutil_utf8_strtolower($path);
34 if ($path == 'readme') {
35 return 'remarkup';
38 $ext = last(explode('.', $path));
39 switch ($ext) {
40 case 'remarkup':
41 case 'md':
42 return 'remarkup';
43 case 'rainbow':
44 return 'rainbow';
45 case 'txt':
46 default:
47 return 'text';
52 public function render() {
53 $readme_path = $this->getPath();
54 $readme_name = basename($readme_path);
55 $interpreter = $this->getReadmeLanguage($readme_name);
56 require_celerity_resource('diffusion-readme-css');
58 $content = $this->getContent();
60 $class = null;
61 switch ($interpreter) {
62 case 'remarkup':
63 // TODO: This is sketchy, but make sure we hit the markup cache.
64 $markup_object = id(new PhabricatorMarkupOneOff())
65 ->setEngineRuleset('diffusion-readme')
66 ->setContent($content);
67 $markup_field = 'default';
69 $content = id(new PhabricatorMarkupEngine())
70 ->setViewer($this->getUser())
71 ->addObject($markup_object, $markup_field)
72 ->process()
73 ->getOutput($markup_object, $markup_field);
75 $engine = $markup_object->newMarkupEngine($markup_field);
77 $readme_content = $content;
78 $class = 'ml';
79 break;
80 case 'rainbow':
81 $content = id(new PhutilRainbowSyntaxHighlighter())
82 ->getHighlightFuture($content)
83 ->resolve();
84 $readme_content = phutil_escape_html_newlines($content);
86 require_celerity_resource('syntax-highlighting-css');
87 $class = 'remarkup-code ml';
88 break;
89 default:
90 case 'text':
91 $readme_content = phutil_escape_html_newlines($content);
92 $class = 'ml';
93 break;
96 $readme_content = phutil_tag(
97 'div',
98 array(
99 'class' => $class,
101 $readme_content);
103 $header = id(new PHUIHeaderView())
104 ->setHeader($readme_name)
105 ->addClass('diffusion-panel-header-view');
107 return id(new PHUIObjectBoxView())
108 ->setHeader($header)
109 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
110 ->addClass('diffusion-mobile-view')
111 ->appendChild($readme_content)
112 ->addClass('diffusion-readme-view');