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 path = require("path");
|
||||
var crypto = require("crypto");
|
||||
var cheerio = require("cheerio");
|
||||
var UglifyJS = require("uglify-js");
|
||||
|
||||
var events = require("../events");
|
||||
@ -332,35 +331,21 @@ function loadNodeConfig(file,module,name) {
|
||||
node.name = path.basename(file)
|
||||
}
|
||||
|
||||
|
||||
var content = fs.readFileSync(node.template,'utf8');
|
||||
|
||||
var $ = cheerio.load(content);
|
||||
var template = "";
|
||||
var script = "";
|
||||
var types = [];
|
||||
|
||||
$("*").each(function(i,el) {
|
||||
if (el.type == "script" && el.attribs.type == "text/javascript") {
|
||||
script += el.children[0].data;
|
||||
} else if (el.name == "script" || el.name == "style") {
|
||||
if (el.attribs.type == "text/x-red" && el.attribs['data-template-name']) {
|
||||
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;
|
||||
}
|
||||
});
|
||||
var regExp = /<script ([^>]*)data-template-name=['"]([^'"]*)['"]/gi;
|
||||
var match = null;
|
||||
|
||||
while((match = regExp.exec(content)) !== null) {
|
||||
types.push(match[2]);
|
||||
}
|
||||
node.types = types;
|
||||
node.config = template;
|
||||
node.script = script;
|
||||
node.config = content;
|
||||
|
||||
// TODO: parse out the javascript portion of the template
|
||||
node.script = "";
|
||||
|
||||
for (var i=0;i<node.types.length;i++) {
|
||||
if (registry.getTypeId(node.types[i])) {
|
||||
|
@ -272,11 +272,11 @@ describe('NodeRegistry', function() {
|
||||
var nodeConfigs = typeRegistry.getNodeConfigs();
|
||||
|
||||
// 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 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();
|
||||
}).catch(function(e) {
|
||||
done(e);
|
||||
|
Loading…
Reference in New Issue
Block a user