From 81581f61037a6dcb66d5ca57d9f2395721cc27ee Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 20 Nov 2019 22:28:04 +0100 Subject: [PATCH] cleanup and tests added for ci/cd --- Models/Editor.js | 32 +++++----- Models/EditorDoc.php | 34 ++++++++-- Theme/Backend/Components/Editor/BaseView.php | 13 ++++ Theme/Backend/Components/Editor/TextView.php | 65 +++++++++++++++++--- 4 files changed, 116 insertions(+), 28 deletions(-) diff --git a/Models/Editor.js b/Models/Editor.js index e520245..b918790 100644 --- a/Models/Editor.js +++ b/Models/Editor.js @@ -3,9 +3,9 @@ import { Markdown } from '../../../jsOMS/Utils/Parser/Markdown.js'; export class Editor { constructor (id) { - this.id = id; - this.editor = document.getElementById(id); - this.markdown = new Markdown.Converter({extensions: [], sanitize: true}); + this.id = id; + this.editor = document.getElementById(id); + this.markdown = new Markdown.Converter({extensions: [], sanitize: true}); this.editorContent = null; }; @@ -51,29 +51,29 @@ export class Editor { break; case 'bold': - startOffset = 2; - endOffset = 2; + startOffset = 2; + endOffset = 2; textarea.value = textarea.value.slice(0, startPosition) + '**' + textarea.value.slice(startPosition, endPosition) + '**' + textarea.value.slice(endPosition, textarea.value.length); break; case 'italic': - startOffset = 1; - endOffset = 1; + startOffset = 1; + endOffset = 1; textarea.value = textarea.value.slice(0, startPosition) + '*' + textarea.value.slice(startPosition, endPosition) + '*' + textarea.value.slice(endPosition, textarea.value.length); break; case 'underline': - startOffset = 2; - endOffset = 2; + startOffset = 2; + endOffset = 2; textarea.value = textarea.value.slice(0, startPosition) + '__' + textarea.value.slice(startPosition, endPosition) + '__' + textarea.value.slice(endPosition, textarea.value.length); break; case 'strikethrough': - startOffset = 2; - endOffset = 2; + startOffset = 2; + endOffset = 2; textarea.value = textarea.value.slice(0, startPosition) + '~~' + textarea.value.slice(startPosition, endPosition) + '~~' + textarea.value.slice(endPosition, textarea.value.length); @@ -132,22 +132,22 @@ export class Editor { case 'link': startOffset = 1; endOffset = 0; - let link = textarea.value.slice(startPosition, endPosition); + let link = textarea.value.slice(startPosition, endPosition); textarea.value = textarea.value.slice(0, startPosition) + ((link.startsWith('http') || link.startsWith('www')) ? '[' + link + ']' : '[' + link + '](https://www.website.com "' + link + '")') + textarea.value.slice(endPosition, textarea.value.length); break; case 'code': - startOffset = 1; - endOffset = 1; + startOffset = 1; + endOffset = 1; textarea.value = textarea.value.slice(0, startPosition) + '`' + textarea.value.slice(startPosition, endPosition) + '`' + textarea.value.slice(endPosition, textarea.value.length); break; case 'quote': - startOffset = 2; - endOffset = 0; + startOffset = 2; + endOffset = 0; textarea.value = textarea.value.slice(0, startPosition) + '> ' + textarea.value.slice(startPosition, textarea.value.length); break; diff --git a/Models/EditorDoc.php b/Models/EditorDoc.php index 3099d90..eaf32f9 100644 --- a/Models/EditorDoc.php +++ b/Models/EditorDoc.php @@ -94,6 +94,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable } /** + * Get the content + * * @return string * * @since 1.0.0 @@ -104,7 +106,9 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable } /** - * @param string $content + * Set the content + * + * @param string $content Content * * @return void * @@ -116,7 +120,9 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable } /** - * @param string $plain + * Set the plain text + * + * @param string $plain Plain text * * @return void * @@ -128,6 +134,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable } /** + * Get the plain text + * * @return string * * @since 1.0.0 @@ -138,6 +146,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable } /** + * Get created at + * * @return \DateTime * * @since 1.0.0 @@ -148,6 +158,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable } /** + * Get the id + * * @return int * * @since 1.0.0 @@ -158,6 +170,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable } /** + * Get created by + * * @return int * * @since 1.0.0 @@ -168,7 +182,9 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable } /** - * @param int $id + * Set created by + * + * @param int $id Creator * * @since 1.0.0 */ @@ -178,6 +194,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable } /** + * Get the title + * * @return string * * @since 1.0.0 @@ -188,7 +206,9 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable } /** - * @param string $title + * Set the title + * + * @param string $title Title * * @return mixed * @@ -200,6 +220,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable } /** + * Get the path + * * @return string * * @since 1.0.0 @@ -210,7 +232,9 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable } /** - * @param string $path + * Set the path if file + * + * @param string $path Path to file * * @return mixed * diff --git a/Theme/Backend/Components/Editor/BaseView.php b/Theme/Backend/Components/Editor/BaseView.php index 814be36..bfca71b 100644 --- a/Theme/Backend/Components/Editor/BaseView.php +++ b/Theme/Backend/Components/Editor/BaseView.php @@ -31,6 +31,12 @@ use phpOMS\Views\View; */ class BaseView extends View { + /** + * Editor id + * + * @var string + * @since 1.0.0 + */ private $id = ''; /** @@ -47,6 +53,13 @@ class BaseView extends View $this->addData('text', $view); } + /** + * Render the editor id + * + * @return string + * + * @since 1.0.0 + */ public function renderId() : string { return $this->printHtml($this->id); diff --git a/Theme/Backend/Components/Editor/TextView.php b/Theme/Backend/Components/Editor/TextView.php index d729605..64f56bf 100644 --- a/Theme/Backend/Components/Editor/TextView.php +++ b/Theme/Backend/Components/Editor/TextView.php @@ -30,13 +30,13 @@ use phpOMS\Views\View; */ class TextView extends View { - private $id = ''; - private $name = ''; - private $form = ''; - private $plain = ''; - private $preview = ''; - private $tplText = ''; - private $tplValue = ''; + private string $id = ''; + private string $name = ''; + private string $form = ''; + private string $plain = ''; + private string $preview = ''; + private string $tplText = ''; + private string $tplValue = ''; /** * {@inheritdoc} @@ -47,36 +47,87 @@ class TextView extends View $this->setTemplate('/Modules/Editor/Theme/Backend/Components/Editor/inline-editor'); } + /** + * Render the form id + * + * @return string + * + * @since 1.0.0 + */ public function renderId() : string { return $this->printHtml($this->id); } + /** + * Render the form name + * + * @return string + * + * @since 1.0.0 + */ public function renderName() : string { return $this->printHtml($this->name); } + /** + * Render the form attribute name + * + * @return string + * + * @since 1.0.0 + */ public function renderForm() : string { return $this->printHtml($this->form); } + /** + * Render the preview + * + * Usually markdown + * + * @return string + * + * @since 1.0.0 + */ public function renderPreview() : string { return $this->preview; } + /** + * Render the plain text + * + * @return string + * + * @since 1.0.0 + */ public function renderPlain() : string { return $this->printHtml($this->plain); } + /** + * Render template text reference + * + * @return string + * + * @since 1.0.0 + */ public function renderTplText() : string { return $this->printHtml($this->tplText); } + /** + * Render template value reference + * + * @return string + * + * @since 1.0.0 + */ public function renderTplValue() : string { return $this->printHtml($this->tplValue);