neobiz 4.3.11 → 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 +48 -20
- package/example/orderChild.v.js +15 -0
- package/package.json +1 -1
- package/readme.md +45 -22
package/browser.js
CHANGED
|
@@ -3,35 +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 (
|
|
32
|
-
|
|
41
|
+
if (
|
|
42
|
+
typeof k[1] != "object" &&
|
|
43
|
+
k[0] != "text" &&
|
|
44
|
+
k[0] != "html" &&
|
|
45
|
+
k[0] != "noprefix" &&
|
|
46
|
+
k[0] != "nopAttr"
|
|
47
|
+
) {
|
|
48
|
+
if (option.camelCase)
|
|
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()}'`;
|
|
33
53
|
}
|
|
34
|
-
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
|
+
) {
|
|
35
61
|
result += ` ${k[0]}='${(k[1] + "")
|
|
36
62
|
.replace(/.*{/, "")
|
|
37
63
|
.split("")
|
|
@@ -41,7 +67,7 @@ function render(val = {}) {
|
|
|
41
67
|
.split("")
|
|
42
68
|
.reverse()
|
|
43
69
|
.join("")}'`;
|
|
44
|
-
} else if (k[0] == "text")
|
|
70
|
+
} else if (k[0] == "text") {
|
|
45
71
|
inn = `${
|
|
46
72
|
typeof k[1] == "string"
|
|
47
73
|
? k[1]
|
|
@@ -52,7 +78,8 @@ function render(val = {}) {
|
|
|
52
78
|
.replace(/'/g, "'")
|
|
53
79
|
: k[1].toString()
|
|
54
80
|
}`;
|
|
55
|
-
|
|
81
|
+
temp.push(inn);
|
|
82
|
+
} else if (k[0] == "html") {
|
|
56
83
|
inn = `${
|
|
57
84
|
typeof k[1] != "function"
|
|
58
85
|
? k[1]
|
|
@@ -66,6 +93,7 @@ function render(val = {}) {
|
|
|
66
93
|
.reverse()
|
|
67
94
|
.join("")
|
|
68
95
|
}`;
|
|
96
|
+
temp.push(inn);
|
|
69
97
|
// typeof k[1] == "string" ? inn : inn.substring(0, inn.length - 1);
|
|
70
98
|
} else temp.push(k);
|
|
71
99
|
});
|
|
@@ -89,11 +117,11 @@ function render(val = {}) {
|
|
|
89
117
|
].includes(e[0]);
|
|
90
118
|
if (stat) {
|
|
91
119
|
result += ">";
|
|
92
|
-
result += inn;
|
|
120
|
+
// result += inn;
|
|
93
121
|
for (let i of temp) {
|
|
94
|
-
result +=
|
|
122
|
+
result += typeof i == "string" ? i : renderz({ [i[0]]: i[1] });
|
|
95
123
|
}
|
|
96
|
-
result += `</${e[0]}>`;
|
|
124
|
+
result += `</${(option.prefix ? option.prefix : "") + e[0]}>`;
|
|
97
125
|
} else {
|
|
98
126
|
if (!stat) result += "/>";
|
|
99
127
|
}
|
|
@@ -104,18 +132,20 @@ function render(val = {}) {
|
|
|
104
132
|
} catch (e) {
|
|
105
133
|
result = `<p>Error: ${e.message}</p>`;
|
|
106
134
|
}
|
|
135
|
+
option.prefixAttr = status2;
|
|
136
|
+
option.prefix = status;
|
|
107
137
|
return result;
|
|
108
138
|
}
|
|
109
139
|
function rdr(val = {}) {
|
|
110
140
|
let result = "<!DOCTYPE html>";
|
|
111
141
|
if (Array.isArray(val)) {
|
|
112
142
|
val.forEach((value) => {
|
|
113
|
-
result +=
|
|
143
|
+
result += renderz(value);
|
|
114
144
|
});
|
|
115
|
-
} else result =
|
|
145
|
+
} else result = renderz(val);
|
|
116
146
|
if (option.once)
|
|
117
147
|
option = {
|
|
118
|
-
camelCase: false,
|
|
148
|
+
// camelCase: false,
|
|
119
149
|
};
|
|
120
150
|
return result;
|
|
121
151
|
}
|
|
@@ -219,11 +249,9 @@ function fromStr(letter, prefix = 0) {
|
|
|
219
249
|
return temp;
|
|
220
250
|
}
|
|
221
251
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
Object.defineProperty({}.__proto__, d, {
|
|
252
|
+
Object.defineProperty({}.__proto__, "_render", {
|
|
225
253
|
get: function () {
|
|
226
|
-
return "<!DOCTYPE html>" + rdr(this);
|
|
254
|
+
return (option.nodoctype ? "" : "<!DOCTYPE html>") + rdr(this);
|
|
227
255
|
},
|
|
228
256
|
});
|
|
229
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
|