-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6ceb9d8
Showing
7 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
phpunit.phar | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
*.project | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Jens Segers | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Python editor extension for laravel-admin based on code-mirror | ||
====== | ||
|
||
## Installation | ||
|
||
```bash | ||
composer require laravel-admin-ext/python-editor | ||
|
||
php artisan vendor:publish --tag=laravel-admin-code-mirror | ||
``` | ||
|
||
## 配置 | ||
|
||
在`config/admin.php`文件的`extensions`,加上属于这个扩展的一些配置 | ||
```php | ||
|
||
'extensions' => [ | ||
|
||
'python-editor' => [ | ||
|
||
// 如果要关掉这个扩展,设置为false | ||
'enable' => true, | ||
|
||
// 编辑器的配置 | ||
'config' => [ | ||
|
||
] | ||
] | ||
] | ||
|
||
``` | ||
|
||
更多配置可以到[CodeMirror文档](https://codemirror.net/)找到 | ||
|
||
## 使用 | ||
|
||
在form表单中使用它: | ||
```php | ||
$form->python('code'); | ||
``` | ||
|
||
设置高度 | ||
```php | ||
$form->python('code')->height(500); | ||
|
||
// 设置版本,默认为3 | ||
$form->python('code')->version(2); | ||
``` | ||
|
||
## 支持 | ||
|
||
如果觉得这个项目帮你节约了时间,不妨支持一下;) | ||
|
||
![-1](https://cloud.githubusercontent.com/assets/1479100/23287423/45c68202-fa78-11e6-8125-3e365101a313.jpg) | ||
|
||
License | ||
------------ | ||
Licensed under [The MIT License (MIT)](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "laravel-admin-ext/python-editor", | ||
"description": "Python editor extension for laravel-admin", | ||
"type": "library", | ||
"keywords": ["laravel-admin", "extension", "code mirror", "python", "editor"], | ||
"homepage": "https://github.com/laravel-admin-ext/python-editor", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "song", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.0.0", | ||
"jxlwqq/code-mirror": "*" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "~6.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Encore\\PythonEditor\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Encore\\PythonEditor\\PythonEditorServiceProvider" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace Encore\PythonEditor; | ||
|
||
use Encore\Admin\Form\Field; | ||
|
||
class Editor extends Field | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $view = 'laravel-admin-code-mirror::editor'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $css = [ | ||
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/lib/codemirror.css', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $js = [ | ||
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/lib/codemirror.js', | ||
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/addon/edit/matchbrackets.js', | ||
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Encore\PythonEditor; | ||
|
||
use Encore\Admin\Extension; | ||
|
||
class PythonEditor extends Extension | ||
{ | ||
public $name = 'python-editor'; | ||
|
||
public $views = __DIR__.'/../resources/views'; | ||
|
||
public $assets = __DIR__.'/../resources/assets'; | ||
|
||
public $menu = [ | ||
'title' => 'Pythoneditor', | ||
'path' => 'python-editor', | ||
'icon' => 'fa-gears', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Encore\PythonEditor; | ||
|
||
use Encore\Admin\Admin; | ||
use Encore\Admin\Form; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class PythonEditorServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function boot(PythonEditor $extension) | ||
{ | ||
if (! PythonEditor::boot()) { | ||
return ; | ||
} | ||
|
||
Admin::booting(function () { | ||
Form::extend('python', Editor::class); | ||
}); | ||
} | ||
} |