Skip to content

Commit 9a6adf9

Browse files
authored
Merge pull request #1363 from LLazyEmail/1361-combine-configurereplacer-with-replace-class
1361 combine configurereplacer with replace class
2 parents e8dca5c + 42eb802 commit 9a6adf9

File tree

4 files changed

+48
-136
lines changed

4 files changed

+48
-136
lines changed

src/domain/parse/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ function parse(source, configureReplacer) {
1010
// i'm adding it only because error warning didnt return red stuff
1111
state.innerCheckErrors();
1212

13-
// console.log(state)
14-
1513
return state;
1614
}
1715

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
1-
import {
2-
replaceMarkdown,
3-
// replaceMarkdownPreviewText,
4-
} from '../replace-markdown/replace-md';
51
import Replacer from '../replace/replace-class';
62

7-
// TODO I propose to move inner things of this method into Replace -> runConfigure()
8-
function configureReplacer(state) {
9-
// CAN WE MOVE OUT CALLBACKS INTO REPLACER?????
10-
Replacer.replaceMDBinded = replaceMarkdown.bind(state);
11-
12-
// TODO crashed when here in FULL mode, needs to be fixed
13-
Replacer.previewText();
14-
15-
// Replacer.comments();
16-
// ---
17-
Replacer.typography();
18-
19-
Replacer.template();
20-
21-
Replacer.miscellaneous();
22-
}
3+
const configureReplacer = (state) => Replacer.configure(state);
234

245
export default configureReplacer;

src/domain/replace-class/replace-markdown/replace-md.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ import { mainObject } from '../index';
88

99
// import debuggingReplacer from './debugging';
1010

11-
// import mainObject from
12-
13-
// @TODO replace the name of this method
14-
function prepOurCallback(callbackName) {
11+
const getDataForReplaceByName = (callbackName) => {
1512
if (!callbackName) {
1613
throw new Error(`name of ${callbackName} is undefined or empty`);
1714
}
1815

1916
return mainObject[callbackName];
20-
}
17+
};
2118

