Skip to content

Commit 336e75c

Browse files
committed
Update to 2.14.2
1 parent ea9fcd1 commit 336e75c

File tree

10 files changed

+57
-16
lines changed

10 files changed

+57
-16
lines changed

examples/htmlserverload/html/home.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
<body>
44
<span>HTML Server Load Example</span>
55
<div>Hello, {{profileName}}</div>
6+
<div id="app-screen" exe="node" js="exeAppScreen">
7+
</div>
68
</body>
79
</html>

examples/htmlserverload/server_example.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ for (var p in PAGES) {
4747
var currentSessionData = { profileName: "LoggedUser1" };
4848

4949
const watchers = htcache.getWatchers(null, 500, true, true);
50-
51-
htcache.setPages(PAGES, htmlparser.HTMLParser, watchers, true);
50+
function decorateParser(hpinst, o, p, op, pages) {
51+
hpinst.jsonSpace = 2;
52+
hpinst.exeMethods.exeAppScreen = function (el, htcache, hpinst, p, op, pages) {
53+
console.log("#exe", el);
54+
el.elements.push(hpinst.getElement("div", false, { id: "app-screen-inset" }));
55+
el.elements.push("\n");
56+
};
57+
}
58+
htcache.setPages(PAGES, htmlparser.HTMLParser, watchers, true, decorateParser);
5259

5360
function isLocal(req) {
5461
return ["::1", "127.0.0.1"].indexOf(req.connection.remoteAddress) !== -1;

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.14.1",
3+
"version": "2.14.2",
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.14.1",
12+
"version": "2.14.2",
1313
"license": "MIT"
1414
}

utils/html/HTMLCache.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,33 @@ class HTMLCache {
127127
o.exePage(page, pdata.execfg);
128128
}
129129

130-
setPages(pages, HTMLParser, watchers, log) {
130+
setPages(pages, HTMLParser, watchers, log, decorateParser) {
131131
var o = this;
132132
var hpinst, p, op;
133133

134134
for (p in pages) {
135135
op = pages[p];
136136
hpinst = new HTMLParser();
137+
if (decorateParser) decorateParser(hpinst, o, p, op, pages);
137138
hpinst.useAutomaton = op.useAutomaton || false;
138139
hpinst.debug = op.debug || false;
139140
if (op.closeTags) hpinst.closeTags = op.closeTags;
140141
if (op.cfgParser) op.cfgParser(hpinst, p, op);
141142
hpinst.parseFromFile(op.hfile, op.dir);
142143
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+
}
143153
if (log) {
154+
console.log("\x1b[34m #Get Dom JSON:\x1b[0m");
144155
console.log(hpinst.getDomJSON());
156+
console.log("\x1b[34m #Dom To String:\x1b[0m");
145157
console.log(hpinst.domToString());
146158
}
147159
}
@@ -159,12 +171,19 @@ class HTMLCache {
159171
o.events.emit(EVENTS.SWAP_CSS, page, pdata, o);
160172
hpinst.search("link", "type", "text/css").forEach((e) => {
161173
var swap,
174+
browserpath,
162175
pr,
163176
f = e.attr.href,
164-
prefix = e.attr.prefix;
177+
fileid = f.split("/").pop(),
178+
prefix = e.attr.prefix,
179+
base = e.attr.base;
165180

166-
if (prefix) {
167-
var browserpath = path.join(prefix, f).split("\\").join("/");
181+
if (base) {
182+
browserpath = path.join(base, fileid).split("\\").join("/");
183+
delete e.attr.base;
184+
e.attr.href = browserpath;
185+
} else if (prefix) {
186+
browserpath = path.join(prefix, f).split("\\").join("/");
168187
delete e.attr.prefix;
169188
e.attr.href = browserpath;
170189
} else if (f) {
@@ -192,12 +211,19 @@ class HTMLCache {
192211
o.events.emit(EVENTS.SWAP_JS, page, pdata, o);
193212
hpinst.search("script", "type", "text/javascript").forEach((e) => {
194213
var swap,
214+
browserpath,
195215
pr,
196216
f = e.attr.src,
197-
prefix = e.attr.prefix;
217+
fileid = f.split("/").pop(),
218+
prefix = e.attr.prefix,
219+
base = e.attr.base;
198220

199-
if (prefix) {
200-
var browserpath = path.join(prefix, f).split("\\").join("/");
221+
if (base) {
222+
browserpath = path.join(base, fileid).split("\\").join("/");
223+
delete e.attr.base;
224+
e.attr.src = browserpath;
225+
} else if (prefix) {
226+
browserpath = path.join(prefix, f).split("\\").join("/");
201227
delete e.attr.prefix;
202228
e.attr.src = browserpath;
203229
} else if (f) {

utils/html/HTMLCache.json

Lines changed: 1 addition & 1 deletion
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.1",
6+
"version": "1.8.2",
77
"date": "2019 - Today",
88
"supername": "zetaret.node.utils.html::HTMLCache",
99
"inherits": null,

utils/html/HTMLCache.md

Lines changed: 1 addition & 1 deletion
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.1*
5+
> *Version: 1.8.2*
66
> *Date: 2019 - Today*
77
88
__required*__

utils/html/HTMLParser.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ class HTMLParser {
5757
"+": "type",
5858
"?": "_",
5959
};
60+
o.exeMethods = {};
61+
o.exeOn = "exe";
62+
o.exeAttr = "node";
63+
o.exeJS = "js";
64+
o.jsonReplacer = null;
65+
o.jsonSpace = null;
6066
}
6167

6268
getFilePath(file, dir) {
@@ -99,7 +105,7 @@ class HTMLParser {
99105
}
100106

101107
getDomJSON() {
102-
return JSON.stringify(this.dom);
108+
return JSON.stringify(this.dom, this.jsonReplacer, this.jsonSpace);
103109
}
104110

105111
domToString(dom, nowhite, pretty, prefix) {

utils/html/HTMLParser.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Simple HTML parser",
44
"text": "RegExp XML processor to object and reversed conversion to HTML",
55
"requires": "fs, path, events",
6-
"version": "1.9.1",
6+
"version": "1.9.2",
77
"date": "2019 - Today",
88
"supername": "zetaret.node.utils.html::HTMLParser",
99
"inherits": null,

utils/html/HTMLParser.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
> __Simple HTML parser__
33
# RegExp XML processor to object and reversed conversion to HTML
44
> *Requires: fs, path, events*
5-
> *Version: 1.9.1*
5+
> *Version: 1.9.2*
66
> *Date: 2019 - Today*
77
88
__required*__

0 commit comments

Comments
 (0)