-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for default values, number and boolean * Fix bug when no variable * Support for objects * Update documentation
- Loading branch information
Showing
7 changed files
with
104 additions
and
47 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,18 +1,35 @@ | ||
import { VariablesConfig } from "./types"; | ||
import { VariablesConfig, TemplateConfig } from "./types"; | ||
|
||
export default ( | ||
variables: VariablesConfig[] | undefined, | ||
cardConfig: any, | ||
templateConfig: TemplateConfig, | ||
): any => { | ||
if (!variables) { | ||
return cardConfig; | ||
if (!variables && !templateConfig.default) { | ||
return templateConfig.card; | ||
} | ||
let jsonConfig = JSON.stringify(cardConfig); | ||
variables.forEach(variable => { | ||
let variableArray: VariablesConfig[] = []; | ||
if (variables) { | ||
variableArray = variables.slice(0); | ||
} | ||
if (templateConfig.default) { | ||
variableArray = variableArray.concat(templateConfig.default); | ||
} | ||
let jsonConfig = JSON.stringify(templateConfig.card); | ||
variableArray.forEach(variable => { | ||
const key = Object.keys(variable)[0]; | ||
const value = Object.values(variable)[0]; | ||
const rxp = new RegExp(`\\[\\[${key}\\]\\]`, "gm"); | ||
jsonConfig = jsonConfig.replace(rxp, value); | ||
if (typeof value === 'number' || typeof value === 'boolean') { | ||
const rxp2 = new RegExp(`"\\[\\[${key}\\]\\]"`, "gm"); | ||
jsonConfig = jsonConfig.replace(rxp2, (value as unknown as string)); | ||
} | ||
if (typeof value === 'object') { | ||
const rxp2 = new RegExp(`"\\[\\[${key}\\]\\]"`, "gm"); | ||
const valueString = JSON.stringify(value); | ||
jsonConfig = jsonConfig.replace(rxp2, valueString); | ||
} else { | ||
jsonConfig = jsonConfig.replace(rxp, value); | ||
} | ||
}); | ||
return JSON.parse(jsonConfig); | ||
} |
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