Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Commit

Permalink
Reformat to PSR-2 Coding Style
Browse files Browse the repository at this point in the history
  • Loading branch information
giovdk21 committed Nov 2, 2014
1 parent 99193f2 commit 9407b70
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 69 deletions.
142 changes: 76 additions & 66 deletions SyntaxHighlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
5 changes: 2 additions & 3 deletions SyntaxHighlighterAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

class SyntaxHighlighterAsset extends AssetBundle
{
// public $basePath = '@webroot';
// public $baseUrl = '@web';
public $sourcePath = '@yii2SyntaxHighlighter/assets';

public static $extraCss = [];
Expand All @@ -24,7 +22,8 @@ class SyntaxHighlighterAsset extends AssetBundle
'yii\web\YiiAsset',
];

public function init(){
public function init()
{

Yii::setAlias('@yii2SyntaxHighlighter', __DIR__);

Expand Down

0 comments on commit 9407b70

Please sign in to comment.