lodash -> lodash.template

This commit is contained in:
ccd0 2016-04-18 05:26:45 -07:00
parent 3dd6a73ce1
commit c9934d69fa
5 changed files with 65 additions and 56 deletions

View File

@ -24,7 +24,7 @@ endif
coffee := $(BIN)coffee -c --no-header coffee := $(BIN)coffee -c --no-header
coffee_deps := node_modules/coffee-script/package.json coffee_deps := node_modules/coffee-script/package.json
template := node tools/template.js template := node tools/template.js
template_deps := package.json tools/template.js node_modules/lodash/package.json node_modules/esprima/package.json template_deps := package.json tools/template.js node_modules/lodash.template/package.json node_modules/esprima/package.json
cat := node tools/cat.js cat := node tools/cat.js
cat_deps := tools/cat.js cat_deps := tools/cat.js
@ -208,7 +208,7 @@ testbuilds/$(name).zip : testbuilds/$(name)-noupdate.crx.zip
builds/% : testbuilds/% | builds builds/% : testbuilds/% | builds
$(CP) $(CP)
test.html : README.md template.jst tools/markdown.js node_modules/marked/package.json node_modules/lodash/package.json test.html : README.md template.jst tools/markdown.js node_modules/marked/package.json node_modules/lodash.template/package.json
node tools/markdown.js node tools/markdown.js
index.html : test.html index.html : test.html

View File

@ -54,7 +54,7 @@
"font-awesome": "4.6.1", "font-awesome": "4.6.1",
"jshint": "^2.9.1", "jshint": "^2.9.1",
"jszip": "^3.0.0", "jszip": "^3.0.0",
"lodash": "^4.11.1", "lodash.template": "^4.2.4",
"marked": "^0.3.5", "marked": "^0.3.5",
"request": "^2.72.0", "request": "^2.72.0",
"webstore-upload": "^0.0.7" "webstore-upload": "^0.0.7"

View File

