Skip to content

Commit 9b63e78

Browse files
ibelarDarkSide666
authored andcommitted
Feature/Code Highlight (#849)
* Feature/Code Highlight Display code in tutorial using Highlight.js * Apply fixes from StyleCI * add lang selection * fix
1 parent 6dac4f9 commit 9b63e78

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

demos/index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
$t->addParagraph('In this version of Agile Toolkit we introduce "User Actions"!');
1818

1919
$app->add(['Button', 'Learn about User Actions', 'huge basic primary fluid', 'iconRight' => 'right arrow'])
20-
->link(['actions', 'layout' => 'Centered', 'begin' => true]);
20+
->link(['tutorial_actions', 'layout' => 'Centered', 'begin' => true]);
2121

2222
exit;
2323
}

demos/init.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class Demo extends \atk4\ui\Columns
1313
{
1414
public $left;
1515
public $right;
16+
public static $isInitialized = false;
17+
public $highlightDefaultStyle = 'dark';
1618

1719
public function init()
1820
{
@@ -23,13 +25,24 @@ public function init()
2325
$this->right = $this->addColumn();
2426
}
2527

26-
public function setCode($code)
28+
public function setCode($code, $lang = 'php')
2729
{
28-
$this->left->add(['element'=>'pre'])->set($code);
30+
$this->highLightCode();
31+
$this->left->add(['element'=>'pre'])->add(['element' => 'code'])->addClass($lang)->set($code);
2932
$app = $this->right;
3033
$app->db = $this->app->db;
3134
eval($code);
3235
}
36+
37+
public function highLightCode()
38+
{
39+
if (!self::$isInitialized) {
40+
$this->app->requireCSS('//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.16.2/build/styles/'.$this->highlightDefaultStyle.'.min.css');
41+
$this->app->requireJS('//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.16.2/build/highlight.min.js');
42+
$this->js(true, (new \atk4\ui\jsChain('hljs'))->initHighlighting());
43+
self::$isInitialized = true;
44+
}
45+
}
3346
}
3447

3548
$app = new \atk4\ui\App([

demos/tutorial_actions.php

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'init.php';
44
require 'database.php';
55

6+
/** @var \atk4\ui\View $wizard */
67
$wizard = $app->add('Wizard');
78
$app->stickyGet($wizard->name);
89

demos/view.php

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
}
2828

2929
$app->add(['Header', 'View load HTML from string or file']);
30+
/** @var \atk4\ui\View $plane */
3031
$plane = $app->add(['View', 'template' => new \atk4\ui\Template('<div id="{$_id}" class="ui statistic">
3132
<div class="value">
3233
<i class="plane icon"></i> {$num}

0 commit comments

Comments
 (0)