diff --git a/SyntaxHighlighter.php b/SyntaxHighlighter.php index 06f47cd..e026524 100644 --- a/SyntaxHighlighter.php +++ b/SyntaxHighlighter.php @@ -20,78 +20,88 @@ class SyntaxHighlighter extends Widget { public $theme = 'default'; - public $brushes = []; - public $brushAliases = [ - 'js' => 'JScript', - ]; - - // config: - public $bloggerMode = false; - public $strings = []; - public $stripBrs = false; - public static $tagName = 'pre'; - - // defaults: - public $showToolbar = false; - public $tabSize = 4; - public $blockClassName = ''; - public $autoLinks = true; - public $collapse = false; - public $showGutter = true; - public $smartTabs = true; - - - /** - * Publishes the assets - */ - public function publishAssets() { - SyntaxHighlighterAsset::register($this->getView()); - } - - /** - * Run the widget - */ - public function run() { - - SyntaxHighlighterAsset::$extraCss[] = 'styles/shCore' . ucfirst($this->theme) . '.css'; - - foreach ($this->brushes as $brushName) { - $brushFile = (!empty($this->brushAliases[$brushName]) ? $this->brushAliases[$brushName] : ucfirst($brushName)); - SyntaxHighlighterAsset::$extraJs[] = 'scripts/shBrush' . $brushFile . '.js'; - } - - $this->publishAssets(); - - $initJs = ''; - $initJs .= "SyntaxHighlighter.config.bloggerMode = " . ($this->bloggerMode ? 'true' : 'false') . ";\n"; - if (!empty($this->strings)) { - $initJs .= "SyntaxHighlighter.config.strings = " . Json::encode($this->strings) . ";\n"; - } - $initJs .= "SyntaxHighlighter.config.stripBrs = " . ($this->stripBrs ? 'true' : 'false') . ";\n"; - $initJs .= "SyntaxHighlighter.config.tagName = '" . static::$tagName . "';\n"; - $initJs .= "SyntaxHighlighter.defaults = { + public $brushes = []; + public $brushAliases = [ + 'js' => 'JScript', + ]; + + // config: + public $bloggerMode = false; + public $strings = []; + public $stripBrs = false; + public static $tagName = 'pre'; + + // defaults: + public $showToolbar = false; + public $tabSize = 4; + public $blockClassName = ''; + public $autoLinks = true; + public $collapse = false; + public $showGutter = true; + public $smartTabs = true; + + + /** + * Publishes the assets + */ + public function publishAssets() + { + SyntaxHighlighterAsset::register($this->getView()); + } + + /** + * Run the widget + */ + public function run() + { + + SyntaxHighlighterAsset::$extraCss[] = 'styles/shCore'.ucfirst($this->theme).'.css'; + + foreach ($this->brushes as $brushName) { + $brushFile = (!empty($this->brushAliases[$brushName]) + ? $this->brushAliases[$brushName] + : ucfirst( + $brushName + )); + SyntaxHighlighterAsset::$extraJs[] = 'scripts/shBrush'.$brushFile.'.js'; + } + + $this->publishAssets(); + + $initJs = ''; + $initJs .= "SyntaxHighlighter.config.bloggerMode = ".($this->bloggerMode ? 'true' : 'false').";\n"; + if (!empty($this->strings)) { + $initJs .= "SyntaxHighlighter.config.strings = ".Json::encode($this->strings).";\n"; + } + $initJs .= "SyntaxHighlighter.config.stripBrs = ".($this->stripBrs ? 'true' : 'false').";\n"; + $initJs .= "SyntaxHighlighter.config.tagName = '".static::$tagName."';\n"; + $initJs .= "SyntaxHighlighter.defaults = { 'tab-size': {$this->tabSize}, 'class-name': '{$this->blockClassName}', - 'auto-links': " . ($this->autoLinks ? 'true' : 'false') . ", - 'collapse': " . ($this->collapse ? 'true' : 'false') . ", - 'gutter': " . ($this->showGutter ? 'true' : 'false') . ", - 'smart-tabs': " . ($this->smartTabs ? 'true' : 'false') . ", - 'toolbar': " . ($this->showToolbar ? 'true' : 'false') . " + 'auto-links': ".($this->autoLinks ? 'true' : 'false').", + 'collapse': ".($this->collapse ? 'true' : 'false').", + 'gutter': ".($this->showGutter ? 'true' : 'false').", + 'smart-tabs': ".($this->smartTabs ? 'true' : 'false').", + 'toolbar': ".($this->showToolbar ? 'true' : 'false')." };\n"; - $initJs .= 'SyntaxHighlighter.all();' . "\n"; - $this->getView()->registerJs($initJs, View::POS_READY, 'InitSyntaxHighlighter'); + $initJs .= 'SyntaxHighlighter.all();'."\n"; + $this->getView()->registerJs($initJs, View::POS_READY, 'InitSyntaxHighlighter'); - parent::run(); - } + parent::run(); + } - public static function getBlock($source, $type, $firstLine = 1) { - $res = Html::tag(static::$tagName, htmlentities($source), [ - 'class' => 'brush: ' . $type . '; first-line: ' . ($firstLine) . ';', - ] - ); + public static function getBlock($source, $type, $firstLine = 1) + { + $res = Html::tag( + static::$tagName, + htmlentities($source), + [ + 'class' => 'brush: '.$type.'; first-line: '.($firstLine).';', + ] + ); - return $res; - } + return $res; + } } diff --git a/SyntaxHighlighterAsset.php b/SyntaxHighlighterAsset.php index d682661..1868d2d 100644 --- a/SyntaxHighlighterAsset.php +++ b/SyntaxHighlighterAsset.php @@ -7,8 +7,6 @@ class SyntaxHighlighterAsset extends AssetBundle { -// public $basePath = '@webroot'; -// public $baseUrl = '@web'; public $sourcePath = '@yii2SyntaxHighlighter/assets'; public static $extraCss = []; @@ -24,7 +22,8 @@ class SyntaxHighlighterAsset extends AssetBundle 'yii\web\YiiAsset', ]; - public function init(){ + public function init() + { Yii::setAlias('@yii2SyntaxHighlighter', __DIR__);