neobiz 4.3.12 → 4.5.0
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/browser.js +47 -21
- package/example/orderChild.v.js +15 -0
- package/package.json +1 -1
- package/readme.md +45 -22
package/browser.js
CHANGED
|
@@ -3,37 +3,61 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const adp = {};
|
|
6
|
-
let d = render ? "_render" : "render";
|
|
7
6
|
let option = {
|
|
8
7
|
camelCase: false,
|
|
8
|
+
prefix: false,
|
|
9
|
+
prefixAttr: false,
|
|
9
10
|
};
|
|
10
11
|
({}.__proto__.renderOption = (opt) => {
|
|
11
12
|
option = opt;
|
|
12
13
|
});
|
|
13
|
-
function
|
|
14
|
+
function renderz(val = {}) {
|
|
14
15
|
let result = "";
|
|
16
|
+
let status = option.prefix;
|
|
17
|
+
let status2 = option.prefixAttr;
|
|
15
18
|
try {
|
|
16
19
|
Object.entries(val).forEach((e) => {
|
|
17
20
|
if (Array.isArray(e[1])) {
|
|
18
21
|
e[1].forEach((g) => {
|
|
19
|
-
result +=
|
|
22
|
+
result += renderz({ [e[0]]: g });
|
|
20
23
|
});
|
|
21
24
|
} else if (typeof e[1] == "object") {
|
|
25
|
+
// if (e[1].noprefix == "true") option.prefix = false;
|
|
26
|
+
if (e[1].noprefix) option.prefix = false;
|
|
27
|
+
if (e[1].nopAttr) option.prefixAttr = false;
|
|
28
|
+
// console.log({ val: e[1], l: e[1].noprefix });
|
|
29
|
+
|
|
22
30
|
e[0] = e[0].replace(/\s/g, "");
|
|
23
|
-
|
|
31
|
+
if (!option.ignoreTag) {
|
|
32
|
+
e[0] = e[1].tag || e[0];
|
|
33
|
+
}
|
|
24
34
|
delete e[1].tag;
|
|
25
35
|
if (option.camelCase)
|
|
26
36
|
e[0] = e[0].replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
27
|
-
result += `<${e[0]}`;
|
|
37
|
+
result += `<${(option.prefix ? option.prefix : "") + e[0]}`;
|
|
28
38
|
const temp = [];
|
|
29
39
|
let inn = "";
|
|
30
40
|
Object.entries(e[1]).forEach((k) => {
|
|
31
|
-
if (
|
|
41
|
+
if (
|
|
42
|
+
typeof k[1] != "object" &&
|
|
43
|
+
k[0] != "text" &&
|
|
44
|
+
k[0] != "html" &&
|
|
45
|
+
k[0] != "noprefix" &&
|
|
46
|
+
k[0] != "nopAttr"
|
|
47
|
+
) {
|
|
32
48
|
if (option.camelCase)
|
|
33
|
-
|
|
34
|
-
result += ` ${
|
|
49
|
+
k[0] = k[0].replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
50
|
+
result += ` ${
|
|
51
|
+
(option.prefixAttr ? option.prefixAttr : "") + k[0]
|
|
52
|
+
}='${k[1].toString()}'`;
|
|
35
53
|
}
|
|
36
|
-
if (
|
|
54
|
+
if (
|
|
55
|
+
typeof k[1] == "function" &&
|
|
56
|
+
k[0] != "text" &&
|
|
57
|
+
k[0] != "html" &&
|
|
58
|
+
k[0] != "noprefix" &&
|
|
59
|
+
k[0] != "nopAttr"
|
|
60
|
+
) {
|
|
37
61
|
result += ` ${k[0]}='${(k[1] + "")
|
|
38
62
|
.replace(/.*{/, "")
|
|
39
63
|
.split("")
|
|
@@ -43,7 +67,7 @@ function render(val = {}) {
|
|
|
43
67
|
.split("")
|
|
44
68
|
.reverse()
|
|
45
69
|
.join("")}'`;
|
|
46
|
-
} else if (k[0] == "text")
|
|
70
|
+
} else if (k[0] == "text") {
|
|
47
71
|
inn = `${
|
|
48
72
|
typeof k[1] == "string"
|
|
49
73
|
? k[1]
|
|
@@ -54,7 +78,8 @@ function render(val = {}) {
|
|
|
54
78
|
.replace(/'/g, "'")
|
|
55
79
|
: k[1].toString()
|
|
56
80
|
}`;
|
|
57
|
-
|
|
81
|
+
temp.push(inn);
|
|
82
|
+
} else if (k[0] == "html") {
|
|
58
83
|
inn = `${
|
|
59
84
|
typeof k[1] != "function"
|
|
60
85
|
? k[1]
|
|
@@ -68,6 +93,7 @@ function render(val = {}) {
|
|
|
68
93
|
.reverse()
|
|
69
94
|
.join("")
|
|
70
95
|
}`;
|
|
96
|
+
temp.push(inn);
|
|
71
97
|
// typeof k[1] == "string" ? inn : inn.substring(0, inn.length - 1);
|
|
72
98
|
} else temp.push(k);
|
|
73
99
|
});
|
|
@@ -91,11 +117,11 @@ function render(val = {}) {
|
|
|
91
117
|
].includes(e[0]);
|
|
92
118
|
if (stat) {
|
|
93
119
|
result += ">";
|
|
94
|
-
result += inn;
|
|
120
|
+
// result += inn;
|
|
95
121
|
for (let i of temp) {
|
|
96
|
-
result +=
|
|
122
|
+
result += typeof i == "string" ? i : renderz({ [i[0]]: i[1] });
|
|
97
123
|
}
|
|
98
|
-
result += `</${e[0]}>`;
|
|
124
|
+
result += `</${(option.prefix ? option.prefix : "") + e[0]}>`;
|
|
99
125
|
} else {
|
|
100
126
|
if (!stat) result += "/>";
|
|
101
127
|
}
|
|
@@ -106,18 +132,20 @@ function render(val = {}) {
|
|
|
106
132
|
} catch (e) {
|
|
107
133
|
result = `<p>Error: ${e.message}</p>`;
|
|
108
134
|
}
|
|
135
|
+
option.prefixAttr = status2;
|
|
136
|
+
option.prefix = status;
|
|
109
137
|
return result;
|
|
110
138
|
}
|
|
111
139
|
function rdr(val = {}) {
|
|
112
140
|
let result = "<!DOCTYPE html>";
|
|
113
141
|
if (Array.isArray(val)) {
|
|
114
142
|
val.forEach((value) => {
|
|
115
|
-
result +=
|
|
143
|
+
result += renderz(value);
|
|
116
144
|
});
|
|
117
|
-
} else result =
|
|
145
|
+
} else result = renderz(val);
|
|
118
146
|
if (option.once)
|
|
119
147
|
option = {
|
|
120
|
-
camelCase: false,
|
|
148
|
+
// camelCase: false,
|
|
121
149
|
};
|
|
122
150
|
return result;
|
|
123
151
|
}
|
|
@@ -221,11 +249,9 @@ function fromStr(letter, prefix = 0) {
|
|
|
221
249
|
return temp;
|
|
222
250
|
}
|
|
223
251
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
Object.defineProperty({}.__proto__, d, {
|
|
252
|
+
Object.defineProperty({}.__proto__, "_render", {
|
|
227
253
|
get: function () {
|
|
228
|
-
return "<!DOCTYPE html>" + rdr(this);
|
|
254
|
+
return (option.nodoctype ? "" : "<!DOCTYPE html>") + rdr(this);
|
|
229
255
|
},
|
|
230
256
|
});
|
|
231
257
|
Object.defineProperty({}.__proto__, "reg", {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!-- @format -->
|
|
2
2
|
|
|
3
|
-
# Documentation Neobiz.js 4.
|
|
3
|
+
# Documentation Neobiz.js 4.5
|
|
4
4
|
|
|
5
5
|
> A simple view engine that has 100% JS features
|
|
6
6
|
|
|
@@ -8,12 +8,13 @@ Neobiz.js is pure in JS lang, transform Object into HTML
|
|
|
8
8
|
|
|
9
9
|
## Updates:
|
|
10
10
|
|
|
11
|
-
- `render` method
|
|
12
|
-
- render option props
|
|
11
|
+
- `render` method change to `**\_render**`to avoid conflict with another library and add safety check
|
|
12
|
+
- render option props improve
|
|
13
|
+
- fix bug on child order
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
features:
|
|
15
16
|
|
|
16
|
-
-
|
|
17
|
+
- eventHandler
|
|
17
18
|
- Reusable & editable style/css
|
|
18
19
|
- Altering object
|
|
19
20
|
- Registering component
|
|
@@ -60,26 +61,26 @@ const myComponent = {
|
|
|
60
61
|
data() {
|
|
61
62
|
return { msg: "hi, this is example" };
|
|
62
63
|
},
|
|
63
|
-
template: { h1: { text: "{{msg}}" } }.
|
|
64
|
+
template: { h1: { text: "{{msg}}" } }._render,
|
|
64
65
|
};
|
|
65
66
|
```
|
|
66
67
|
|
|
67
68
|
<br>
|
|
68
69
|
|
|
69
|
-
| properties
|
|
70
|
-
|
|
|
71
|
-
|
|
|
72
|
-
| outFile
|
|
73
|
-
| range
|
|
74
|
-
| repulse
|
|
75
|
-
| css
|
|
76
|
-
| cssText
|
|
77
|
-
| alter [trials]
|
|
78
|
-
| reg
|
|
79
|
-
| regm
|
|
80
|
-
| load
|
|
81
|
-
| unred
|
|
82
|
-
| renderOption
|
|
70
|
+
| properties | caller | return-type | description |
|
|
71
|
+
| -------------- | ------------------------------------- | ----------- | --------------------------------------- |
|
|
72
|
+
| \_render | Object | string | rendering to HTML |
|
|
73
|
+
| outFile | Object @params destination[string] | void | generate static HTML file |
|
|
74
|
+
| range | Array @params length[int], start[int] | Array | shortcut for looping in a range |
|
|
75
|
+
| repulse | String | Object | generate object from HTML string |
|
|
76
|
+
| css | Object | Object | generate css from object |
|
|
77
|
+
| cssText | Object | Object | inline css |
|
|
78
|
+
| alter [trials] | Object @params cb[function] | Object | altering object before rendering |
|
|
79
|
+
| reg | Object | void | registring an object |
|
|
80
|
+
| regm | Object | void | updating the existing registered object |
|
|
81
|
+
| load | Object | Object | read an existing registered object |
|
|
82
|
+
| unred | Object | void | removing an existing registered object |
|
|
83
|
+
| renderOption | Object @params option[Object] | void | set the option for rendering |
|
|
83
84
|
|
|
84
85
|
#### Why use this?
|
|
85
86
|
|
|
@@ -106,14 +107,14 @@ It's just an Object! `wrap in () to create a statement or just assign to a var`
|
|
|
106
107
|
h1: {
|
|
107
108
|
text: "Hello World!",
|
|
108
109
|
},
|
|
109
|
-
}.
|
|
110
|
+
}._render;
|
|
110
111
|
// <h1>Hello World!</h1>
|
|
111
112
|
```
|
|
112
113
|
|
|
113
114
|
or use call method
|
|
114
115
|
|
|
115
116
|
```js
|
|
116
|
-
|
|
117
|
+
_render.call({
|
|
117
118
|
// text property is same as innerText
|
|
118
119
|
h1: {
|
|
119
120
|
text: "Hello World!",
|
|
@@ -213,6 +214,10 @@ Object can not use 2 keys with the same name
|
|
|
213
214
|
renderOption({
|
|
214
215
|
camelCase: false,
|
|
215
216
|
once: false,
|
|
217
|
+
nodoctype: false,
|
|
218
|
+
ignoreTag: false,
|
|
219
|
+
prefixTag: false,
|
|
220
|
+
prefixAttr: false,
|
|
216
221
|
});
|
|
217
222
|
```
|
|
218
223
|
|
|
@@ -220,6 +225,24 @@ set once to `true` to use option only for once,
|
|
|
220
225
|
<br>
|
|
221
226
|
<br>
|
|
222
227
|
|
|
228
|
+
set nodoctype to `true` to remove `<!doctype html>` in the beninging,
|
|
229
|
+
<br>
|
|
230
|
+
<br>
|
|
231
|
+
|
|
232
|
+
set ignoreTag to `true` to unused `tag` properties,
|
|
233
|
+
<br>
|
|
234
|
+
<br>
|
|
235
|
+
|
|
236
|
+
set prefixTag to `something` to add text before `tag`,
|
|
237
|
+
<br>
|
|
238
|
+
use `noprefix:true` to skip on specific object
|
|
239
|
+
<br>
|
|
240
|
+
|
|
241
|
+
set prefixAttr to `something` to add text before `attribute`,
|
|
242
|
+
<br>
|
|
243
|
+
use `nopAttr:true` to skip in specific object
|
|
244
|
+
<br>
|
|
245
|
+
|
|
223
246
|
set `camelCase` `true` to convert **camelCase** properties to **kebab-case**
|
|
224
247
|
|
|
225
248
|
make sure to set the option before rendering
|