- saving progress;
This commit is contained in:
11
src/helpers/getTokens.js
Normal file
11
src/helpers/getTokens.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { tokenize } from 'expression-language';
|
||||
|
||||
const getTokens = expr => tokenize(expr).tokens
|
||||
.filter((o, i, arr) => o.type === 'name'
|
||||
&& (typeof arr[i+1] === 'undefined'
|
||||
|| (typeof arr[i+1] !== 'undefined' && arr[i+1].value !== '('))
|
||||
)
|
||||
.map(o => o.value)
|
||||
.filter((v, i, arr) => arr.indexOf(v) === i);
|
||||
|
||||
export default getTokens;
|
||||
23
src/helpers/renderWithDataVars.js
Normal file
23
src/helpers/renderWithDataVars.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import mustache from 'mustache';
|
||||
import { replace } from 'ramda';
|
||||
|
||||
/**
|
||||
* Use mustachejs to parse content and replace variables with their values
|
||||
* Each variable (everything in brackets) is expression for EE
|
||||
*
|
||||
* @param {string} content
|
||||
* @param {object} context
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
const renderWithDataVars = (content = '', context = {}) => {
|
||||
try {
|
||||
let newContent = replace(/{/g, '{{&', content);
|
||||
newContent = replace(/}/g, '}}', newContent);
|
||||
return mustache.render(newContent, context);
|
||||
} catch {
|
||||
return content;
|
||||
}
|
||||
};
|
||||
|
||||
export default renderWithDataVars;
|
||||
Reference in New Issue
Block a user