Skip to content

Commit a95da86

Browse files
committed
Update to 2.15.1
1 parent 1779511 commit a95da86

File tree

9 files changed

+54
-21
lines changed

9 files changed

+54
-21
lines changed

examples/htmlserverload/html/head.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
<title>HTML Server Test</title>
33
<link prefix="/assets" href="./style.css" rel="stylesheet" type="text/css"/>
44
<script prefix="/assets" src="./app.js" supername="zetaret.node.examples.htmlserverload.html::app" type="text/javascript"></script>
5+
<script id="data-addon" exe="node" js="addDataHeadScript"></script>
6+
<script id="data-addon-pretty" exe="node" js="addDataHeadScript2"></script>
57
</head>

examples/htmlserverload/html/home.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<#template section="head" #>
33
<body>
44
<span>HTML Server Load Example</span>
5-
<div>Hello, {{profileName}}</div>
5+
<div id="profile-name">Hello, {{profileName}}</div>
6+
<div id="profile-description" exe="node" js="exeProfileDescription">Description: {{profileDescription}}</div>
67
<div id="app-screen" exe="node" js="exeAppScreen">
78
</div>
89
</body>

examples/htmlserverload/server_example.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,35 @@ for (var p in PAGES) {
4444
};
4545
}
4646

47-
var currentSessionData = { profileName: "LoggedUser1" };
47+
function exportServerVar(name, json, pretty) {
48+
return "var " + name + "=" + JSON.stringify(json, null, pretty ? 2 : null);
49+
}
50+
51+
var currentSessionData = { profileName: "LoggedUser1", profileDescription: "Logged User Description" };
4852

