forked from laravel-admin-extensions/python-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditor.php
More file actions
84 lines (71 loc) · 1.71 KB
/
Editor.php
File metadata and controls
84 lines (71 loc) · 1.71 KB
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
<?php
namespace Ladmin\PythonEditor;
use Ladmin\Form\Field;
use Ladmin\CodeMirror\CodeMirror;
class Editor extends Field
{
/**
* {@inheritdoc}
*/
protected $view = 'laravel-admin-code-mirror::editor';
/**
* {@inheritdoc}
*/
protected static $css = [
CodeMirror::ASSETS_PATH . 'lib/codemirror.css',
];
/**
* {@inheritdoc}
*/
protected static $js = [
CodeMirror::ASSETS_PATH . 'lib/codemirror.js',
CodeMirror::ASSETS_PATH . 'addon/edit/matchbrackets.js',
CodeMirror::ASSETS_PATH . 'mode/python/python.js',
];
protected $version = 3;
/**
* Set editor height.
*
* @param int $height
* @return $this
*/
public function height($height = 10)
{
return $this->addVariables(compact('height'));
}
/**
* Set python version.
*
* @param int $version
* @return $this
*/
public function version($version = 3)
{
$this->version = $version;
return $this;
}
/**
* {@inheritdoc}
*/
public function render()
{
$options = array_merge(
[
'mode' => [
'name' => 'python',
'version' => $this->version,
'singleLineStringErrors' => false,
],
'lineNumbers' => true,
'matchBrackets' => true,
'indentUnit' => 4,
],
PythonEditor::config('config', [])
);
$options = json_encode($options);
$this->script = <<<EOT
CodeMirror.fromTextArea(document.getElementById("{$this->id}"), $options);
EOT;
return parent::render();
}
}