2219
/* const simple_debug = (name, params) => {
2320
const { callback_name, singleElement } = params;
@@ -32,17 +29,16 @@ function prepOurCallback(callbackName) {
3229

3330
// plus i wanna have more control for debugging stuff
3431
//----------------------------
35-
function replaceMarkdown(callback_name) {
36-
const singleElement = prepOurCallback(callback_name);
32+
export function replaceMarkdown(callbackName) {
33+
const singleElement = getDataForReplaceByName(callbackName);
3734

3835
// let debug_params = {callback_name, singleElement}
3936

4037
// --------- comment for debugging purposes
41-
// // --- You can comment this when you debugging our wrapper
38+
// --- You can comment this when you debugging our wrapper
4239
const _replacer = singleElement.replacer.bind(this);
4340
this.content = this.content.replace(singleElement.constant, _replacer);
4441
// TODO let's handle a case, when this.content.replace( regex, undefined)
45-
// ------------- end
4642
}
4743

4844
// function replaceMarkdownDebug(callback_name) {
@@ -63,5 +59,3 @@ function replaceMarkdown(callback_name) {
6359
// //--------------
6460
// //--------------
6561
// }
66-
67-
export { replaceMarkdown };

src/domain/replace-class/replace/replace-class.js

Lines changed: 42 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @TODO include things from a new module that we have.
22
// we need to pass all constants somewhere, but not to the replaceWrapper
3+
import { replaceMarkdown } from '../replace-markdown/replace-md';
34

45
class Replace {
56
constructor() {
@@ -9,113 +10,51 @@ class Replace {
910
// Replacer.replaceMDBindedPreviewText = replaceMarkdownPreviewText.bind(state);
1011
// this.replaceMDBindedPreviewText = () => {};
1112

12-
this.previewText = function () {
13-
this.replaceMDBinded('previewText');
14-
};
15-
16-
// this.comments = () => {
17-
// // HEEEEEEYY
18-
// this.replaceMDBinded('');
19-
// };
20-
21-
this.strong = () => {
22-
this.replaceMDBinded('strong');
23-
};
24-
25-
this.em = () => {
26-
this.replaceMDBinded('italic');
27-
};
13+
this.previewText = () => this.replaceMDBinded('previewText');
2814

15+
this.strong = () => this.replaceMDBinded('strong');
16+
this.em = () => this.replaceMDBinded('italic');
2917
// TODO finish this case
30-
this.italicAsterix = () => {
31-
this.replaceMDBinded('italic_asterix');
32-
};
33-
18+
this.italicAsterix = () => this.replaceMDBinded('italic_asterix');
3419
// TODO working not ideally, because we have headings & subtitles,
3520
// so it's confusing a little bit
36-
this.header = () => {
37-
this.replaceMDBinded('header');
38-
};
39-
40-
this.subtitle = () => {
41-
this.replaceMDBinded('header');
42-
};
43-
this.title = () => {
44-
this.replaceMDBinded('header');
45-
};
46-
47-
this.image = () => {
48-
this.replaceMDBinded('image');
49-
};
50-
51-
this.link = () => {
52-
this.replaceMDBinded('link');
53-
};
54-
55-
this.del = () => {
56-
this.replaceMDBinded('del');
57-
};
58-
59-
this.q = () => {
60-
this.replaceMDBinded('q');
61-
};
62-
63-
this.code = () => {
64-
this.replaceMDBinded('code');
65-
};
66-
67-
this.ul = () => {
68-
this.replaceMDBinded('ulList');
69-
};
70-
71-
this.ol = () => {
72-
this.replaceMDBinded('olList');
73-
};
74-
75-
this.blockquote = () => {
76-
this.replaceMDBinded('blockquote');
77-
};
78-
79-
this.hr = () => {
80-
this.replaceMDBinded('hr');
81-
};
82-
83-
this.paragraph = () => {
84-
this.replaceMDBinded('paragraph');
85-
};
86-
//---------------------
87-
// TODO hiding for now, let's fix it after our release
88-
// this.emptyUl = () => {
89-
// this.replaceMDBinded('REGEXP_EMPTY_UL');
90-
// };
91-
92-
// this.emptyOl = () => {
93-
// this.replaceMDBinded('REGEXP_EMPTY_OL');
94-
// };
21+
this.header = () => this.replaceMDBinded('header');
22+
this.subtitle = () => this.replaceMDBinded('header');
23+
this.title = () => this.replaceMDBinded('header');
24+
this.image = () => this.replaceMDBinded('image');
25+
this.link = () => this.replaceMDBinded('link');
26+
this.del = () => this.replaceMDBinded('del');
27+
this.q = () => this.replaceMDBinded('q');
28+
this.code = () => this.replaceMDBinded('code');
29+
this.ul = () => this.replaceMDBinded('ulList');
30+
this.ol = () => this.replaceMDBinded('olList');
31+
this.blockquote = () => this.replaceMDBinded('blockquote');
32+
this.hr = () => this.replaceMDBinded('hr');
33+
this.paragraph = () => this.replaceMDBinded('paragraph');
34+
this.br = () => this.replaceMDBinded('br');
35+
this.sponsorship = () => this.replaceMDBinded('sponsorship');
36+
// here we have a different name
37+
this.memes = () => this.replaceMDBinded('memes');
38+
this.separator = () => this.replaceMDBinded('separator');
9539

96-
// this line is generating an error
97-
// this.replaceMDBinded(this._constants.REGEXP_EMPTY_BLOCKQUOTE, newLine);
98-
// this.emptyBlockquote = () => {
40+
// TODO hiding for now, let's fix it after our release
41+
// this.emptyUl = () => this.replaceMDBinded('REGEXP_EMPTY_UL');
42+
// this.emptyOl = () => this.replaceMDBinded('REGEXP_EMPTY_OL');
43+
// this.comments = () => this.replaceMDBinded('');
44+
// this.emptyBlockquote = () =>
9945
// this.replaceMDBinded('REGEXP_EMPTY_BLOCKQUOTE');
100-
// };
101-
//---------------------
102-
103-
this.br = function () {
104-
this.replaceMDBinded('br');
105-
};
46+
}
10647

107-
this.sponsorship = function () {
108-
this.replaceMDBinded('sponsorship');
109-
};
48+
configure(state) {
49+
this.replaceMDBinded = replaceMarkdown.bind(state);
11050

111-
// here we have a different name
112-
this.memes = function () {
113-
this.replaceMDBinded('memes');
114-
};
51+
// TODO crashed when here in FULL mode, needs to be fixed
52+
this.previewText();
11553

116-
this.separator = function () {
117-
this.replaceMDBinded('separator');
118-
};
54+
// Replacer.comments();
55+
this.typography();
56+
this.template();
57+
this.miscellaneous();
11958
}
12059

12160
template() {
@@ -142,10 +81,10 @@ class Replace {
14281

14382
typography() {
14483
this.strong();
145-
//---------------
84+
14685
this.em();
14786
this.italicAsterix();
148-
//---------------
87+
14988
this.subtitle();
15089
this.title();
15190
// this.header();
@@ -155,13 +94,13 @@ class Replace {
15594
this.del();
15695
this.q();
15796
this.code();
158-
//-----
97+
15998
this.ul();
16099
this.ol();
161-
//-----
100+
162101
this.blockquote();
163102
this.hr();
164-
//-----
103+
165104
this.paragraph();
166105

167106
// TODO fix this

0 commit comments

Comments
 (0)