Skip to content

Commit e6ea6ec

Browse files
committed
first commit
0 parents  commit e6ea6ec

File tree

14 files changed

+290
-0
lines changed

14 files changed

+290
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
phpunit.phar
3+
/vendor
4+
composer.phar
5+
composer.lock
6+
*.project
7+
.idea/

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Jens Segers
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Several c-lick language editor extensions for laravel-admin based on code-mirror
2+
======
3+
4+
## Installation
5+
6+
```bash
7+
composer require laravel-admin-ext/clike-editor
8+
9+
php artisan vendor:publish --tag=laravel-admin-code-mirror
10+
```
11+
12+
## 配置
13+
14+
`config/admin.php`文件的`extensions`,加上属于这个扩展的一些配置
15+
```php
16+
17+
'extensions' => [
18+
19+
'clike-editor' => [
20+
21+
// 如果要关掉这个扩展,设置为false
22+
'enable' => true,
23+
24+
// 编辑器的配置
25+
'config' => [
26+
27+
]
28+
]
29+
]
30+
31+
```
32+
33+
更多配置可以到[CodeMirror文档](https://codemirror.net/)找到
34+
35+
## 使用
36+
37+
在form表单中使用它:
38+
```php
39+
$form->clang('code');
40+
41+
$form->cpp('code');
42+
43+
$form->java('code');
44+
45+
$form->objectivec('code');
46+
47+
$form->scala('code');
48+
49+
$form->kotlin('code');
50+
51+
$form->ceylon('code');
52+
```
53+
54+
设置高度
55+
```php
56+
$form->clang('code')->height(500);
57+
```
58+
59+
## 支持
60+
61+
如果觉得这个项目帮你节约了时间,不妨支持一下;)
62+
63+
![-1](https://cloud.githubusercontent.com/assets/1479100/23287423/45c68202-fa78-11e6-8125-3e365101a313.jpg)
64+
65+
License
66+
------------
67+
Licensed under [The MIT License (MIT)](LICENSE).

composer.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "laravel-admin-ext/click-editor",
3+
"description": "Several c-lick language editor extensions for laravel-admin based on code-mirror",
4+
"type": "library",
5+
"keywords": ["laravel-admin", "extension", "code-mirror", "editor", "clang", "cpp", "java", "objectivec", "scala", "kotlin", "Ceylon"],
6+
"homepage": "https://github.com/laravel-admin-ext/click-editor",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "song",
11+
"email": "[email protected]"
12+
}
13+
],
14+
"require": {
15+
"php": ">=7.0.0",
16+
"jxlwqq/code-mirror": "*"
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "~6.0"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Encore\\ClikeEditor\\": "src/"
24+
}
25+
},
26+
"extra": {
27+
"laravel": {
28+
"providers": [
29+
"Encore\\ClikeEditor\\ClikeEditorServiceProvider"
30+
]
31+
}
32+
}
33+
}

src/Ceylon.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Encore\ClikeEditor;
4+
5+
class Ceylon extends Editor
6+
{
7+
protected $mode = 'text/x-ceylon';
8+
}

src/Clang.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Encore\ClikeEditor;
4+
5+
class Clang extends Editor
6+
{
7+
protected $mode = 'text/x-csrc';
8+
}

src/ClikeEditor.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Encore\ClikeEditor;
4+
5+
use Encore\Admin\Extension;
6+
7+
class ClikeEditor extends Extension
8+
{
9+
public $name = 'click-editor';
10+
}

src/ClikeEditorServiceProvider.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Encore\ClikeEditor;
4+
5+
use Encore\Admin\Admin;
6+
use Encore\Admin\Form;
7+
use Illuminate\Support\ServiceProvider;
8+
9+
class ClikeEditorServiceProvider extends ServiceProvider
10+
{
11+
/**
12+
* {@inheritdoc}
13+
*/
14+
public function boot()
15+
{
16+
if (!ClikeEditor::boot()) {
17+
return;
18+
}
19+
20+
Admin::booting(function () {
21+
Form::extend('clang', Clang::class);
22+
Form::extend('cpp', Cpp::class);
23+
Form::extend('java', Java::class);
24+
Form::extend('objectivec', Objectivec::class);
25+
Form::extend('scala', Scala::class);
26+
Form::extend('clang', Kotlin::class);
27+
Form::extend('ceylon', Ceylon::class);
28+
});
29+
}
30+
}

src/Cpp.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Encore\ClikeEditor;
4+
5+
class Cpp extends Editor
6+
{
7+
protected $mode = 'text/x-c++src';
8+
}

src/Editor.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace Encore\ClikeEditor;
4+
5+
use Encore\Admin\Form\Field;
6+
7+
abstract class Editor extends Field
8+
{
9+
protected $mode = '';
10+
11+
/**
12+
* {@inheritdoc}
13+
*/
14+
protected $view = 'laravel-admin-code-mirror::editor';
15+
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
protected static $css = [
20+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/lib/codemirror.css',
21+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/addon/hint/show-hint.css',
22+
];
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
protected static $js = [
28+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/lib/codemirror.js',
29+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/addon/edit/matchbrackets.js',
30+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/addon/hint/show-hint.js',
31+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/mode/click/click.js',
32+
];
33+
34+
/**
35+
* Set editor height.
36+
*
37+
* @param int $height
38+
* @return $this
39+
*/
40+
public function height($height = 10)
41+
{
42+
return $this->addVariables(compact('height'));
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
public function render()
49+
{
50+
$options = array_merge(
51+
[
52+
'mode' => $this->mode,
53+
'lineNumbers' => true,
54+
'matchBrackets' => true,
55+
],
56+
ClikeEditor::config('config', [])
57+
);
58+
59+
$options = json_encode($options);
60+
61+
$this->script = <<<EOT
62+
CodeMirror.fromTextArea(document.getElementById("{$this->id}"), $options);
63+
EOT;
64+
65+
return parent::render();
66+
}
67+
}

0 commit comments

Comments
 (0)