forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasteEmbedView.php
70 lines (56 loc) · 1.49 KB
/
PasteEmbedView.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
final class PasteEmbedView extends AphrontView {
private $paste;
private $handle;
private $highlights = array();
private $lines = 30;
public function setPaste(PhabricatorPaste $paste) {
$this->paste = $paste;
return $this;
}
public function setHandle(PhabricatorObjectHandle $handle) {
$this->handle = $handle;
return $this;
}
public function setHighlights(array $highlights) {
$this->highlights = $highlights;
return $this;
}
public function setLines($lines) {
$this->lines = $lines;
}
public function render() {
if (!$this->paste) {
throw new Exception('Call setPaste() before render()!');
}
$lines = phutil_split_lines($this->paste->getContent());
require_celerity_resource('paste-css');
$link = phutil_tag(
'a',
array(
'href' => '/P'.$this->paste->getID()
),
$this->handle->getFullName());
$head = phutil_tag(
'div',
array(
'class' => 'paste-embed-head'
),
$link);
$body_attributes = array('class' => 'paste-embed-body');
if ($this->lines != null) {
$body_attributes['style'] = 'max-height: '.$this->lines * (1.15).'em;';
}
$body = phutil_tag(
'div',
$body_attributes,
id(new PhabricatorSourceCodeView())
->setLines($lines)
->setHighlights($this->highlights)
->disableHighlightOnClick());
return phutil_tag(
'div',
array('class' => 'paste-embed'),
array($head, $body));
}
}