Skip to content

Commit

Permalink
Merge pull request #1363 from LLazyEmail/1361-combine-configurereplac…
Browse files Browse the repository at this point in the history
…er-with-replace-class

1361 combine configurereplacer with replace class
  • Loading branch information
vadim9999 authored Jul 23, 2022
2 parents e8dca5c + 42eb802 commit 9a6adf9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 136 deletions.
2 changes: 0 additions & 2 deletions src/domain/parse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ function parse(source, configureReplacer) {
// i'm adding it only because error warning didnt return red stuff
state.innerCheckErrors();

// console.log(state)

return state;
}

Expand Down
21 changes: 1 addition & 20 deletions src/domain/replace-class/configuration/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
import {
replaceMarkdown,
// replaceMarkdownPreviewText,
} from '../replace-markdown/replace-md';
import Replacer from '../replace/replace-class';

// TODO I propose to move inner things of this method into Replace -> runConfigure()
function configureReplacer(state) {
// CAN WE MOVE OUT CALLBACKS INTO REPLACER?????
Replacer.replaceMDBinded = replaceMarkdown.bind(state);

// TODO crashed when here in FULL mode, needs to be fixed
Replacer.previewText();

// Replacer.comments();
// ---
Replacer.typography();

Replacer.template();

Replacer.miscellaneous();
}
const configureReplacer = (state) => Replacer.configure(state);

export default configureReplacer;
16 changes: 5 additions & 11 deletions src/domain/replace-class/replace-markdown/replace-md.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ import { mainObject } from '../index';

// import debuggingReplacer from './debugging';

// import mainObject from

// @TODO replace the name of this method
function prepOurCallback(callbackName) {
const getDataForReplaceByName = (callbackName) => {
if (!callbackName) {
throw new Error(`name of ${callbackName} is undefined or empty`);
}

return mainObject[callbackName];
}
};

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

