-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(api-service): variable extraction (#7369)
- Loading branch information
1 parent
55f7de6
commit f0d20c3
Showing
7 changed files
with
62 additions
and
46 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
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
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,48 @@ | ||
import { JSONContent } from '@maily-to/render'; | ||
|
||
export enum MailyContentTypeEnum { | ||
VARIABLE = 'variable', | ||
FOR = 'for', | ||
BUTTON = 'button', | ||
IMAGE = 'image', | ||
} | ||
|
||
export const variableAttributeConfig = (type: MailyContentTypeEnum) => { | ||
//todo add variable type | ||
if (type === MailyContentTypeEnum.BUTTON) { | ||
return [ | ||
{ attr: 'text', flag: 'isTextVariable' }, | ||
{ attr: 'url', flag: 'isUrlVariable' }, | ||
{ attr: 'showIfKey', flag: 'showIfKey' }, | ||
]; | ||
} | ||
|
||
if (type === MailyContentTypeEnum.IMAGE) { | ||
return [ | ||
{ attr: 'src', flag: 'isSrcVariable' }, | ||
{ attr: 'externalLink', flag: 'isExternalLinkVariable' }, | ||
{ attr: 'showIfKey', flag: 'showIfKey' }, | ||
]; | ||
} | ||
|
||
return [{ attr: 'showIfKey', flag: 'showIfKey' }]; | ||
}; | ||
|
||
export function processNodeAttrs(node: JSONContent): JSONContent { | ||
if (!node.attrs) return node; | ||
|
||
const typeConfig = variableAttributeConfig(node.type as MailyContentTypeEnum); | ||
|
||
for (const { attr, flag } of typeConfig) { | ||
if (node.attrs[flag] && node.attrs[attr]) { | ||
// eslint-disable-next-line no-param-reassign | ||
node.attrs[attr] = wrapInLiquidOutput(node.attrs[attr] as string); | ||
} | ||
} | ||
|
||
return node; | ||
} | ||
|
||
export function wrapInLiquidOutput(value: string): string { | ||
return `{{${value}}}`; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.