neobiz 1.2.2 → 1.2.4
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/example/basic_syntax.v.js +5 -0
- package/example/innerText&html.v.js +15 -0
- package/index.js +10 -3
- package/package.json +1 -1
- package/readme.md +22 -14
- package/example/basic.html +0 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** @format */
|
|
2
|
+
|
|
3
|
+
import { outFile, render } from "../index.js";
|
|
4
|
+
|
|
5
|
+
console.log(
|
|
6
|
+
render({
|
|
7
|
+
h1: { text: "Hello World!<b>this is text</b>" },
|
|
8
|
+
ul: { html: "<li>Text hello</li>" },
|
|
9
|
+
})
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
outFile("./select.html", {
|
|
13
|
+
h1: { text: "Hello World! <b>this is \"text\"&'blue'</b>" },
|
|
14
|
+
ul: { html: "<li>Text hello</li>" },
|
|
15
|
+
});
|
package/index.js
CHANGED
|
@@ -15,10 +15,17 @@ function render(val = {}) {
|
|
|
15
15
|
const temp = [];
|
|
16
16
|
let inn = "";
|
|
17
17
|
Object.entries(e[1]).forEach((k) => {
|
|
18
|
-
if (typeof k[1] == "string" && k[0] != "text")
|
|
18
|
+
if (typeof k[1] == "string" && k[0] != "text" && k[0] != "html")
|
|
19
19
|
result += ` ${k[0]}='${k[1]}'`;
|
|
20
|
-
else if (typeof k[1] == "function") result += ` ${k[0]}='${k[1] + ""}'`;
|
|
21
|
-
else if (k[0] == "text")
|
|
20
|
+
// else if (typeof k[1] == "function") result += ` ${k[0]}='${k[1] + ""}'`;
|
|
21
|
+
else if (k[0] == "text")
|
|
22
|
+
inn = `${k[1]
|
|
23
|
+
.replace(/&/g, "&")
|
|
24
|
+
.replace(/</g, "<")
|
|
25
|
+
.replace(/>/g, ">")
|
|
26
|
+
.replace(/"/g, """)
|
|
27
|
+
.replace(/'/g, "'")}`;
|
|
28
|
+
else if (k[0] == "html") inn = `${k[1]}`;
|
|
22
29
|
else temp.push(k);
|
|
23
30
|
});
|
|
24
31
|
const stat = !["input", "link", "br", "hr"].includes(e[0]);
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
> A simple view engine that has 100% JS features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
[Github](https://www.npmjs.com/package/neobiz-express?activeTab=dependencies)
|
|
8
|
+
Neobiz.js is pure in JS lang, transform Object into HTML
|
|
8
9
|
|
|
9
10
|
`read /example dir to understanding`
|
|
10
11
|
|
|
@@ -15,29 +16,28 @@ Neobiz.js is pure JS lang, transpile Object to HTML as string
|
|
|
15
16
|
| function | params | return-type | description |
|
|
16
17
|
| -------- | ---------------------------------- | ----------- | ------------------------------- |
|
|
17
18
|
| render | content:object | string | rendering to HTML |
|
|
18
|
-
| outFile | destination:string, content:object |
|
|
19
|
+
| outFile | destination:string, content:object | void | generate static HTML file |
|
|
19
20
|
| range | length:int, start:int | Array | shortcut for looping in a range |
|
|
20
21
|
| partial | source:string | AsyncFn | including other file |
|
|
21
22
|
|
|
22
23
|
#### Why use this?
|
|
23
24
|
|
|
24
|
-
- One lang for all,
|
|
25
|
+
- One lang for all, back end - view - browser script all js!
|
|
25
26
|
- **directly** interact data or Model with a view
|
|
26
|
-
-
|
|
27
|
+
- Generate static html file
|
|
27
28
|
- Full control of serving the view. Such as encrypting the data before serve, or just like conditional and loop case
|
|
28
29
|
- Almost no need to learn anything. Just need to learn how to render
|
|
29
30
|
- Limitless potential, because it's just js. Almost all library should be compatible
|
|
30
|
-
- Just like JSON replace XML
|
|
31
31
|
|
|
32
32
|
## Basic syntax
|
|
33
33
|
|
|
34
|
-
It's just Object
|
|
34
|
+
It's just an Object!
|
|
35
35
|
|
|
36
36
|
```js
|
|
37
37
|
{
|
|
38
38
|
// text property is same as innerHTML
|
|
39
39
|
h1: {
|
|
40
|
-
text: "Hello World!"
|
|
40
|
+
text: "Hello World!",
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
// <h1>Hello World!</h1>
|
|
@@ -47,23 +47,31 @@ properties dom
|
|
|
47
47
|
|
|
48
48
|
```js
|
|
49
49
|
{
|
|
50
|
-
// text property is same as innerHTML
|
|
51
50
|
h1: {
|
|
52
51
|
class:"heading",
|
|
53
52
|
text: "Hello World!",
|
|
54
|
-
style:"color: #DC1E1E"
|
|
53
|
+
style:"color: #DC1E1E",
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
// <h1 class="heading" style="color: #DC1E1E">Hello World!</h1>
|
|
58
57
|
```
|
|
59
58
|
|
|
59
|
+
innerText & innerHTML:
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
{
|
|
63
|
+
h1: { text: "<b>this is a text</b>" },
|
|
64
|
+
ul: { html: "<li>this will be render as html</li>" },
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
60
68
|
nested dom:
|
|
61
69
|
|
|
62
70
|
```js
|
|
63
71
|
{
|
|
64
72
|
body: {
|
|
65
73
|
h1: {
|
|
66
|
-
text: "Hello World!"
|
|
74
|
+
text: "Hello World!",
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
77
|
}
|
|
@@ -78,7 +86,7 @@ There is a case like this:
|
|
|
78
86
|
<li>banana</li>
|
|
79
87
|
```
|
|
80
88
|
|
|
81
|
-
Object can not use 2 keys with same name, instead use this:
|
|
89
|
+
Object can not use 2 keys with the same name, instead use this:
|
|
82
90
|
|
|
83
91
|
```js
|
|
84
92
|
// Don't do this
|
|
@@ -108,13 +116,13 @@ What if there is somethings in the middle of list?
|
|
|
108
116
|
|
|
109
117
|
Can't use array? just use this:
|
|
110
118
|
|
|
111
|
-
> use string as key could distinc element just
|
|
119
|
+
> use string as key could distinc an element with just a space
|
|
112
120
|
> no need to worry, it will render without space
|
|
113
121
|
|
|
114
122
|
```js
|
|
115
123
|
{
|
|
116
124
|
li:{text:"orange"},
|
|
117
|
-
p:{span:{text:"This is in the middle"}}
|
|
125
|
+
p:{span:{text:"This is in the middle"}},
|
|
118
126
|
"li ":{text:"banana"},
|
|
119
127
|
}
|
|
120
128
|
```
|
|
@@ -263,7 +271,7 @@ export default (title) => ({ title: { text: title } });
|
|
|
263
271
|
|
|
264
272
|
### templating
|
|
265
273
|
|
|
266
|
-
this example use single file usage. for modular usage leave to you
|
|
274
|
+
this example use single file usage. for modular usage leave to you, or just read the example dir
|
|
267
275
|
|
|
268
276
|
```js
|
|
269
277
|
import { render } from "../index.js";
|
package/example/basic.html
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<h1>Hello World!</h1>
|