neobiz 1.3.4 → 1.3.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +401 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neobiz",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "description": "A simple view engine with JS features",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -1,24 +1,404 @@
1
1
  <!-- @format -->
2
2
 
3
- <script src="https://cdn.jsdelivr.net/npm/showdown@2.1.0/dist/showdown.min.js"></script>
4
- <script>
5
- fetch(
6
- "https://raw.githubusercontent.com/harakun24/assets-neobiz/main/readme.md"
7
- )
8
- .then((e) => e.text())
9
- .then((e) => {
10
- var converter = new showdown.Converter(),
11
- text = e;
12
- try {
13
- document.getElementById("readme").innerHTML = converter.makeHtml(text);
14
- } catch {
15
- const t = document.createElement("a");
16
- t.setAttribute(
17
- "href",
18
- "https://raw.githubusercontent.com/harakun24/assets-neobiz/main/readme.md"
19
- );
20
- t.innerText = "Go to readme";
21
- document.querySelector("body").append(t);
3
+ <!-- @format -->
4
+
5
+ # Documentation Neobiz.js
6
+
7
+ > A simple view engine that has 100% JS features
8
+
9
+ [[Github example]](https://github.com/harakun24/assets-neobiz)
10
+ Neobiz.js is pure in JS lang, transform Object into HTML
11
+
12
+ `read /example dir to understanding`
13
+
14
+ [link to usage in express.js](https://www.npmjs.com/package/neobiz-express?activeTab=dependencies)
15
+
16
+ ---
17
+
18
+ | function | params | return-type | description |
19
+ | -------- | ------------------------------------ | ----------- | -------------------------------- |
20
+ | render | content[object] | string | rendering to HTML |
21
+ | outFile | destination[string], content[object] | void | generate static HTML file |
22
+ | range | length[int], start[int] | Array | shortcut for looping in a range |
23
+ | partial | source[string] | AsyncFn | including other file |
24
+ | fromStr | str[string] | Object | generate object from HTML string |
25
+
26
+ #### Why use this?
27
+
28
+ - Integrating back-end to view
29
+ - **directly** manipulation data or Model with a view
30
+ - Generate static html file
31
+ - Full control of view. Such as filtering, encrypting the data before serve, or just like conditional and loop case
32
+ - Almost no need to learn anything. Just need to learn how to render
33
+ - Limitless potential, because it's just js. Almost all library should be compatible
34
+
35
+ ## Basic syntax
36
+
37
+ It's just an Object!
38
+
39
+ ```js
40
+ {
41
+ // text property is same as innerText
42
+ h1: {
43
+ text: "Hello World!",
44
+ }
45
+ }
46
+ // <h1>Hello World!</h1>
47
+ ```
48
+
49
+ Comments:
50
+
51
+ ```js
52
+ {
53
+ // this is comment
54
+ /*
55
+ this is multi line
56
+ */
57
+ h1: {
58
+ text: "This is heading";
59
+ }
60
+ }
61
+ ```
62
+
63
+ properties dom
64
+
65
+ ```js
66
+ {
67
+ h1: {
68
+ class:"heading",
69
+ text: "Hello World!",
70
+ style:"color: #DC1E1E",
71
+ }
72
+ }
73
+ // <h1 class="heading" style="color: #DC1E1E">Hello World!</h1>
74
+ ```
75
+
76
+ innerText & innerHTML:
77
+
78
+ ```js
79
+ {
80
+ h1: { text: "<b>this is a text</b>" },
81
+ ul: { html: "<li>this will be render as html</li>" },
82
+ }
83
+ ```
84
+
85
+ nested dom:
86
+
87
+ ```js
88
+ {
89
+ body: {
90
+ h1: {
91
+ text: "Hello World!",
92
+ }
93
+ }
94
+ }
95
+ ```
96
+
97
+ expression & operator
98
+
99
+ ```js
100
+ {
101
+ span: [
102
+ { text: 24 + 12 / 6 },
103
+ { text: !false },
104
+ ],
105
+ }
106
+ ```
107
+
108
+ siblings dom:
109
+
110
+ There is a case like this:
111
+
112
+ ```html
113
+ <li>orange</li>
114
+ <li>banana</li>
115
+ ```
116
+
117
+ Object can not use 2 keys with the same name
118
+
119
+ ```js
120
+ // Don't do this
121
+ {
122
+ li:{text:"orange"},
123
+ li:{text:"banana"},
124
+ }
125
+
126
+ // Do this
127
+ {
128
+ li:[
129
+ {text:"orange"},
130
+ {text:"banana"},
131
+ ]
132
+ }
133
+ ```
134
+
135
+ What if there is somethings in the middle of list?
136
+
137
+ ```html
138
+ <li>orange</li>
139
+ <p>
140
+ <span>This is in the middle</span>
141
+ </p>
142
+ <li>banana</li>
143
+ ```
144
+
145
+ Can't use array? just use this:
146
+
147
+ > use string as key could distinc an element with just a space
148
+ > no need to worry, it will render without space
149
+
150
+ ```js
151
+ {
152
+ li:{text:"orange"},
153
+ p:{span:{text:"This is in the middle"}},
154
+ "li ":{text:"banana"},
155
+ }
156
+ ```
157
+
158
+ ### Components
159
+
160
+ ```js
161
+ import header from "./header.v.js"; //function type
162
+ import footer from "./footer.v.js"; //object type
163
+
164
+ render({
165
+ div: header({ user: "dim24" }),
166
+ p: { text: "this is text" },
167
+ div: footer,
168
+ });
169
+ ```
170
+
171
+ header.v.js
172
+
173
+ ```js
174
+ export default ({ user }) => ({ h1: { text: `Hi, ${user}` } });
175
+ ```
176
+
177
+ footer.v.js
178
+
179
+ ```js
180
+ export default {
181
+ script: { src: "/assets/js/main.js" },
182
+ span: { text: "this is footer" },
183
+ };
184
+ ```
185
+
186
+ ### Interacting with DOM
187
+
188
+ use `script` to interact with browser with **html** property
189
+
190
+ wrap the script with a function, or use string
191
+
192
+ ```js
193
+ {
194
+ button:{onclick:"sayHi(this)",id:"hi-button"},
195
+ script:{
196
+ html:()=>{
197
+ document.getElementById("hi-button").innerText="Click me!";
198
+
199
+ function sayHi(el){
200
+ el.innerText="Hi!";
22
201
  }
23
- });
24
- </script>
202
+ }
203
+ }
204
+ }
205
+
206
+ ```
207
+
208
+ ## fromStr
209
+
210
+ If you already have an html file and want to modify it, or make it as a template, just use `fromStr` function
211
+
212
+ > this function is still has some issues, but for simple html fromStr is work fine!
213
+
214
+ - wrap all tag into single parent
215
+ - use external script and css
216
+ - repetitive nested could caused weird behavior (help me, please!)
217
+
218
+ I still try to improve this feature. **if you can provide some help** just tell me please... :)
219
+
220
+ ```js
221
+ const { fromStr, render } = require("./index");
222
+
223
+ const { div } = fromStr(`
224
+ <div>
225
+ <h1>Hello dims!</h1>
226
+ </div>
227
+ `);
228
+
229
+ div.id = "main";
230
+ div.h1.class = "heading";
231
+ div.p = { text: "this is a whole text" };
232
+
233
+ console.log(render({ div }));
234
+ ```
235
+
236
+ result
237
+
238
+ ```html
239
+ <div id="main">
240
+ <h1 class="heading">Hello dims!</h1>
241
+ <p>this is a whole text</p>
242
+ </div>
243
+ ```
244
+
245
+ ## Pass Value
246
+
247
+ use function
248
+
249
+ ```js
250
+ import { render } from "../index.js";
251
+
252
+ console.log(render(((user) => ({ h1: { text: `Hello, ${user}` } }))("Vins")));
253
+ ```
254
+
255
+ or
256
+
257
+ ```js
258
+ const greeting = (user) => ({ h1: `Hello, ${user}` });
259
+
260
+ console.log(render(greeting("Vins")));
261
+ ```
262
+
263
+ ## Control Flow
264
+
265
+ ternary:
266
+
267
+ ```js
268
+ {
269
+ h1: status
270
+ ? { text: "Hello World!" }
271
+ : {
272
+ a: { href: "#", text: "You are offline!" },
273
+ },
274
+ }
275
+ ```
276
+
277
+ IIFE if-else
278
+
279
+ ```js
280
+ {
281
+ h1: (() => {
282
+ let result;
283
+ if (status) result = { text: "Hello World!" };
284
+ else
285
+ result = {
286
+ a: { href: "#", text: "You are offline!" },
287
+ };
288
+ return result;
289
+ })(),
290
+ }
291
+ ```
292
+
293
+ IIFE switch-case
294
+
295
+ ```js
296
+ {
297
+ h1: (() => {
298
+ let result;
299
+ switch (status) {
300
+ case true:
301
+ result = { text: "Hello World!" };
302
+ break;
303
+ case false:
304
+ result = {
305
+ a: { href: "#", text: "You are offline!" },
306
+ };
307
+ }
308
+ return result;
309
+ })(),
310
+ }
311
+ ```
312
+
313
+ ## Loop & array manipulation
314
+
315
+ range & map:
316
+
317
+ ```js
318
+ import { render, range } from "../index.js";
319
+
320
+ {
321
+ ul: {
322
+ li: range(8, 1).map((item) => ({ text: "data-" + item })),
323
+ },
324
+ }
325
+ ```
326
+
327
+ map
328
+
329
+ ```js
330
+ {
331
+ ul: {
332
+ li: ["grape", "banana", "apple"].map((text) => ({ text })),
333
+ },
334
+ }
335
+ ```
336
+
337
+ for
338
+
339
+ ```js
340
+ {
341
+ ul: {
342
+ li: (() => {
343
+ const result = [];
344
+ for (let i = 1; i < 9; i++) result.push({ text: "data-" + i });
345
+ return result;
346
+ })(),
347
+ },
348
+ }
349
+ ```
350
+
351
+ while
352
+
353
+ ```js
354
+ {
355
+ ul: {
356
+ li: (() => {
357
+ const result = [];
358
+ let i = 0;
359
+ while (++i < 9) result.push({ text: "data-" + i });
360
+ return result;
361
+ })(),
362
+ },
363
+ }
364
+ ```
365
+
366
+ ## partial & templating
367
+
368
+ ### partial
369
+
370
+ make sure to default export as a function
371
+
372
+ ```js
373
+ import { render, partial } from "../index.js";
374
+
375
+ {
376
+ head: (await partial("./exported.v.js"))("example page"),
377
+ h1: { text: "This is example" },
378
+ }
379
+ ```
380
+
381
+ `/exported.v.js`
382
+
383
+ ```js
384
+ export default (title) => ({ title: { text: title } });
385
+ ```
386
+
387
+ ### templating
388
+
389
+ this example use single file usage. for modular usage leave to you, or just read the example dir
390
+
391
+ ```js
392
+ import { render } from "../index.js";
393
+
394
+ const template = (content) => ({
395
+ div: {
396
+ class: "main wrapper",
397
+ div: content,
398
+ },
399
+ });
400
+
401
+ template({
402
+ h1: { text: "Hello World!" },
403
+ });
404
+ ```