Changeset View
Changeset View
Standalone View
Standalone View
src/view/layout/PhabricatorSourceCodeView.php
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | final class PhabricatorSourceCodeView extends AphrontView { | ||||
public function render() { | public function render() { | ||||
$blame_map = $this->getBlameMap(); | $blame_map = $this->getBlameMap(); | ||||
$has_blame = ($blame_map !== null); | $has_blame = ($blame_map !== null); | ||||
require_celerity_resource('phabricator-source-code-view-css'); | require_celerity_resource('phabricator-source-code-view-css'); | ||||
require_celerity_resource('syntax-highlighting-css'); | require_celerity_resource('syntax-highlighting-css'); | ||||
Javelin::initBehavior('phabricator-oncopy', array()); | |||||
if ($this->canClickHighlight) { | if ($this->canClickHighlight) { | ||||
Javelin::initBehavior('phabricator-line-linker'); | Javelin::initBehavior('phabricator-line-linker'); | ||||
} | } | ||||
$line_number = 1; | $line_number = 1; | ||||
$rows = array(); | $rows = array(); | ||||
$lines = $this->lines; | $lines = $this->lines; | ||||
if ($this->truncatedFirstLines) { | if ($this->truncatedFirstLines) { | ||||
$lines[] = phutil_tag( | $lines[] = phutil_tag( | ||||
'span', | 'span', | ||||
array( | array( | ||||
'class' => 'c', | 'class' => 'c', | ||||
), | ), | ||||
pht('...')); | pht('...')); | ||||
} else if ($this->truncatedFirstBytes) { | } else if ($this->truncatedFirstBytes) { | ||||
$last_key = last_key($lines); | $last_key = last_key($lines); | ||||
$lines[$last_key] = hsprintf( | $lines[$last_key] = hsprintf( | ||||
'%s%s', | '%s%s', | ||||
$lines[$last_key], | $lines[$last_key], | ||||
phutil_tag( | phutil_tag( | ||||
'span', | 'span', | ||||
array( | array( | ||||
'class' => 'c', | 'class' => 'c', | ||||
), | ), | ||||
pht('...'))); | pht('...'))); | ||||
} | } | ||||
$base_uri = (string)$this->uri; | $base_uri = (string)$this->uri; | ||||
foreach ($lines as $line) { | foreach ($lines as $line) { | ||||
// NOTE: See phabricator-oncopy behavior. | |||||
$content_line = hsprintf("\xE2\x80\x8B%s", $line); | |||||
$row_attributes = array(); | $row_attributes = array(); | ||||
if (isset($this->highlights[$line_number])) { | if (isset($this->highlights[$line_number])) { | ||||
$row_attributes['class'] = 'phabricator-source-highlight'; | $row_attributes['class'] = 'phabricator-source-highlight'; | ||||
} | } | ||||
if ($this->canClickHighlight) { | if ($this->canClickHighlight) { | ||||
if ($base_uri) { | if ($base_uri) { | ||||
$line_href = $base_uri.'$'.$line_number; | $line_href = $base_uri.'$'.$line_number; | ||||
} else { | } else { | ||||
$line_href = null; | $line_href = null; | ||||
} | } | ||||
$tag_number = phutil_tag( | $tag_number = phutil_tag( | ||||
'a', | 'a', | ||||
array( | array( | ||||
'href' => $line_href, | 'href' => $line_href, | ||||
), | 'data-n' => $line_number, | ||||
$line_number); | )); | ||||
} else { | } else { | ||||
$tag_number = phutil_tag( | $tag_number = phutil_tag( | ||||
'span', | 'span', | ||||
array(), | array(), | ||||
$line_number); | $line_number); | ||||
} | } | ||||
if ($has_blame) { | if ($has_blame) { | ||||
Show All 37 Lines | foreach ($lines as $line) { | ||||
'class' => 'phabricator-source-line', | 'class' => 'phabricator-source-line', | ||||
), | ), | ||||
$tag_number), | $tag_number), | ||||
phutil_tag( | phutil_tag( | ||||
'td', | 'td', | ||||
array( | array( | ||||
'class' => 'phabricator-source-code', | 'class' => 'phabricator-source-code', | ||||
), | ), | ||||
$content_line), | $line), | ||||
)); | )); | ||||
$line_number++; | $line_number++; | ||||
} | } | ||||
$classes = array(); | $classes = array(); | ||||
$classes[] = 'phabricator-source-code-view'; | $classes[] = 'phabricator-source-code-view'; | ||||
$classes[] = 'remarkup-code'; | $classes[] = 'remarkup-code'; | ||||
Show All 26 Lines |