Test Failed
Push — master ( 6508c2...e5864c )
by Terzi
14:31
created

EditorManager.constructor   A

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
c 0
b 0
f 0
dl 0
loc 10
rs 10
1
class EditorManager {
2
    constructor(mix) {
3
        this.mix = mix;
4
5
        this.KNOWN_EDITORS = [
6
            'TinyMce',
7
            'Medium',
8
            'Markdown',
9
            'Ck'
10
        ];
11
    }
12
13
    /**
14
     * Assemble required editors.
15
     */
16
    enable(editors) {
17
        if (!Array.isArray(editors)) {
18
            editors = Array.from(arguments);
19
        }
20
21
        editors.forEach((editor) => {
22
            if (this.KNOWN_EDITORS.indexOf(editor) === -1) {
23
                throw new Error(`Unknown editor: ${editor}`);
24
            }
25
        });
26
27
        (editors || ['Medium']).forEach((editor) => {
28
            const method = `handle${editor}Editor`;
29
30
            this[method]();
31
        });
32
    }
33
34
    /**
35
     * Assembles TinyMCE editor
36
     *
37
     * @requires `tinymce@^4.6.4` package
38
     * @note npm i tinymce@^4.6.4 --save-dev
39
     */
40
    handleTinyMceEditor() {
41
        this.mix.copy('node_modules/tinymce/skins', 'build/editors/skins');
42
        this.mix.js('resources/js/editors/tinymce.js', 'build/editors/tinymce.js');
43
    }
44
45
    /**
46
     * Assembles CK editor
47
     *
48
     * @requires `ckeditor@^4.7.0` package
49
     * @note npm i ckeditor@^4.7.0 --save-dev
50
     */
51
    handleCkEditor() {
52
        this.mix.copy([
53
            'node_modules/ckeditor/config.js',
54
            'node_modules/ckeditor/styles.js',
55
            'node_modules/ckeditor/contents.css'
56
        ], 'build/editors');
57
        this.mix.copy('node_modules/ckeditor/lang/en.js', 'build/editors/lang/en.js');
58
        this.mix.copy('node_modules/ckeditor/skins', 'build/editors/skins');
59
        this.mix.copy('node_modules/ckeditor/plugins', 'build/editors/plugins');
60
61
        this.mix.js('resources/js/editors/ckeditor.js', 'build/editors/ckeditor.js');
62
    }
63
64
    /**
65
     * Assembles Medium editor.
66
     *
67
     * @requires `medium-editor@^5.23.1` package
68
     * @note npm i medium-editor@^5.23.1 --save-dev
69
     */
70
    handleMediumEditor() {
71
        this.mix.js('resources/js/editors/medium.js', 'build/editors/medium.js');
72
        this.mix.sass('resources/sass/editors/medium.scss', 'build/editors/medium.css');
73
    }
74
75
    /**
76
     * Assembles Markdown editor.
77
     *
78
     * @requires `simplemde` package
79
     * @note npm i simplemde --save-dev
80
     */
81
    handleMarkdownEditor() {
82
        this.mix.js('resources/js/editors/markdown.js', 'build/editors/markdown.js');
83
        this.mix.sass('resources/sass/editors/markdown.scss', 'build/editors/markdown.css');
84
    }
85
}
86
87
module.exports = EditorManager;