Completed
Push — master ( 2ee94f...e70fcb )
by Terzi
06:41
created

publishes/mix/editors.js   A

Complexity

Total Complexity 11
Complexity/F 1.38

Size

Lines of Code 87
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
eloc 37
nc 1
dl 0
loc 87
rs 10
c 1
b 0
f 0
wmc 11
mnd 1
bc 10
fnc 8
bpm 1.25
cpm 1.375
noi 0

6 Functions

Rating   Name   Duplication   Size   Complexity  
A editors.js ➔ handleCkEditor 0 12 1
A editors.js ➔ handleTinyMceEditor 0 4 1
A editors.js ➔ handleMediumEditor 0 4 1
A editors.js ➔ handleMarkdownEditor 0 4 1
A editors.js ➔ enable 0 17 2
A editors.js ➔ constructor 0 10 1
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;