// plus i wanna have more control for debugging stuff
//----------------------------
function replaceMarkdown(callback_name) {
const singleElement = prepOurCallback(callback_name);
export function replaceMarkdown(callbackName) {
const singleElement = getDataForReplaceByName(callbackName);

// let debug_params = {callback_name, singleElement}

// --------- comment for debugging purposes
// // --- You can comment this when you debugging our wrapper
// --- You can comment this when you debugging our wrapper
const _replacer = singleElement.replacer.bind(this);
this.content = this.content.replace(singleElement.constant, _replacer);
// TODO let's handle a case, when this.content.replace( regex, undefined)
// ------------- end
}

// function replaceMarkdownDebug(callback_name) {
Expand All @@ -63,5 +59,3 @@ function replaceMarkdown(callback_name) {
// //--------------
// //--------------
// }

export { replaceMarkdown };
145 changes: 42 additions & 103 deletions src/domain/replace-class/replace/replace-class.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @TODO include things from a new module that we have.
// we need to pass all constants somewhere, but not to the replaceWrapper
import { replaceMarkdown } from '../replace-markdown/replace-md';

class Replace {
constructor() {
Expand All @@ -9,113 +10,51 @@ class Replace {
// Replacer.replaceMDBindedPreviewText = replaceMarkdownPreviewText.bind(state);
// this.replaceMDBindedPreviewText = () => {};

this.previewText = function () {
this.replaceMDBinded('previewText');
};

// this.comments = () => {
// // HEEEEEEYY
// this.replaceMDBinded('');
// };

this.strong = () => {
this.replaceMDBinded('strong');
};

this.em = () => {
this.replaceMDBinded('italic');
};
this.previewText = () => this.replaceMDBinded('previewText');

this.strong = () => this.replaceMDBinded('strong');
this.em = () => this.replaceMDBinded('italic');
// TODO finish this case
this.italicAsterix = () => {
this.replaceMDBinded('italic_asterix');
};

this.italicAsterix = () => this.replaceMDBinded('italic_asterix');
// TODO working not ideally, because we have headings & subtitles,
// so it's confusing a little bit
this.header = () => {
this.replaceMDBinded('header');
};

this.subtitle = () => {
this.replaceMDBinded('header');
};
this.title = () => {
this.replaceMDBinded('header');
};

this.image = () => {
this.replaceMDBinded('image');
};

this.link = () => {
this.replaceMDBinded('link');
};

this.del = () => {
this.replaceMDBinded('del');
};

this.q = () => {
this.replaceMDBinded('q');
};

this.code = () => {
this.replaceMDBinded('code');
};

this.ul = () => {
this.replaceMDBinded('ulList');
};

this.ol = () => {
this.replaceMDBinded('olList');
};

this.blockquote = () => {
this.replaceMDBinded('blockquote');
};

this.hr = () => {
this.replaceMDBinded('hr');
};

this.paragraph = () => {
this.replaceMDBinded('paragraph');
};
//---------------------
// TODO hiding for now, let's fix it after our release
// this.emptyUl = () => {
// this.replaceMDBinded('REGEXP_EMPTY_UL');
// };

// this.emptyOl = () => {
// this.replaceMDBinded('REGEXP_EMPTY_OL');
// };
this.header = () => this.replaceMDBinded('header');
this.subtitle = () => this.replaceMDBinded('header');
this.title = () => this.replaceMDBinded('header');
this.image = () => this.replaceMDBinded('image');
this.link = () => this.replaceMDBinded('link');
this.del = () => this.replaceMDBinded('del');
this.q = () => this.replaceMDBinded('q');
this.code = () => this.replaceMDBinded('code');
this.ul = () => this.replaceMDBinded('ulList');
this.ol = () => this.replaceMDBinded('olList');
this.blockquote = () => this.replaceMDBinded('blockquote');
this.hr = () => this.replaceMDBinded('hr');
this.paragraph = () => this.replaceMDBinded('paragraph');
this.br = () => this.replaceMDBinded('br');
this.sponsorship = () => this.replaceMDBinded('sponsorship');
// here we have a different name
this.memes = () => this.replaceMDBinded('memes');
this.separator = () => this.replaceMDBinded('separator');

// this line is generating an error
// this.replaceMDBinded(this._constants.REGEXP_EMPTY_BLOCKQUOTE, newLine);
// this.emptyBlockquote = () => {
// TODO hiding for now, let's fix it after our release
// this.emptyUl = () => this.replaceMDBinded('REGEXP_EMPTY_UL');
// this.emptyOl = () => this.replaceMDBinded('REGEXP_EMPTY_OL');
// this.comments = () => this.replaceMDBinded('');
// this.emptyBlockquote = () =>
// this.replaceMDBinded('REGEXP_EMPTY_BLOCKQUOTE');
// };
//---------------------

this.br = function () {
this.replaceMDBinded('br');
};
}

this.sponsorship = function () {
this.replaceMDBinded('sponsorship');
};
configure(state) {
this.replaceMDBinded = replaceMarkdown.bind(state);

// here we have a different name
this.memes = function () {
this.replaceMDBinded('memes');
};
// TODO crashed when here in FULL mode, needs to be fixed
this.previewText();

this.separator = function () {
this.replaceMDBinded('separator');
};
// Replacer.comments();
this.typography();
this.template();
this.miscellaneous();
}

template() {
Expand All @@ -142,10 +81,10 @@ class Replace {

typography() {
this.strong();
//---------------

this.em();
this.italicAsterix();
//---------------

this.subtitle();
this.title();
// this.header();
Expand All @@ -155,13 +94,13 @@ class Replace {
this.del();
this.q();
this.code();
//-----

this.ul();
this.ol();
//-----

this.blockquote();
this.hr();
//-----

this.paragraph();

// TODO fix this
Expand Down

0 comments on commit 9a6adf9

Please sign in to comment.