neobiz 3.8.1 → 4.1.15
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 +27 -0
- package/example/basic_syntax.v.js +1 -1
- package/example/explicit-tag.v..js +16 -0
- package/example/register.v.js +20 -0
- package/package.json +1 -1
- package/readme.md +111 -15
package/browser.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/** @format */
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
|
+
|
|
5
|
+
const adp = {};
|
|
6
|
+
|
|
4
7
|
function render(val = {}) {
|
|
5
8
|
let result = "";
|
|
6
9
|
try {
|
|
@@ -11,6 +14,8 @@ function render(val = {}) {
|
|
|
11
14
|
});
|
|
12
15
|
} else if (typeof e[1] == "object") {
|
|
13
16
|
e[0] = e[0].replace(/\s/g, "");
|
|
17
|
+
e[0] = e[1].tag || e[0];
|
|
18
|
+
delete e[1].tag;
|
|
14
19
|
result += `<${e[0]}`;
|
|
15
20
|
const temp = [];
|
|
16
21
|
let inn = "";
|
|
@@ -207,6 +212,28 @@ Object.defineProperty({}.__proto__, "render", {
|
|
|
207
212
|
return "<!DOCTYPE html>" + rdr(this);
|
|
208
213
|
},
|
|
209
214
|
});
|
|
215
|
+
Object.defineProperty({}.__proto__, "reg", {
|
|
216
|
+
value: function (name) {
|
|
217
|
+
const val = this;
|
|
218
|
+
if (!adp[name]) adp[name] = val;
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
Object.defineProperty({}.__proto__, "regm", {
|
|
222
|
+
value: function (name) {
|
|
223
|
+
const val = this;
|
|
224
|
+
if (adp[name]) adp[name] = val;
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
Object.defineProperty({}.__proto__, "unreg", {
|
|
228
|
+
value: function (name) {
|
|
229
|
+
delete adp[name];
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
Object.defineProperty({}.__proto__, "load", {
|
|
233
|
+
value: function (component) {
|
|
234
|
+
return adp[component] || "not registered";
|
|
235
|
+
},
|
|
236
|
+
});
|
|
210
237
|
Object.defineProperty({}.__proto__, "css", {
|
|
211
238
|
get: function () {
|
|
212
239
|
let y = "";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @format */
|
|
2
|
+
|
|
3
|
+
import "../index.js";
|
|
4
|
+
|
|
5
|
+
console.log(
|
|
6
|
+
{ li: [{ text: "one" }, { tag: "p", text: "two" }, { text: "three" }] }.render
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
console.log(
|
|
10
|
+
{
|
|
11
|
+
PersonList: ["Arthur", "Zoro"].map((person) => ({
|
|
12
|
+
tag: "li",
|
|
13
|
+
text: person,
|
|
14
|
+
})),
|
|
15
|
+
}.render
|
|
16
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** @format */
|
|
2
|
+
|
|
3
|
+
import "../index.js";
|
|
4
|
+
|
|
5
|
+
reg.call({ name: "viewport" }, "viewport");
|
|
6
|
+
|
|
7
|
+
console.log(load("viewport"));
|
|
8
|
+
|
|
9
|
+
regm.call(
|
|
10
|
+
load("viewport").alter((o) => {
|
|
11
|
+
o.content = "width=device-width, initial-scale=1.0";
|
|
12
|
+
}),
|
|
13
|
+
"viewport"
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
console.log(load("viewport"));
|
|
17
|
+
|
|
18
|
+
unreg("viewport");
|
|
19
|
+
|
|
20
|
+
console.log(load("viewport"));
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!-- @format -->
|
|
2
2
|
|
|
3
|
-
# Documentation Neobiz.js
|
|
3
|
+
# Documentation Neobiz.js 4.1.15
|
|
4
4
|
|
|
5
5
|
> A simple view engine that has 100% JS features
|
|
6
6
|
|
|
@@ -8,11 +8,15 @@ Neobiz.js is pure in JS lang, transform Object into HTML
|
|
|
8
8
|
|
|
9
9
|
new features:
|
|
10
10
|
|
|
11
|
-
-
|
|
12
|
-
- style/css
|
|
13
|
-
-
|
|
11
|
+
- Sanitized eventHandler
|
|
12
|
+
- Reusable & editable style/css
|
|
13
|
+
- Altering object
|
|
14
|
+
- Registering component
|
|
15
|
+
- Explicit tag name supported
|
|
14
16
|
|
|
15
|
-
`read /example dir to understanding`
|
|
17
|
+
`read /example dir to better understanding`
|
|
18
|
+
|
|
19
|
+
for browser usage use `browser.js` file.
|
|
16
20
|
|
|
17
21
|
[link to usage in express.js](https://www.npmjs.com/package/neobiz-express?activeTab=dependencies)
|
|
18
22
|
|
|
@@ -57,15 +61,19 @@ const myComponent = {
|
|
|
57
61
|
|
|
58
62
|
<br>
|
|
59
63
|
|
|
60
|
-
| properties
|
|
61
|
-
|
|
|
62
|
-
| render
|
|
63
|
-
| outFile
|
|
64
|
-
| range
|
|
65
|
-
| repulse
|
|
66
|
-
| css
|
|
67
|
-
| cssText
|
|
68
|
-
| alter
|
|
64
|
+
| properties | caller | return-type | description |
|
|
65
|
+
| -------------- | ------------------------------------- | -------------------------------------- | --------------------------------------- |
|
|
66
|
+
| render | Object | string | rendering to HTML |
|
|
67
|
+
| outFile | Object @params destination[string] | void | generate static HTML file |
|
|
68
|
+
| range | Array @params length[int], start[int] | Array | shortcut for looping in a range |
|
|
69
|
+
| repulse | String | Object | generate object from HTML string |
|
|
70
|
+
| css | Object | Object | generate css from object |
|
|
71
|
+
| cssText | Object | Object | inline css |
|
|
72
|
+
| alter [trials] | Object @params cb[function] | Object | altering object before rendering |
|
|
73
|
+
| reg | Object | void | registring an object |
|
|
74
|
+
| regm | Object | void | updating the existing registered object |
|
|
75
|
+
| load | Object | Object | read an existing registered object |
|
|
76
|
+
| unred | Object void | removing an existing registered object |
|
|
69
77
|
|
|
70
78
|
#### Why use this?
|
|
71
79
|
|
|
@@ -182,6 +190,8 @@ Object can not use 2 keys with the same name
|
|
|
182
190
|
}
|
|
183
191
|
```
|
|
184
192
|
|
|
193
|
+
## Explicit tag name
|
|
194
|
+
|
|
185
195
|
What if there is somethings in the middle of list?
|
|
186
196
|
|
|
187
197
|
```html
|
|
@@ -192,7 +202,7 @@ What if there is somethings in the middle of list?
|
|
|
192
202
|
<li>banana</li>
|
|
193
203
|
```
|
|
194
204
|
|
|
195
|
-
|
|
205
|
+
if we use an array there will share the tag name right? just use this:
|
|
196
206
|
|
|
197
207
|
> use string as key could distinc an element with just a space
|
|
198
208
|
> no need to worry, it will render without space
|
|
@@ -205,6 +215,29 @@ Can't use array? just use this:
|
|
|
205
215
|
}
|
|
206
216
|
```
|
|
207
217
|
|
|
218
|
+
or write the tag name:
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
{
|
|
222
|
+
li: [
|
|
223
|
+
{ text: "orange" },
|
|
224
|
+
{ tag: "p", span: { text: "This is in the middle" } },
|
|
225
|
+
{ text: "banana" },
|
|
226
|
+
],
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
also with specifying tag name, we can name it differently:
|
|
231
|
+
|
|
232
|
+
```js
|
|
233
|
+
{
|
|
234
|
+
PersonList: ["Arthur", "Zoro"].map((person) => ({
|
|
235
|
+
tag: "li",
|
|
236
|
+
text: person,
|
|
237
|
+
})),
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
208
241
|
### Modify an Object
|
|
209
242
|
|
|
210
243
|
use `alter` properties, with function as params. no need to return a value
|
|
@@ -249,6 +282,57 @@ export default {
|
|
|
249
282
|
};
|
|
250
283
|
```
|
|
251
284
|
|
|
285
|
+
### reg, regm, load & unreg Components
|
|
286
|
+
|
|
287
|
+
The idea is to make object has resuability
|
|
288
|
+
|
|
289
|
+
#### reg & load
|
|
290
|
+
|
|
291
|
+
> this function need a single argument to set a name of registering object,
|
|
292
|
+
|
|
293
|
+
there is 2 ways to registering an component:
|
|
294
|
+
|
|
295
|
+
- through properties method:
|
|
296
|
+
|
|
297
|
+
```js
|
|
298
|
+
{ name:"viewport"}.reg("viewport")
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
- via call method:
|
|
302
|
+
|
|
303
|
+
```js
|
|
304
|
+
reg.call({ name: "viewport" }, "viewport");
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
now we can load it's value whenever we want
|
|
308
|
+
|
|
309
|
+
```js
|
|
310
|
+
{
|
|
311
|
+
meta:load("viewport"),
|
|
312
|
+
body: {
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
#### regm
|
|
318
|
+
|
|
319
|
+
this function will replace an existing registered object with a new value:
|
|
320
|
+
|
|
321
|
+
```js
|
|
322
|
+
const newValue = load("viewport");
|
|
323
|
+
newValue.content = "width=device-width, initial-scale=1.0";
|
|
324
|
+
|
|
325
|
+
newValue.regm("viewport");
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
#### unreg
|
|
329
|
+
|
|
330
|
+
when we the object doesn't needed anymore, just unreg it:
|
|
331
|
+
|
|
332
|
+
```js
|
|
333
|
+
unreg("viewport");
|
|
334
|
+
```
|
|
335
|
+
|
|
252
336
|
### Style
|
|
253
337
|
|
|
254
338
|
use camel case to css properties
|
|
@@ -501,6 +585,16 @@ map
|
|
|
501
585
|
}
|
|
502
586
|
```
|
|
503
587
|
|
|
588
|
+
filter
|
|
589
|
+
|
|
590
|
+
```js
|
|
591
|
+
{
|
|
592
|
+
ul: {
|
|
593
|
+
li: [].range(8, 1).filter( num => num % 2 == 0 ).map((item) => ({ text: "data-" + item })),
|
|
594
|
+
},
|
|
595
|
+
}
|
|
596
|
+
```
|
|
597
|
+
|
|
504
598
|
for
|
|
505
599
|
|
|
506
600
|
```js
|
|
@@ -548,3 +642,5 @@ template({
|
|
|
548
642
|
h1: { text: "Hello World!" },
|
|
549
643
|
});
|
|
550
644
|
```
|
|
645
|
+
|
|
646
|
+
### Thank you for read until here.
|