-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement custom template description functionality for clubhouse
add clubhouse customTemplate db settings add clubhouse tab to settings page create templateParser and templateMessenger classes
- Loading branch information
Jeremy
committed
Apr 21, 2020
1 parent
ef8fc4f
commit 5c5e222
Showing
11 changed files
with
180 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const browser = require('webextension-polyfill'); | ||
|
||
class CustomTemplateMessenger { | ||
customTemplate = ""; | ||
customTemplateMessageName = ""; | ||
useCustomTemplate = false; | ||
|
||
constructor(customTemplateMessageName: string){ | ||
this.customTemplateMessageName = customTemplateMessageName; | ||
} | ||
|
||
async fetchSettings () { | ||
await browser.runtime.sendMessage({ | ||
type: this.customTemplateMessageName | ||
}).then( | ||
(res) => this.handleResponse(res), | ||
(err) => this.handleError(err) | ||
); | ||
} | ||
|
||
handleError (error: any) { | ||
console.error('handleError: ', error); | ||
} | ||
|
||
handleResponse = ({ useCustomTemplate, customTemplate }: CustomTemplateMessage):void => { | ||
this.useCustomTemplate = useCustomTemplate; | ||
this.customTemplate = customTemplate; | ||
} | ||
|
||
} | ||
|
||
export default CustomTemplateMessenger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class CustomTemplateParser { | ||
templateMap = {}; | ||
templateStr = ""; | ||
regexParser: RegExp; | ||
constructor(templateMap: CustomTemplateParserMap, templateStr: string){ | ||
this.templateMap = templateMap; | ||
this.templateStr = templateStr; | ||
this.regexParser = new RegExp(/{{\s*(.*?)\s*}}/); | ||
} | ||
parse():string { | ||
let strMatch = this.templateStr.match(this.regexParser); | ||
while (strMatch) { | ||
this.templateStr = this.templateStr.replace(strMatch[0], this.templateMap[strMatch[1]]()); | ||
strMatch = this.templateStr.match(this.regexParser); | ||
} | ||
return this.templateStr; | ||
}; | ||
} | ||
|
||
export default CustomTemplateParser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters