neobiz 3.3.0 → 4.1.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/browser.js +32 -3
- package/example/basic_syntax.v.js +1 -1
- package/example/explicit-tag.v..js +16 -0
- package/example/register.v.js +20 -0
- package/example/style.v.js +28 -0
- package/package.json +4 -2
- package/readme.md +169 -13
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 = "";
|
|
@@ -235,9 +262,11 @@ Object.defineProperty({}.__proto__, "cssText", {
|
|
|
235
262
|
return y;
|
|
236
263
|
},
|
|
237
264
|
});
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
265
|
+
|
|
266
|
+
Object.defineProperty({}.__proto__, "alter", {
|
|
267
|
+
value: function (fn) {
|
|
268
|
+
fn(this);
|
|
269
|
+
return this;
|
|
241
270
|
},
|
|
242
271
|
});
|
|
243
272
|
|
|
@@ -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"));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** @format */
|
|
2
|
+
|
|
3
|
+
import "../index.js";
|
|
4
|
+
|
|
5
|
+
// inline
|
|
6
|
+
console.log(
|
|
7
|
+
{
|
|
8
|
+
h1: {
|
|
9
|
+
text: "this is text",
|
|
10
|
+
style: { color: "blue", fontSize: "140%" }.cssText,
|
|
11
|
+
},
|
|
12
|
+
}.render
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
// tag style
|
|
16
|
+
console.log(
|
|
17
|
+
{
|
|
18
|
+
style: {
|
|
19
|
+
h1: {
|
|
20
|
+
// something
|
|
21
|
+
},
|
|
22
|
+
body: {
|
|
23
|
+
margin: "0px",
|
|
24
|
+
padding: "0px",
|
|
25
|
+
},
|
|
26
|
+
}.css,
|
|
27
|
+
}.render
|
|
28
|
+
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "neobiz",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.14",
|
|
4
4
|
"description": "A simple view engine with JS features",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
"template",
|
|
12
12
|
"dom",
|
|
13
13
|
"html",
|
|
14
|
-
"express"
|
|
14
|
+
"express",
|
|
15
|
+
"front-end",
|
|
16
|
+
"layout"
|
|
15
17
|
],
|
|
16
18
|
"license": "MIT"
|
|
17
19
|
}
|
package/readme.md
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
<!-- @format -->
|
|
2
2
|
|
|
3
|
-
# Documentation Neobiz.js
|
|
3
|
+
# Documentation Neobiz.js 4.1.14
|
|
4
4
|
|
|
5
5
|
> A simple view engine that has 100% JS features
|
|
6
6
|
|
|
7
7
|
Neobiz.js is pure in JS lang, transform Object into HTML
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
new features:
|
|
10
|
+
|
|
11
|
+
- Sanitized eventHandler
|
|
12
|
+
- Reusable & editable style/css
|
|
13
|
+
- Altering object
|
|
14
|
+
- Registering component
|
|
15
|
+
- Explicit tag name supported
|
|
16
|
+
|
|
17
|
+
`read /example dir to better understanding`
|
|
18
|
+
|
|
19
|
+
for browser usage use `browser.js` file.
|
|
10
20
|
|
|
11
21
|
[link to usage in express.js](https://www.npmjs.com/package/neobiz-express?activeTab=dependencies)
|
|
12
22
|
|
|
@@ -29,7 +39,7 @@ import "neobiz";
|
|
|
29
39
|
id: "app",
|
|
30
40
|
},
|
|
31
41
|
script: {
|
|
32
|
-
html
|
|
42
|
+
html() {
|
|
33
43
|
const { createApp } = Vue;
|
|
34
44
|
|
|
35
45
|
createApp(myComponent).mount("#app");
|
|
@@ -51,14 +61,19 @@ const myComponent = {
|
|
|
51
61
|
|
|
52
62
|
<br>
|
|
53
63
|
|
|
54
|
-
| properties
|
|
55
|
-
|
|
|
56
|
-
| render
|
|
57
|
-
| outFile
|
|
58
|
-
| range
|
|
59
|
-
| repulse
|
|
60
|
-
| css
|
|
61
|
-
| cssText
|
|
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 |
|
|
62
77
|
|
|
63
78
|
#### Why use this?
|
|
64
79
|
|
|
@@ -175,6 +190,8 @@ Object can not use 2 keys with the same name
|
|
|
175
190
|
}
|
|
176
191
|
```
|
|
177
192
|
|
|
193
|
+
## Explicit tag name
|
|
194
|
+
|
|
178
195
|
What if there is somethings in the middle of list?
|
|
179
196
|
|
|
180
197
|
```html
|
|
@@ -185,7 +202,7 @@ What if there is somethings in the middle of list?
|
|
|
185
202
|
<li>banana</li>
|
|
186
203
|
```
|
|
187
204
|
|
|
188
|
-
|
|
205
|
+
if we use an array there will share the tag name right? just use this:
|
|
189
206
|
|
|
190
207
|
> use string as key could distinc an element with just a space
|
|
191
208
|
> no need to worry, it will render without space
|
|
@@ -198,6 +215,45 @@ Can't use array? just use this:
|
|
|
198
215
|
}
|
|
199
216
|
```
|
|
200
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
|
+
|
|
241
|
+
### Modify an Object
|
|
242
|
+
|
|
243
|
+
use `alter` properties, with function as params. no need to return a value
|
|
244
|
+
|
|
245
|
+
```js
|
|
246
|
+
const y = {
|
|
247
|
+
h1: { text: "Hello World!" },
|
|
248
|
+
p: { text: "this is a p" }.alter((e) => (e.class = "lorem")),
|
|
249
|
+
}.alter((e) => {
|
|
250
|
+
e.h1.text = "thi is altered text";
|
|
251
|
+
e.h1.style = { color: "red", fontSize: "150%" }.cssText;
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
console.log(y.render);
|
|
255
|
+
```
|
|
256
|
+
|
|
201
257
|
### Components / Partials
|
|
202
258
|
|
|
203
259
|
```js
|
|
@@ -226,6 +282,57 @@ export default {
|
|
|
226
282
|
};
|
|
227
283
|
```
|
|
228
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({ 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
|
+
|
|
229
336
|
### Style
|
|
230
337
|
|
|
231
338
|
use camel case to css properties
|
|
@@ -279,6 +386,27 @@ style.body.margin = "12px";
|
|
|
279
386
|
}.render
|
|
280
387
|
```
|
|
281
388
|
|
|
389
|
+
reusable style / mixin
|
|
390
|
+
|
|
391
|
+
```js
|
|
392
|
+
const flex = (justify, align, direction = "row") => ({
|
|
393
|
+
display: "flex",
|
|
394
|
+
justifyContent: justify,
|
|
395
|
+
alignItems: align,
|
|
396
|
+
flexDirection: direction,
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
const space = {
|
|
400
|
+
padding: "6px 8px",
|
|
401
|
+
margin: "6px 10px",
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
console.log({
|
|
405
|
+
style: { div: flex("center", "center"), button: { border: "none", ...space } }
|
|
406
|
+
.css,
|
|
407
|
+
});
|
|
408
|
+
```
|
|
409
|
+
|
|
282
410
|
### Interacting with DOM
|
|
283
411
|
|
|
284
412
|
use `script` to interact with browser with **html** property
|
|
@@ -354,7 +482,7 @@ result
|
|
|
354
482
|
|
|
355
483
|
## Pass Value
|
|
356
484
|
|
|
357
|
-
use function
|
|
485
|
+
use shorthand anonym function
|
|
358
486
|
|
|
359
487
|
```js
|
|
360
488
|
console.log(((user) => ({ h1: { text: `Hello, ${user}` } }))("Vins").render);
|
|
@@ -398,6 +526,22 @@ IIFE if-else
|
|
|
398
526
|
}
|
|
399
527
|
```
|
|
400
528
|
|
|
529
|
+
normal if else
|
|
530
|
+
|
|
531
|
+
```js
|
|
532
|
+
let result;
|
|
533
|
+
if (status) result = { text: "Hello World!" };
|
|
534
|
+
else
|
|
535
|
+
result = {
|
|
536
|
+
a: { href: "#", text: "You are offline!" },
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
//use
|
|
540
|
+
{
|
|
541
|
+
h1: result,
|
|
542
|
+
}
|
|
543
|
+
```
|
|
544
|
+
|
|
401
545
|
IIFE switch-case
|
|
402
546
|
|
|
403
547
|
```js
|
|
@@ -441,6 +585,16 @@ map
|
|
|
441
585
|
}
|
|
442
586
|
```
|
|
443
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
|
+
|
|
444
598
|
for
|
|
445
599
|
|
|
446
600
|
```js
|
|
@@ -488,3 +642,5 @@ template({
|
|
|
488
642
|
h1: { text: "Hello World!" },
|
|
489
643
|
});
|
|
490
644
|
```
|
|
645
|
+
|
|
646
|
+
### Thank you for read until here.
|