Skip to content

Commit

Permalink
Merge pull request #5 from alaminfirdows/2.x
Browse files Browse the repository at this point in the history
Release Version 2.x
  • Loading branch information
alaminfirdows authored Feb 26, 2023
2 parents f791e68 + 93ef9b3 commit a2a2643
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 54 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,22 @@ $post = Post::find(1);
echo $post->body;
```

## Versioning

| Laravel | Supported |
| ------- | --------- |
| 10.x | ✅ 2.x |
| 9.x | ✅ 1.1 |
| 8.x | ✅ 1.0 |

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Credits

- [Al-Amin Firdows](https://github.com/alaminfirdows)
- [All Contributors](../../contributors)
- [Al-Amin Firdows](https://github.com/alaminfirdows)
- [All Contributors](../../contributors)

## License

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
}
],
"require": {
"php": "^7.4|^8",
"codex-team/editor.js": "dev-master",
"illuminate/support": "^6|^7|^8|^9"
"php": "^7.2|^8.1",
"codex-team/editor.js": "v2.0.7",
"illuminate/support": "^8.0|^9.0|^10.0"
},
"require-dev": {
"orchestra/testbench": "^6.0",
Expand Down
96 changes: 54 additions & 42 deletions config/laravel_editorjs.php
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
<?php

return [
'config' => [
'config' => [
'tools' => [
'paragraph' => [
'text' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
'text' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
],
],
'header' => [
'text' => [
'type' => 'string',
'header' => [
'text' => [
'type' => 'string',
'allowedTags' => 'a[href],mark[class]',
],
'level' => [1, 2, 3, 4, 5, 6],
],
'list' => [
'style' => [
'list' => [
'type' => [
0 => 'ordered',
1 => 'unordered',
],
'items' => [
'type' => 'array',
'data' => [
'-' => [
'type' => 'string',
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
],
],
],
],
'linkTool' => [
'linkTool' => [
'link' => 'string',
'meta' => [
'type' => 'array',
'data' => [
'title' => [
'title' => [
'type' => 'string',
],
'description' => [
'type' => 'string',
],
'url' => [
'type' => 'string',
'url' => [
'type' => 'string',
'required' => false,
],
'domain' => [
'type' => 'string',
'domain' => [
'type' => 'string',
'required' => false,
],
'image' => [
'type' => 'array',
'image' => [
'type' => 'array',
'required' => false,
'data' => [
'data' => [
'url' => [
'type' => 'string',
],
Expand All @@ -62,73 +62,85 @@
],
],
],
'image' => [
'file' => [
'image' => [
'file' => [
'type' => 'array',
'data' => [
'width' => [
'type' => 'integer',
'width' => [
'type' => 'integer',
'required' => false,
],
'height' => [
'type' => 'integer',
'type' => 'integer',
'required' => false,
],
'url' => 'string',
'url' => 'string',
],
],
'caption' => [
'type' => 'string',
'caption' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
],
'withBorder' => 'boolean',
'withBorder' => 'boolean',
'withBackground' => 'boolean',
'stretched' => 'boolean',
'stretched' => 'boolean',
],
'table' => [
'table' => [
'withHeadings' => 'boolean',
'content' => [
'content' => [
'type' => 'array',
'data' => [
'-' => [
'type' => 'array',
'data' => [
'-' => [
'type' => 'string',
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
],
],
],
],
],
],
'quote' => [
'text' => [
'type' => 'string',
'quote' => [
'text' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
],
'caption' => [
'type' => 'string',
'caption' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
],
'alignment' => [
0 => 'left',
1 => 'center',
],
],
'code' => [
'code' => [
'code' => [
'type' => 'string',
'type' => 'string',
'allowedTags' => '*',
],
],
'delimiter' => [],
'raw' => [
'raw' => [
'html' => [
'type' => 'string',
'type' => 'string',
'allowedTags' => '*',
],
],
// 'attaches' => [
// 'file' => [
// 'type' => 'array',
// 'data' => [
// 'url' => 'string',
// 'size' => 'integer',
// 'name' => 'string',
// 'extension' => 'string',
// ],
// ],
// 'title' => 'string',
// ]
],
],
];
];
4 changes: 2 additions & 2 deletions resources/views/blocks/list.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@php
$tag = 'ul';
if('ordered' === $data['style']){
if('ordered' === $data['type']){
$tag = 'ol';
}
@endphp
Expand All @@ -9,4 +9,4 @@
@foreach($data['items'] as $item)
<li>{{ $item }}</li>
@endforeach
</{{ $tag }}>
</{{ $tag }}>
2 changes: 1 addition & 1 deletion resources/views/blocks/not-found.blade.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p style="color: red">{{ __('Block Not Found!') }}</p>
<p style="color: red">{{ "{$type}: " . __('Block Not Found!') }}</p>
11 changes: 7 additions & 4 deletions src/LaravelEditorJs.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LaravelEditorJs
* @param string $data
* @return string
*/
public function render(string $data): string
public function render(string $data) : string
{
try {
$configJson = json_encode(config('laravel_editorjs.config') ?: []);
Expand All @@ -28,16 +28,19 @@ public function render(string $data): string

$viewName = "laravel_editorjs::blocks." . Str::snake($block['type'], '-');

if (!View::exists($viewName)) {
if (! View::exists($viewName)) {
$viewName = 'laravel_editorjs::blocks.not-found';
}

$renderedBlocks[] = View::make($viewName, ['data' => $block['data']])->render();
$renderedBlocks[] = View::make($viewName, [
'type' => $block['type'],
'data' => $block['data']
])->render();
}

return implode($renderedBlocks);
} catch (EditorJSException $e) {
throw new \Exception($e->getMessage());
}
}
}
}

0 comments on commit a2a2643

Please sign in to comment.