jcc-express-mvc 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -10,8 +10,8 @@ class Template {
|
|
|
10
10
|
include: /@include\((?<includePath>['"]([^'"]+)['"])\)/,
|
|
11
11
|
ternary:
|
|
12
12
|
/@ternary\((?<condition>[a-zA-Z0-9_.-]+)\s*\?\s*(?<trueData>[\s\S]+?)\s*:\s*(?<falseData>[\s\S]+?)\)/,
|
|
13
|
-
variable: /{{\s*(?<param>
|
|
14
|
-
auth: /@auth(?<authBody>[\s\S]*?)@endauth/,
|
|
13
|
+
variable: /{{\s*(?<param>(.*?))\s*}}/,
|
|
14
|
+
auth: /@auth(?:(\((?<authData>[^)]*)\)))?(?<authBody>[\s\S]*?)@endauth/,
|
|
15
15
|
guest: /@guest(?<guestBody>[\s\S]*?)@endguest/,
|
|
16
16
|
};
|
|
17
17
|
|
|
@@ -118,35 +118,40 @@ class Template {
|
|
|
118
118
|
new RegExp(
|
|
119
119
|
Object.values(this.#directives)
|
|
120
120
|
.map((regex) => `(${regex.source})`)
|
|
121
|
-
.join("|")
|
|
122
|
-
)
|
|
121
|
+
.join("|"),
|
|
122
|
+
),
|
|
123
123
|
);
|
|
124
124
|
if (!match) return content;
|
|
125
|
+
switch (true) {
|
|
126
|
+
case match[0].startsWith("@include"):
|
|
127
|
+
return this.#includes(content, match, param);
|
|
125
128
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
if (match[0].startsWith("@auth")) {
|
|
133
|
-
return this.#auth(content, match, param);
|
|
134
|
-
}
|
|
135
|
-
if (match[0].startsWith("@guest")) {
|
|
136
|
-
return this.#guest(content, match, param);
|
|
137
|
-
}
|
|
138
|
-
if (match[0].startsWith("@if")) {
|
|
139
|
-
return this.#handleCondition(content, match, param);
|
|
140
|
-
}
|
|
141
|
-
if (match[0].startsWith("@ternary")) {
|
|
142
|
-
return this.#ternary(content, match, param);
|
|
143
|
-
}
|
|
129
|
+
case match[0].startsWith("@foreach"):
|
|
130
|
+
return this.#handleLoop(content, match, param);
|
|
131
|
+
|
|
132
|
+
case match[0].startsWith("@auth"):
|
|
133
|
+
return this.#auth(content, match, param);
|
|
144
134
|
|
|
145
|
-
|
|
135
|
+
case match[0].startsWith("@guest"):
|
|
136
|
+
return this.#guest(content, match, param);
|
|
137
|
+
|
|
138
|
+
case match[0].startsWith("@if"):
|
|
139
|
+
return this.#handleCondition(content, match, param);
|
|
140
|
+
|
|
141
|
+
case match[0].startsWith("@ternary"):
|
|
142
|
+
return this.#ternary(content, match, param);
|
|
143
|
+
|
|
144
|
+
case match[0].startsWith("{{"):
|
|
145
|
+
return this.#handleVariable(content, match, param);
|
|
146
|
+
default:
|
|
147
|
+
return content;
|
|
148
|
+
}
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
#compiler(content) {
|
|
149
|
-
const newContent = this.#extends(content)
|
|
152
|
+
const newContent = this.#extends(content)
|
|
153
|
+
.replace(/(\{\{\-\-)/g, "<!--")
|
|
154
|
+
.replace(/(\-\-\}\})/g, "-->");
|
|
150
155
|
const finalContent = this.#parser(newContent);
|
|
151
156
|
return finalContent
|
|
152
157
|
.replace(/(\{\{\-\-)/g, "<!--")
|
|
@@ -33,7 +33,7 @@ class Util {
|
|
|
33
33
|
if (item.length === 2) {
|
|
34
34
|
const newLayout = layoutContent.replace(
|
|
35
35
|
`@yield(${item[0]})`,
|
|
36
|
-
item[1].replace(/\"/g, "")
|
|
36
|
+
item[1].replace(/\"/g, ""),
|
|
37
37
|
);
|
|
38
38
|
const { beforMatch, afterMatch } = Util.content(content, match);
|
|
39
39
|
return Util.layout(beforMatch + afterMatch, newLayout);
|
|
@@ -42,7 +42,7 @@ class Util {
|
|
|
42
42
|
if (sectionContent) {
|
|
43
43
|
const newLayout = layoutContent.replace(
|
|
44
44
|
`@yield(${sectionContent})`,
|
|
45
|
-
match?.groups?.sectionBody
|
|
45
|
+
match?.groups?.sectionBody,
|
|
46
46
|
);
|
|
47
47
|
const { beforMatch, afterMatch } = Util.content(content, match);
|
|
48
48
|
return Util.layout(beforMatch + afterMatch, newLayout);
|
|
@@ -51,7 +51,7 @@ class Util {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
static accessNestedProperty(obj, propertyString) {
|
|
54
|
-
const properties = propertyString?.split(".") ?? [];
|
|
54
|
+
const properties = propertyString.replace(/\s/g, "")?.split(".") ?? [];
|
|
55
55
|
return properties.reduce((acc, prop) => acc?.[prop], obj) ?? "";
|
|
56
56
|
}
|
|
57
57
|
|