|
1
|
|
|
export let abeTag = /({{abe.*?[\s\S].*?}})/g; |
|
|
|
|
|
|
2
|
|
|
// |
|
3
|
|
|
export let abePattern = /[^"']({{abe.*?type=[\'|\"][text|rich|textarea]+[\'|\"][\s\S].*?}})/g; |
|
|
|
|
|
|
4
|
|
|
// This pattern finds all abe tags enclosed in a HTML tag attribute |
|
5
|
|
|
// export let abeAsAttributePattern = /( [A-Za-z0-9\-\_]+=["|']{1}{{abe.*?}})/g; |
|
6
|
|
|
// export let abeAsAttributePattern = /( [A-Za-z0-9\-\_]+=["|']{1})(.*?)({{abe.*?}})/g |
|
7
|
|
|
export let abeAsAttributePattern = /( [A-Za-z0-9\-\_]+=["|']{1})([^=]*?)({{abe.*?["|'| ]}})["|']/g; |
|
|
|
|
|
|
8
|
|
|
// This pattern finds all {{#each ...}}...{{/each}} blocks |
|
9
|
|
|
// export let eachBlockPattern = />\s*(\{\{#each (\r|\t|\n|.)*?\/each\}\})/g; |
|
10
|
|
|
export let eachBlockPattern = /(\{\{#each (\r|\t|\n|.)*?\/each\}\})/g; |
|
|
|
|
|
|
11
|
|
|
// This pattern finds all {{#each ...}}...{{/each}} blocks |
|
12
|
|
|
export let blockPattern = /(\{\{#each.*\}\}[\s\S]*?\{\{\/each\}\})/g; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* escape a regex |
|
16
|
|
|
* @param {String} str |
|
17
|
|
|
* @param {String} params g,m,i |
|
|
|
|
|
|
18
|
|
|
* @return {Object} RegExp |
|
19
|
|
|
*/ |
|
20
|
|
|
export function getAttr (str, attr) { |
|
21
|
|
|
var rex = new RegExp(attr + '=["|\']([\\S\\s]*?)["|\']( +[a-zA-Z0-9-]*?=|}})') |
|
22
|
|
|
var res = rex.exec(str) |
|
23
|
|
|
res = (res != null && res.length > 1) ? res[1] : '' |
|
24
|
|
|
return res |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* escape a regex |
|
29
|
|
|
* @param {String} str |
|
30
|
|
|
* @param {String} params g,m,i |
|
31
|
|
|
* @return {Object} RegExp |
|
32
|
|
|
*/ |
|
33
|
|
|
export function escapeTextToRegex(str, params) { |
|
34
|
|
|
str = str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') |
|
35
|
|
|
return new RegExp(str, params) |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Test if a string don't contains string key from ABE block statement |
|
40
|
|
|
* @param {String} str string to test |
|
41
|
|
|
* @return {Boolean} true = this is not a block content |
|
42
|
|
|
*/ |
|
43
|
|
|
export function isSingleAbe(str, text){ |
|
44
|
|
|
return !new RegExp('#each(.)+?' + getAttr(str, 'key').split('.')[0]).test(text) && |
|
45
|
|
|
str.indexOf('{{#') < 0 && |
|
46
|
|
|
str.indexOf('#each') < 0 && |
|
47
|
|
|
str.indexOf('{{/') < 0 && |
|
48
|
|
|
str.indexOf('/each') < 0 && |
|
49
|
|
|
str.indexOf('attrAbe') < 0 |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Test if a string don't contains string key from ABE block statement |
|
54
|
|
|
* @param {String} str string to test |
|
55
|
|
|
* @return {Boolean} true = this is not a block content |
|
56
|
|
|
*/ |
|
57
|
|
|
export function getEachParentKey(str){ |
|
58
|
|
|
return getAttr(str, 'key').split('.')[0] |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Test if a string contains string key from ABE block statement |
|
63
|
|
|
* @param {String} str string to test |
|
64
|
|
|
* @return {Boolean} true = this is a block content |
|
65
|
|
|
*/ |
|
66
|
|
|
export function isBlockAbe(str) { |
|
67
|
|
|
return str.indexOf('abe') > -1 && getAttr(str, 'key').indexOf('.') > -1 |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Test if a string contains string key from {{#each}} block statement |
|
72
|
|
|
* @param {String} str string to test |
|
73
|
|
|
* @return {Boolean} true = this is a block content |
|
74
|
|
|
*/ |
|
75
|
|
|
export function isEachStatement(str) { |
|
76
|
|
|
return str.indexOf('#each') > -1 || str.indexOf('/each') > -1 |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Test if a string contains string key from {{#each}} block statement |
|
81
|
|
|
* @param {String} str string to test |
|
|
|
|
|
|
82
|
|
|
* @return {Boolean} true = this is a block content |
|
83
|
|
|
*/ |
|
84
|
|
|
export function getTagAbeTypeRequest(text) { |
|
85
|
|
|
let listReg = /({{abe.*type=[\'|\"]data.*}})/g |
|
86
|
|
|
var matches = [] |
|
87
|
|
|
var match |
|
88
|
|
|
while (match = listReg.exec(text)) { |
|
89
|
|
|
matches.push(match) |
|
90
|
|
|
} |
|
91
|
|
|
return matches |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
*/ |
|
96
|
|
|
export function getTagAbeWithType(text, type) { |
|
97
|
|
|
var listReg = new RegExp(`({{abe.*type=[\\'|\\"]${type}.*}})`, 'g') |
|
98
|
|
|
var matches = [] |
|
99
|
|
|
var match |
|
100
|
|
|
while (match = listReg.exec(text)) { |
|
101
|
|
|
matches.push(match[0]) |
|
102
|
|
|
} |
|
103
|
|
|
return matches |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
*/ |
|
108
|
|
|
export function getTagAbeWithTab(text, tab) { |
|
109
|
|
|
var listReg = new RegExp(`({{abe.*tab=[\\'|\\"]${tab}.*}})`, 'g') |
|
110
|
|
|
var matches = [] |
|
111
|
|
|
var match |
|
112
|
|
|
while (match = listReg.exec(text)) { |
|
113
|
|
|
matches.push(match[0]) |
|
114
|
|
|
} |
|
115
|
|
|
return matches |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
export function validDataAbe(str){ |
|
119
|
|
|
return str.replace(/\[([0-9]*)\]/g, '$1') |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
export function getWorkflowFromOperationsUrl(str){ |
|
123
|
|
|
let regUrl = /\/abe\/operations\/(.*?)\/(.*?)\// |
|
124
|
|
|
var workflow = 'draft' |
|
125
|
|
|
var match = str.match(regUrl) |
|
126
|
|
|
if (match != null && match[2] != null) { |
|
127
|
|
|
workflow = match[2] |
|
128
|
|
|
} |
|
129
|
|
|
var postUrl = str.replace(regUrl, '') |
|
130
|
|
|
return { |
|
131
|
|
|
workflow: workflow, |
|
132
|
|
|
postUrl: postUrl |
|
133
|
|
|
} |
|
134
|
|
|
} |