Skip to content

Commit e897318

Browse files
committed
.
1 parent 49cb267 commit e897318

3 files changed

Lines changed: 45 additions & 32 deletions

File tree

bundle/examples/simple/client.html

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
{
22
"#title": "Client",
33
"info": {
4-
"#num": 120,
5-
"#txt": "ATOME"
4+
"num": 120,
5+
"txt": "ATOME"
66
},
7+
"tst": [
8+
"The number id **{{ info.num }}** and the number again {{ info.txt }} and {{ info.txt.ttt.hello.opa }}"
9+
],
710
"main": [
8-
"The number id **{{ [/examples/simple/source.html] info.#num }}**",
9-
"The number id **{{ info.#num }}** and the number again {{ info.#txt }}",
10-
"The number id **{{ [/examples/simple/source.html] info.#txt }}** and \nthis is another {{ [/examples/simple/source.html] info.#txt }}",
11-
"The number id **{{ [http://nn] info.#txt }}** this is another {{ [/examples/simple/source.html] info.#txt }}",
12-
"The number id **{{ [http://nn] info.#txt }}** and the number again {{ info.#txt }}",
13-
"The number id **{{ [/examples/simple/source.html] info.#loopa }}** and the number again {{ info.#txt }}",
14-
"The number id **{{ [/examples/simple/source.html] info.#txt }}**",
15-
"The number id **{{ [/examples/simple/index.html] info.#txt }}**",
16-
11+
"The number id **{{ [/examples/simple/source.html] info.num }}** and **{{ [/examples/simple/source.html] info.txt }}**",
12+
"The number id **{{ info.num }}** and the number again {{ info.txt }}",
13+
"The number id **{{ [/examples/simple/source.html] info.nested.hello }}**",
14+
"WDR Title **{{ [https://webdatarender.com] #title }}**",
15+
"WDR Last Update **{{ [https://webdatarender.com] updates.items.0.description }}**",
16+
"WDR Last last Update **{{ [https://webdatarender.com] updates.items.1.description }}**",
17+
"WDR Subscribe **{{ [https://webdatarender.com] subscribe }}**",
18+
""
19+
],
20+
"#sec": [
21+
"The number id **{{ [/examples/simple/source.html] info.txt }}** and \nthis is another {{ [/examples/simple/source.html] info.txt }}",
22+
"The number id **{{ [http://nn] info.txt }}** this is another {{ [/examples/simple/source.html] info.txt }}",
23+
"The number id **{{ [http://nn] info.txt }}** and the number again {{ info.txt }}",
24+
"The number id **{{ [/examples/simple/source.html] info.#loopa }}** and the number again {{ info.txt }}",
25+
"The number id **{{ [/examples/simple/source.html] info.txt }}**",
26+
"The number id **{{ [/examples/simple/index.html] info.txt }}**",
1727
""
1828
],
1929
"#test": [
2030
"--------------------------------------------------",
21-
"The number id **{{ info.#num }}**",
22-
"The number id **{{info.#num}}**",
23-
"The number id **{{ info.#num }}**",
24-
"The number id **{{ info.#num {{num}} }}**",
25-
"The number id **{{ [/examples/simple/source.html]info.#num }}**",
26-
"The number id **{{ [/examples/simple/source.html] info.#num }}**",
27-
31+
"The number id **{{ info.num }}**",
32+
"The number id **{{info.num}}**",
33+
"The number id **{{ info.num }}**",
34+
"The number id **{{ info.num {{num}} }}**",
35+
"The number id **{{ [/examples/simple/source.html]info.num }}**",
36+
"The number id **{{ [/examples/simple/source.html] info.num }}**",
2837
""
2938
],
3039

bundle/examples/simple/source.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
22
"#title": "Source",
33
"info": {
4-
"#num": 42,
5-
"#txt": "Universe"
4+
"num": 42,
5+
"txt": "Universe",
6+
"nested": {
7+
"hello": "world"
8+
}
69
},
710
"main": [
8-
"The number id **{{ info.#num }}** and the number again {{ info.#txt }}"
11+
"The number id **{{ info.num }}** and the number again {{ info.txt }} in {{ info.nested.hello }}"
912
],
1013

1114

src/Variables.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,32 @@
22

33
function createVariables(defaultData) {
44

5-
const data = {
5+
const DATA = {
66
_: defaultData
77
}
88

99
async function getData(key) {
1010

1111
if (key) {
12-
if (data[key] == undefined) {
13-
console.log('NEW DATABASE --- ', key);
14-
15-
data[key] = fetch(key)
12+
if (DATA[key] == undefined) {
13+
DATA[key] = fetch(key)
1614
.then(x => new Promise(resolve => setTimeout(() => resolve(x), Math.random()*10000)))
1715
.then(r => r.json());
1816
}
19-
return data[key];
17+
return DATA[key];
2018

2119
} else {
22-
return data['_'];
20+
return DATA['_'];
2321
}
2422

2523
}
2624

25+
async function getValue(url, path) {
26+
27+
const data = await getData(url);
28+
return path.split(".").reduce((acc, cur) => acc[cur.trim()], data);
29+
}
30+
2731
return {
2832
replace: (str, mark) => {
2933
return str.replace(/{{[^{}]+}}/g, mark);
@@ -43,10 +47,7 @@ function createVariables(defaultData) {
4347
ret.push(str.slice(i, match.index));
4448

4549
try {
46-
const d = await getData(url);
47-
48-
ret.push(`[[[${url || ""}@${path}]]]`);
49-
50+
ret.push(await getValue(url, path));
5051
} catch (error) {
5152
ret.push(`[ERROR]`);
5253
}

0 commit comments

Comments
 (0)