Changeset View
Changeset View
Standalone View
Standalone View
src/view/layout/PhabricatorSourceCodeView.php
<?php | <?php | ||||
final class PhabricatorSourceCodeView extends AphrontView { | final class PhabricatorSourceCodeView extends AphrontView { | ||||
private $lines; | private $lines; | ||||
private $uri; | private $uri; | ||||
private $highlights = array(); | private $highlights = array(); | ||||
private $canClickHighlight = true; | private $canClickHighlight = true; | ||||
private $truncatedFirstBytes = false; | private $truncatedFirstBytes = false; | ||||
private $truncatedFirstLines = false; | private $truncatedFirstLines = false; | ||||
private $symbolMetadata; | private $symbolMetadata; | ||||
private $blameMap; | |||||
public function setLines(array $lines) { | public function setLines(array $lines) { | ||||
$this->lines = $lines; | $this->lines = $lines; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setURI(PhutilURI $uri) { | public function setURI(PhutilURI $uri) { | ||||
$this->uri = $uri; | $this->uri = $uri; | ||||
Show All 24 Lines | public function setSymbolMetadata(array $symbol_metadata) { | ||||
$this->symbolMetadata = $symbol_metadata; | $this->symbolMetadata = $symbol_metadata; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getSymbolMetadata() { | public function getSymbolMetadata() { | ||||
return $this->symbolMetadata; | return $this->symbolMetadata; | ||||
} | } | ||||
public function setBlameMap(array $map) { | |||||
$this->blameMap = $map; | |||||
return $this; | |||||
} | |||||
public function getBlameMap() { | |||||
return $this->blameMap; | |||||
} | |||||
public function render() { | public function render() { | ||||
$blame_map = $this->getBlameMap(); | |||||
$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()); | Javelin::initBehavior('phabricator-oncopy', array()); | ||||
if ($this->canClickHighlight) { | if ($this->canClickHighlight) { | ||||
Javelin::initBehavior('phabricator-line-linker'); | Javelin::initBehavior('phabricator-line-linker'); | ||||
} | } | ||||
Show All 19 Lines | if ($this->truncatedFirstLines) { | ||||
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. | // NOTE: See phabricator-oncopy behavior. | ||||
$content_line = hsprintf("\xE2\x80\x8B%s", $line); | $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'; | ||||
} | } | ||||
Show All 12 Lines | foreach ($lines as $line) { | ||||
$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) { | |||||
$lines = idx($blame_map, $line_number); | |||||
if ($lines) { | |||||
$skip_blame = 'skip;'.$lines; | |||||
$info_blame = 'info;'.$lines; | |||||
} else { | |||||
$skip_blame = null; | |||||
$info_blame = null; | |||||
} | |||||
$blame_cells = array( | |||||
phutil_tag( | |||||
'th', | |||||
array( | |||||
'class' => 'phabricator-source-blame-skip', | |||||
'data-blame' => $skip_blame, | |||||
)), | |||||
phutil_tag( | |||||
'th', | |||||
array( | |||||
'class' => 'phabricator-source-blame-info', | |||||
'data-blame' => $info_blame, | |||||
)), | |||||
); | |||||
} else { | |||||
$blame_cells = null; | |||||
} | |||||
$rows[] = phutil_tag( | $rows[] = phutil_tag( | ||||
'tr', | 'tr', | ||||
$row_attributes, | $row_attributes, | ||||
array( | array( | ||||
$blame_cells, | |||||
phutil_tag( | phutil_tag( | ||||
'th', | 'th', | ||||
array( | array( | ||||
'class' => 'phabricator-source-line', | 'class' => 'phabricator-source-line', | ||||
), | ), | ||||
$tag_number), | $tag_number), | ||||
phutil_tag( | phutil_tag( | ||||
'td', | 'td', | ||||
Show All 38 Lines |