4953
const watchers = htcache.getWatchers(null, 500, true, true);
50-
function decorateParser(hpinst, o, p, op, pages) {
54+
function decorateParser(hpinst, o, p, op) {
5155
hpinst.jsonSpace = 2;
52-
hpinst.exeMethods.exeAppScreen = function (el, htcache, hpinst, p, op, pages) {
53-
console.log("#exe", el);
56+
//hpinst.exeDeleteOnSet = true;
57+
hpinst.exeMethods.addDataHeadScript = function (el, htcache, hpinst, p, op) {
58+
console.log("#addDataHeadScript", p, el);
59+
let expvar = { any: { name: "server" }, num: 3, bool: true, tostr: "string", time: new Date().toISOString() };
60+
el.elements.push(exportServerVar("exportedVar", expvar));
61+
};
62+
hpinst.exeMethods.addDataHeadScript2 = function (el, htcache, hpinst, p, op) {
63+
console.log("#addDataHeadScript2", p, el);
64+
let expvar = { anyData2: { name2: "fromServer" }, num2: 3, bool2: true, tostr2: "string" };
65+
el.elements.push(exportServerVar("exportedVar2", expvar, true));
66+
};
67+
hpinst.exeMethods.exeAppScreen = function (el, htcache, hpinst, p, op) {
68+
console.log("#exeAppScreen", p, el);
5469
el.elements.push(hpinst.getElement("div", false, { id: "app-screen-inset" }));
5570
el.elements.push("\n");
5671
};
72+
hpinst.exeMethods.exeProfileDescription = function (el, htcache, hpinst, p, op) {
73+
console.log("#exeProfileDescription", p, el);
74+
el.elements[0] = replaceParams(el.elements[0], currentSessionData);
75+
};
5776
}
5877
htcache.setPages(PAGES, htmlparser.HTMLParser, watchers, true, decorateParser);
5978

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "protoss-nodejs-basic",
3-
"version": "2.15.0",
3+
"version": "2.15.1",
44
"author": "Zeta Ret",
55
"license": "MIT",
66
"type": "commonjs",

protossdox.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"relative": true,
1010
"markdown": true,
1111
"ext": ["js", "ts"],
12-
"version": "2.15.0",
12+
"version": "2.15.1",
1313
"license": "MIT"
1414
}

utils/html/HTMLCache.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class HTMLCache {
8686
pdata.execfg = cfg;
8787
pdata.binders = {};
8888
pdata.content = "";
89+
o.execDom(hpinst, page, pdata);
8990
o.resetBinders(page);
9091
if (cfg.swapjs) o.swapJS(page, cfg.jsh, cfg.despacejs);
9192
if (cfg.swapcss) o.swapCSS(page, cfg.cssh, cfg.despacecss);
@@ -127,29 +128,37 @@ class HTMLCache {
127128
o.exePage(page, pdata.execfg);
128129
}
129130

131+
execDom(hpinst, id, pdata) {
132+
var o = this;
133+
var exes = hpinst.search(null, hpinst.exeOn, hpinst.exeAttr);
134+
if (exes.length > 0) {
135+
exes.forEach((el) => {
136+
let method = el.attr[hpinst.exeJS];
137+
if (hpinst.exeMethods[method]) {
138+
hpinst.exeMethods[method](el, o, hpinst, id, pdata);
139+
}
140+
if (hpinst.exeDeleteOnSet) {
141+
delete el.attr[hpinst.exeOn];
142+
delete el.attr[hpinst.exeJS];
143+
}
144+
});
145+
}
146+
}
147+
130148
setPages(pages, HTMLParser, watchers, log, decorateParser) {
131149
var o = this;
132150
var hpinst, p, op;
133151

134152
for (p in pages) {
135153
op = pages[p];
136154
hpinst = new HTMLParser();
137-
if (decorateParser) decorateParser(hpinst, o, p, op, pages);
155+
if (decorateParser) decorateParser(hpinst, o, p, op);
138156
hpinst.useAutomaton = op.useAutomaton || false;
139157
hpinst.debug = op.debug || false;
140158
if (op.closeTags) hpinst.closeTags = op.closeTags;
141159
if (op.cfgParser) op.cfgParser(hpinst, p, op);
142160
hpinst.parseFromFile(op.hfile, op.dir);
143161
o.addPage(op.id, hpinst, op.hfile, op.dir);
144-
var exes = hpinst.search(null, hpinst.exeOn, hpinst.exeAttr);
145-
if (exes.length > 0) {
146-
exes.forEach((el) => {
147-
let method = el.attr[hpinst.exeJS];
148-
if (hpinst.exeMethods[method]) {
149-
hpinst.exeMethods[method](el, o, hpinst, p, op, pages);
150-
}
151-
});
152-
}
153162
if (log) {
154163
console.log("\x1b[34m #Get Dom JSON:\x1b[0m");
155164
console.log(hpinst.getDomJSON());

utils/html/HTMLCache.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "HTML page cache utility",
44
"text": "Swap JS/CSS from filepath into tag as relative, cache as page content",
55
"requires": "fs, path, events",
6-
"version": "1.8.2",
6+
"version": "1.8.3",
77
"date": "2019 - Today",
88
"supername": "zetaret.node.utils.html::HTMLCache",
99
"inherits": null,
@@ -42,7 +42,7 @@
4242
"renderContent": "page*: String; return String",
4343
"resetBinders": "page*: String",
4444
"recache": "page*: String",
45-
"setPages": "pages*: Object, HTMLParser*: zetaret.node.utils.html.HTMLParser, watchers: Object, log: Boolean",
45+
"setPages": "pages*: Object, HTMLParser*: zetaret.node.utils.html.HTMLParser, watchers: Object, log: Boolean, decorateParser: Function",
4646
"swapCSS": "page*: String, handler: Function",
4747
"swapJS": "page*: String, handler: Function",
4848
"defaultRenderTemplate": "hcache*: zetaret.node.utils.html.HTMLCache, page*: String, pdata*: Object, hpinst*: zetaret.node.utils.html.HTMLParser, cfg*: Object",

utils/html/HTMLCache.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
> __HTML page cache utility__
33
# Swap JS/CSS from filepath into tag as relative, cache as page content
44
> *Requires: fs, path, events*
5-
> *Version: 1.8.2*
5+
> *Version: 1.8.3*
66
> *Date: 2019 - Today*
77
88
__required*__
@@ -132,12 +132,13 @@ __recache(*String* page) : *void*__
132132
> *return __void__*
133133
134134
##
135-
__setPages(*Object* pages, *zetaret.node.utils.html.HTMLParser* HTMLParser, *Object* watchers, *Boolean* log) : *void*__
135+
__setPages(*Object* pages, *zetaret.node.utils.html.HTMLParser* HTMLParser, *Object* watchers, *Boolean* log, *Function* decorateParser) : *void*__
136136

137137
- __pages*__ - __*Object*__,
138138
- __HTMLParser*__ - __*zetaret.node.utils.html.HTMLParser*__,
139139
- watchers - __*Object*__,
140140
- log - __*Boolean*__,
141+
- decorateParser - __*Function*__,
141142
> *return __void__*
142143
143144
##

utils/html/HTMLParser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class HTMLParser {
6161
o.exeOn = "exe";
6262
o.exeAttr = "node";
6363
o.exeJS = "js";
64+
o.exeDeleteOnSet = false;
6465
o.jsonReplacer = null;
6566
o.jsonSpace = null;
6667
}

0 commit comments

Comments
 (0)