-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEPrism.php
86 lines (74 loc) · 2.25 KB
/
EPrism.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* EPrism class file.
*
* @author Andrius Marcinkevicius <andrew.web@ifdattic.com>
* @copyright Copyright © 2013 Andrius Marcinkevicius
* @license Licensed under MIT license. http://ifdattic.mit-license.org
* @version 1.0.0
*/
/**
* EPrism adds Prism (http://prismjs.com). A lightweight, robust, elegant syntax highlighting.
*
* @author Andrius Marcinkevicius <andrew.web@ifdattic.com>
*/
class EPrism extends CWidget
{
/**
* @var array options for plugin script file.
*/
private $scriptOptions = [];
/**
* @var boolean flag to disable automatic highlighting.
*/
public $manualHighlight = false;
/**
* @var int where the script will be inserted in the page.
*/
public $scriptPosition;
/**
* @var mixed the CSS file for extension.
* If false - CSS file won't be registered.
* If null - the default CSS file will be registered.
* If string - defined file will be registered.
*/
public $cssFile;
/**
* @var mixed the JS file for extension.
* If false - JS file won't be registered.
* If null - the default JS file will be registered.
* If string - defined file will be registered.
*/
public $scriptFile;
/**
* Initialize widget.
*/
public function init()
{
if (is_null($this->scriptPosition)) {
$this->scriptPosition = Yii::app()->clientScript->defaultScriptFilePosition;
}
if ($this->manualHighlight) {
$this->scriptOptions['data-manual'] = true;
}
return parent::init();
}
/**
* Add Prism plugin.
*/
public function run()
{
$assets = Yii::app()->getAssetManager()->publish(dirname(__FILE__) . '/assets');
$cs = Yii::app()->getClientScript();
if ($this->cssFile !== false) {
$cs->registerCssFile($this->cssFile ? $this->cssFile : $assets . '/prism.css');
}
if ($this->scriptFile !== false) {
$cs->registerScriptFile(
$this->scriptFile ? $this->scriptFile : $assets . '/prism.js',
$this->scriptPosition,
$this->scriptOptions
);
}
}
}