@ -16,11 +16,6 @@
"from": "archiver@>=0.8.0 <0.9.0", "from": "archiver@>=0.8.0 <0.9.0",
"resolved": "https://registry.npmjs.org/archiver/-/archiver-0.8.1.tgz", "resolved": "https://registry.npmjs.org/archiver/-/archiver-0.8.1.tgz",
"dependencies": { "dependencies": {
"lodash": {
"version": "2.4.2",
"from": "lodash@>=2.4.1 <2.5.0",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz"
},
"readable-stream": { "readable-stream": {
"version": "1.0.34", "version": "1.0.34",
"from": "readable-stream@>=1.0.24 <1.1.0", "from": "readable-stream@>=1.0.24 <1.1.0",
@ -304,14 +299,7 @@
"findup-sync": { "findup-sync": {
"version": "0.1.3", "version": "0.1.3",
"from": "findup-sync@>=0.1.2 <0.2.0", "from": "findup-sync@>=0.1.2 <0.2.0",
"resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-0.1.3.tgz", "resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-0.1.3.tgz"
"dependencies": {
"lodash": {
"version": "2.4.2",
"from": "lodash@>=2.4.1 <2.5.0",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz"
}
}
}, },
"font-awesome": { "font-awesome": {
"version": "4.6.1", "version": "4.6.1",
@ -378,14 +366,7 @@
"htmlparser2": { "htmlparser2": {
"version": "3.8.3", "version": "3.8.3",
"from": "htmlparser2@>=3.8.0 <3.9.0", "from": "htmlparser2@>=3.8.0 <3.9.0",
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz", "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz"
"dependencies": {
"readable-stream": {
"version": "1.1.14",
"from": "readable-stream@>=1.1.0 <1.2.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz"
}
}
}, },
"http-signature": { "http-signature": {
"version": "1.1.1", "version": "1.1.1",
@ -456,11 +437,6 @@
"version": "3.7.0", "version": "3.7.0",
"from": "lodash@>=3.7.0 <3.8.0", "from": "lodash@>=3.7.0 <3.8.0",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-3.7.0.tgz" "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.7.0.tgz"
},
"minimatch": {
"version": "2.0.10",
"from": "minimatch@>=2.0.0 <2.1.0",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-2.0.10.tgz"
} }
} }
}, },
@ -489,11 +465,6 @@
"from": "jszip@>=3.0.0 <4.0.0", "from": "jszip@>=3.0.0 <4.0.0",
"resolved": "https://registry.npmjs.org/jszip/-/jszip-3.0.0.tgz", "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.0.0.tgz",
"dependencies": { "dependencies": {
"es6-promise": {
"version": "3.0.2",
"from": "es6-promise@>=3.0.2 <3.1.0",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.0.2.tgz"
},
"isarray": { "isarray": {
"version": "1.0.0", "version": "1.0.0",
"from": "isarray@>=1.0.0 <1.1.0", "from": "isarray@>=1.0.0 <1.1.0",
@ -518,9 +489,54 @@
} }
}, },
"lodash": { "lodash": {
"version": "4.11.1", "version": "2.4.2",
"from": "lodash@>=4.11.1 <5.0.0", "from": "lodash@>=2.4.1 <2.5.0",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.11.1.tgz" "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz"
},
"lodash._reinterpolate": {
"version": "3.0.0",
"from": "lodash._reinterpolate@>=3.0.0 <3.1.0",
"resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz"
},
"lodash.assigninwith": {
"version": "4.0.6",
"from": "lodash.assigninwith@>=4.0.0 <5.0.0",
"resolved": "https://registry.npmjs.org/lodash.assigninwith/-/lodash.assigninwith-4.0.6.tgz"
},
"lodash.escape": {
"version": "4.0.0",
"from": "lodash.escape@>=4.0.0 <5.0.0",
"resolved": "https://registry.npmjs.org/lodash.escape/-/lodash.escape-4.0.0.tgz"
},
"lodash.keys": {
"version": "4.0.6",
"from": "lodash.keys@>=4.0.0 <5.0.0",
"resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-4.0.6.tgz"
},
"lodash.keysin": {
"version": "4.1.3",
"from": "lodash.keysin@>=4.0.0 <5.0.0",
"resolved": "https://registry.npmjs.org/lodash.keysin/-/lodash.keysin-4.1.3.tgz"
},
"lodash.rest": {
"version": "4.0.2",
"from": "lodash.rest@>=4.0.0 <5.0.0",
"resolved": "https://registry.npmjs.org/lodash.rest/-/lodash.rest-4.0.2.tgz"
},
"lodash.template": {
"version": "4.2.4",
"from": "lodash.template@latest",
"resolved": "https://registry.npmjs.org/lodash.template/-/lodash.template-4.2.4.tgz"
},
"lodash.templatesettings": {
"version": "4.0.1",
"from": "lodash.templatesettings@>=4.0.0 <5.0.0",
"resolved": "https://registry.npmjs.org/lodash.templatesettings/-/lodash.templatesettings-4.0.1.tgz"
},
"lodash.tostring": {
"version": "4.1.2",
"from": "lodash.tostring@>=4.0.0 <5.0.0",
"resolved": "https://registry.npmjs.org/lodash.tostring/-/lodash.tostring-4.1.2.tgz"
}, },
"lru-cache": { "lru-cache": {
"version": "2.7.3", "version": "2.7.3",
@ -734,11 +750,6 @@
"from": "glob@>=7.0.0 <8.0.0", "from": "glob@>=7.0.0 <8.0.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.0.3.tgz" "resolved": "https://registry.npmjs.org/glob/-/glob-7.0.3.tgz"
}, },
"lodash": {
"version": "2.4.2",
"from": "lodash@>=2.4.1 <3.0.0",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz"
},
"minimatch": { "minimatch": {
"version": "3.0.0", "version": "3.0.0",
"from": "minimatch@>=2.0.0 <3.0.0||>=3.0.0 <4.0.0", "from": "minimatch@>=2.0.0 <3.0.0||>=3.0.0 <4.0.0",
@ -771,14 +782,10 @@
"from": "zip-stream@>=0.3.0 <0.4.0", "from": "zip-stream@>=0.3.0 <0.4.0",
"resolved": "https://registry.npmjs.org/zip-stream/-/zip-stream-0.3.7.tgz", "resolved": "https://registry.npmjs.org/zip-stream/-/zip-stream-0.3.7.tgz",
"dependencies": { "dependencies": {
"lodash": {
"version": "2.4.2",
"from": "lodash@>=2.4.1 <2.5.0",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz"
},
"readable-stream": { "readable-stream": {
"version": "1.0.34", "version": "1.0.34",
"from": "readable-stream@>=1.0.26 <1.1.0" "from": "readable-stream@1.0.34",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz"
} }
} }
} }

View File

@ -1,10 +1,10 @@
var fs = require('fs'); var fs = require('fs');
var marked = require('marked'); var marked = require('marked');
var _ = require('lodash'); var template = require('lodash.template');
var md = fs.readFileSync('README.md', 'utf8'); var md = fs.readFileSync('README.md', 'utf8');
var content = marked(md); var content = marked(md);
var template = fs.readFileSync('template.jst', 'utf8'); var webtemplate = fs.readFileSync('template.jst', 'utf8');
var output = _.template(template)({content: content}); var output = template(webtemplate)({content: content});
output = output.replace(/\r\n/g, '\n'); output = output.replace(/\r\n/g, '\n');
fs.writeFileSync('test.html', output); fs.writeFileSync('test.html', output);

View File

@ -1,9 +1,9 @@
var fs = require('fs'); var fs = require('fs');
var _ = require('lodash'); var template = require('lodash.template');
var esprima = require('esprima'); var esprima = require('esprima');
// disable ES6 delimiters // disable ES6 delimiters
_.templateSettings.interpolate = /<%=([\s\S]+?)%>/g; var templateSettings = {interpolate: /<%=([\s\S]+?)%>/g};
var obj = {}; var obj = {};
@ -25,7 +25,7 @@ obj.multiline = function(text) {
obj.importHTML = function(filename) { obj.importHTML = function(filename) {
var text = read(`src/${filename}.html`).replace(/^ +/gm, '').replace(/\r?\n/g, ''); var text = read(`src/${filename}.html`).replace(/^ +/gm, '').replace(/\r?\n/g, '');
text = _.template(text)(pkg); // variables only; no recursive imports text = template(text, templateSettings)(pkg); // variables only; no recursive imports
return obj.html(text); return obj.html(text);
}; };
@ -187,8 +187,10 @@ for (var i = 4; i < process.argv.length; i++) {
pkg[m[1]] = m[2]; pkg[m[1]] = m[2];
} }
_.assign(obj, pkg); for (var key in pkg) {
obj[key] = pkg[key];
}
var text = read(process.argv[2]); var text = read(process.argv[2]);
text = _.template(text)(obj); text = template(text, templateSettings)(obj);
fs.writeFileSync(process.argv[3], text); fs.writeFileSync(process.argv[3], text);