neobiz 1.2.4 → 1.2.5
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/interact_withDOM.v.js +16 -0
- package/index.js +17 -8
- package/package.json +5 -2
- package/readme.md +69 -8
- package/minify.js +0 -11
- package/neobiz.min.js +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @format */
|
|
2
|
+
|
|
3
|
+
import { outFile } from "../index.js";
|
|
4
|
+
|
|
5
|
+
outFile("./temp.html", {
|
|
6
|
+
button: { onclick: "sayHi(this)", id: "example" },
|
|
7
|
+
script: {
|
|
8
|
+
html: function () {
|
|
9
|
+
document.getElementById("example").innerText = "click me!";
|
|
10
|
+
|
|
11
|
+
function sayHi(el) {
|
|
12
|
+
el.innerText = "hi!";
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
});
|
package/index.js
CHANGED
|
@@ -19,14 +19,23 @@ function render(val = {}) {
|
|
|
19
19
|
result += ` ${k[0]}='${k[1]}'`;
|
|
20
20
|
// else if (typeof k[1] == "function") result += ` ${k[0]}='${k[1] + ""}'`;
|
|
21
21
|
else if (k[0] == "text")
|
|
22
|
-
inn = `${
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
inn = `${
|
|
23
|
+
typeof k[1] == "string"
|
|
24
|
+
? k[1]
|
|
25
|
+
.replace(/&/g, "&")
|
|
26
|
+
.replace(/</g, "<")
|
|
27
|
+
.replace(/>/g, ">")
|
|
28
|
+
.replace(/"/g, """)
|
|
29
|
+
.replace(/'/g, "'")
|
|
30
|
+
: k[1].toString()
|
|
31
|
+
}`;
|
|
32
|
+
else if (k[0] == "html") {
|
|
33
|
+
inn = `${
|
|
34
|
+
typeof k[1] != "function" ? k[1] : (k[1] + "").replace(/.*{/, "")
|
|
35
|
+
}`;
|
|
36
|
+
inn =
|
|
37
|
+
typeof k[1] == "string" ? inn : inn.substring(0, inn.length - 1);
|
|
38
|
+
} else temp.push(k);
|
|
30
39
|
});
|
|
31
40
|
const stat = !["input", "link", "br", "hr"].includes(e[0]);
|
|
32
41
|
if (stat) result += ">";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "neobiz",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "simple view engine yet powerful with javascript features",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
10
|
"view engine",
|
|
11
|
-
"template
|
|
11
|
+
"template",
|
|
12
|
+
"dom",
|
|
13
|
+
"html",
|
|
14
|
+
"",
|
|
12
15
|
"view"
|
|
13
16
|
],
|
|
14
17
|
"license": "ISC"
|
package/readme.md
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
> A simple view engine that has 100% JS features
|
|
6
6
|
|
|
7
|
-
[Github](https://
|
|
7
|
+
[[Github]](https://github.com/harakun24/neobiz.js)
|
|
8
8
|
Neobiz.js is pure in JS lang, transform Object into HTML
|
|
9
9
|
|
|
10
10
|
`read /example dir to understanding`
|
|
11
11
|
|
|
12
|
-
[
|
|
12
|
+
[link to usage in express.js](https://www.npmjs.com/package/neobiz-express?activeTab=dependencies)
|
|
13
13
|
|
|
14
|
-
**
|
|
14
|
+
**Function**
|
|
15
15
|
|
|
16
16
|
| function | params | return-type | description |
|
|
17
17
|
| -------- | ---------------------------------- | ----------- | ------------------------------- |
|
|
@@ -22,10 +22,10 @@ Neobiz.js is pure in JS lang, transform Object into HTML
|
|
|
22
22
|
|
|
23
23
|
#### Why use this?
|
|
24
24
|
|
|
25
|
-
-
|
|
26
|
-
- **directly**
|
|
25
|
+
- Integrating back-end to view
|
|
26
|
+
- **directly** manipulation data or Model with a view
|
|
27
27
|
- Generate static html file
|
|
28
|
-
- Full control of
|
|
28
|
+
- Full control of view. Such as filtering, encrypting the data before serve, or just like conditional and loop case
|
|
29
29
|
- Almost no need to learn anything. Just need to learn how to render
|
|
30
30
|
- Limitless potential, because it's just js. Almost all library should be compatible
|
|
31
31
|
|
|
@@ -35,7 +35,7 @@ It's just an Object!
|
|
|
35
35
|
|
|
36
36
|
```js
|
|
37
37
|
{
|
|
38
|
-
// text property is same as
|
|
38
|
+
// text property is same as innerText
|
|
39
39
|
h1: {
|
|
40
40
|
text: "Hello World!",
|
|
41
41
|
}
|
|
@@ -77,6 +77,17 @@ nested dom:
|
|
|
77
77
|
}
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
expression & operator
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
{
|
|
84
|
+
span: [
|
|
85
|
+
{ text: 24 + 12 / 6 },
|
|
86
|
+
{ text: !false },
|
|
87
|
+
],
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
80
91
|
siblings dom:
|
|
81
92
|
|
|
82
93
|
There is a case like this:
|
|
@@ -86,7 +97,7 @@ There is a case like this:
|
|
|
86
97
|
<li>banana</li>
|
|
87
98
|
```
|
|
88
99
|
|
|
89
|
-
Object can not use 2 keys with the same name
|
|
100
|
+
Object can not use 2 keys with the same name
|
|
90
101
|
|
|
91
102
|
```js
|
|
92
103
|
// Don't do this
|
|
@@ -127,6 +138,56 @@ Can't use array? just use this:
|
|
|
127
138
|
}
|
|
128
139
|
```
|
|
129
140
|
|
|
141
|
+
### Components
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
import header from "./header.v.js"; //function type
|
|
145
|
+
import footer from "./footer.v.js"; //object type
|
|
146
|
+
|
|
147
|
+
render({
|
|
148
|
+
div: header({ user: "dim24" }),
|
|
149
|
+
p: { text: "this is text" },
|
|
150
|
+
div: footer,
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
header.v.js
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
export default ({ user }) => ({ h1: { text: `Hi, ${user}` } });
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
footer.v.js
|
|
161
|
+
|
|
162
|
+
```js
|
|
163
|
+
export default {
|
|
164
|
+
script: { src: "/assets/js/main.js" },
|
|
165
|
+
span: { text: "this is footer" },
|
|
166
|
+
};
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Interacting with DOM
|
|
170
|
+
|
|
171
|
+
use `script` to interact with browser with **html** property
|
|
172
|
+
|
|
173
|
+
wrap the script with a function, or use string
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
{
|
|
177
|
+
button:{onclick:"sayHi(this)",id:"hi-button"},
|
|
178
|
+
script:{
|
|
179
|
+
html:()=>{
|
|
180
|
+
document.getElementById("hi-button").innerText="Click me!";
|
|
181
|
+
|
|
182
|
+
function sayHi(el){
|
|
183
|
+
el.innerText="Hi!";
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
|
|
130
191
|
## Pass Value
|
|
131
192
|
|
|
132
193
|
use function
|
package/minify.js
DELETED
package/neobiz.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/** @format */"use strict";const path = require("path");function render(val = {}) { let result = ""; Object.entries(val).forEach((e) => { if (e[1].length) { e[1].forEach((g) => { result += render({ [e[0]]: g }); }); } else if (typeof e[1] == "object") { e[0] = e[0].replace(" ", ""); result += `<${e[0]}`; const temp = []; let inn = ""; Object.entries(e[1]).forEach((k) => { if (typeof k[1] == "string" && k[0] != "text") result += ` ${k[0]}='${k[1]}'`; else if (typeof k[1] == "function") result += ` ${k[0]}='${k[1] + ""}'`; else if (k[0] == "text") inn = `${k[1]}`; else temp.push(k); }); const stat = !["input", "link", "br", "hr"].includes(e[0]); if (stat) result += ">"; result += inn; for (let i of temp) result += render({ [i[0]]: i[1] }); if (stat) result += `</${e[0]}>`; else result += "/>"; } else { } }); result = result.replace(/[\r\n\t]/gm, ""); result = result.replace(/\s{2,}/gm, " "); return result;}function range(length, start = 0) { return [...Array(length)].map(() => start++);}function outFile(source, data) { const fs = require("fs"); (function () { const dir = path.dirname(path.resolve(source)); if (!fs.existsSync(dir)) fs.mkdirSync(dir); fs.writeFileSync(source, render(data)); console.log(`Output file: ${source}`); })();}module.exports = { render, range, outFile, partial: async (src) => { console.log(path.join("file:\\\\", process.cwd(), src)); const { default: i } = await import( path.join("file:\\\\", process.cwd(), src) ); return i; },};
|