mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Remove cheerio parse of node html files on start-up
This commit is contained in:
parent
76e8512869
commit
e8c4caaf74
@ -20,7 +20,6 @@ var whenNode = require('when/node');
|
|||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var crypto = require("crypto");
|
var crypto = require("crypto");
|
||||||
var cheerio = require("cheerio");
|
|
||||||
var UglifyJS = require("uglify-js");
|
var UglifyJS = require("uglify-js");
|
||||||
|
|
||||||
var events = require("../events");
|
var events = require("../events");
|
||||||
@ -332,35 +331,21 @@ function loadNodeConfig(file,module,name) {
|
|||||||
node.name = path.basename(file)
|
node.name = path.basename(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var content = fs.readFileSync(node.template,'utf8');
|
var content = fs.readFileSync(node.template,'utf8');
|
||||||
|
|
||||||
var $ = cheerio.load(content);
|
|
||||||
var template = "";
|
|
||||||
var script = "";
|
|
||||||
var types = [];
|
var types = [];
|
||||||
|
|
||||||
$("*").each(function(i,el) {
|
var regExp = /<script ([^>]*)data-template-name=['"]([^'"]*)['"]/gi;
|
||||||
if (el.type == "script" && el.attribs.type == "text/javascript") {
|
var match = null;
|
||||||
script += el.children[0].data;
|
|
||||||
} else if (el.name == "script" || el.name == "style") {
|
while((match = regExp.exec(content)) !== null) {
|
||||||
if (el.attribs.type == "text/x-red" && el.attribs['data-template-name']) {
|
types.push(match[2]);
|
||||||
types.push(el.attribs['data-template-name'])
|
|
||||||
}
|
}
|
||||||
var openTag = "<"+el.name;
|
|
||||||
var closeTag = "</"+el.name+">";
|
|
||||||
for (var j in el.attribs) {
|
|
||||||
if (el.attribs.hasOwnProperty(j)) {
|
|
||||||
openTag += " "+j+'="'+el.attribs[j]+'"';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
openTag += ">";
|
|
||||||
template += openTag+$(el).text()+closeTag;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
node.types = types;
|
node.types = types;
|
||||||
node.config = template;
|
node.config = content;
|
||||||
node.script = script;
|
|
||||||
|
// TODO: parse out the javascript portion of the template
|
||||||
|
node.script = "";
|
||||||
|
|
||||||
for (var i=0;i<node.types.length;i++) {
|
for (var i=0;i<node.types.length;i++) {
|
||||||
if (registry.getTypeId(node.types[i])) {
|
if (registry.getTypeId(node.types[i])) {
|
||||||
|
@ -272,11 +272,11 @@ describe('NodeRegistry', function() {
|
|||||||
var nodeConfigs = typeRegistry.getNodeConfigs();
|
var nodeConfigs = typeRegistry.getNodeConfigs();
|
||||||
|
|
||||||
// TODO: this is brittle...
|
// TODO: this is brittle...
|
||||||
nodeConfigs.should.equal("<script type=\"text/x-red\" data-template-name=\"test-node-1\"></script><script type=\"text/x-red\" data-help-name=\"test-node-1\"></script><style></style><script type=\"text/x-red\" data-template-name=\"test-node-2\"></script><script type=\"text/x-red\" data-help-name=\"test-node-2\"></script><style></style><script type=\"text/javascript\">RED.nodes.registerType(\"test-node-1\",{}),RED.nodes.registerType(\"test-node-2\",{});</script>");
|
nodeConfigs.should.equal("<script type=\"text/x-red\" data-template-name=\"test-node-1\"></script>\n<script type=\"text/x-red\" data-help-name=\"test-node-1\"></script>\n<script type=\"text/javascript\">RED.nodes.registerType('test-node-1',{});</script>\n<style></style>\n<p>this should be filtered out</p>\n<script type=\"text/x-red\" data-template-name=\"test-node-2\"></script>\n<script type=\"text/x-red\" data-help-name=\"test-node-2\"></script>\n<script type=\"text/javascript\">RED.nodes.registerType('test-node-2',{});</script>\n<style></style>\n");
|
||||||
|
|
||||||
var nodeId = list[0].id;
|
var nodeId = list[0].id;
|
||||||
var nodeConfig = typeRegistry.getNodeConfig(nodeId);
|
var nodeConfig = typeRegistry.getNodeConfig(nodeId);
|
||||||
nodeConfig.should.equal("<script type=\"text/x-red\" data-template-name=\"test-node-1\"></script><script type=\"text/x-red\" data-help-name=\"test-node-1\"></script><style></style><script type=\"text/javascript\">RED.nodes.registerType('test-node-1',{});</script>");
|
nodeConfig.should.equal("<script type=\"text/x-red\" data-template-name=\"test-node-1\"></script>\n<script type=\"text/x-red\" data-help-name=\"test-node-1\"></script>\n<script type=\"text/javascript\">RED.nodes.registerType('test-node-1',{});</script>\n<style></style>\n<p>this should be filtered out</p>\n<script type=\"text/javascript\"></script>");
|
||||||
done();
|
done();
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
done(e);
|
done(e);
|
||||||
|
Loading…
Reference in New Issue
Block a user