Merge branch 'bstable'
This commit is contained in:
commit
3f265b33dc
18
Makefile
18
Makefile
@ -89,8 +89,8 @@ sources13 := \
|
||||
sources := $(foreach i,$(parts),$(sources$(i)))
|
||||
|
||||
imports := \
|
||||
node_modules/font-awesome/package.json \
|
||||
$(wildcard src/Linkification/icons/*.png) \
|
||||
tmp/font-awesome.css \
|
||||
tmp/style.css \
|
||||
src/Archive/archives.json \
|
||||
src/meta/icon48.png \
|
||||
$(wildcard src/Monitoring/Favicon/*/*.png) \
|
||||
@ -103,6 +103,12 @@ imports := \
|
||||
$(wildcard src/css/*.css) \
|
||||
.tests_enabled
|
||||
|
||||
imports_font_awesome := \
|
||||
node_modules/font-awesome/css/font-awesome.css \
|
||||
node_modules/font-awesome/fonts/fontawesome-webfont.woff
|
||||
imports_style := \
|
||||
$(wildcard src/Linkification/icons/*.png)
|
||||
|
||||
crx_contents := script.js eventPage.js icon16.png icon48.png icon128.png manifest.json
|
||||
|
||||
bds := \
|
||||
@ -132,12 +138,18 @@ all : jshint bds install
|
||||
npm install
|
||||
echo -> $@
|
||||
|
||||
node_modules/%/package.json : .events/npm
|
||||
node_modules/% : .events/npm
|
||||
|
||||
|
||||
.tests_enabled :
|
||||
echo false> .tests_enabled
|
||||
|
||||
tmp/font-awesome.css : src/css/font-awesome.css $(imports_font_awesome) $(template_deps) | tmp
|
||||
$(template) $< $@
|
||||
|
||||
tmp/style.css : src/css/style.css $(imports_style) $(template_deps) | tmp
|
||||
$(template) $< $@
|
||||
|
||||
define rules_part
|
||||
|
||||
tmp/parts/script$1.coffee : $$(sources$1) $(cat_deps) | tmp/parts
|
||||
|
||||
@ -391,7 +391,7 @@ Main =
|
||||
$.ready ->
|
||||
cb() if Main.isThisPageLegit()
|
||||
|
||||
css: `<%= importCSS('font-awesome', 'style', 'yotsuba', 'yotsuba-b', 'futaba', 'burichan', 'tomorrow', 'photon', 'supports') %>`
|
||||
css: `<%= importCSS('../../tmp/font-awesome', '../../tmp/style', 'yotsuba', 'yotsuba-b', 'futaba', 'burichan', 'tomorrow', 'photon', 'supports') %>`
|
||||
|
||||
cssWWW: `<%= importCSS('www') %>`
|
||||
|
||||
|
||||
@ -74,7 +74,7 @@ Linkify =
|
||||
|
||||
if Linkify.regString.test word
|
||||
links.push Linkify.makeRange node, endNode, index, length
|
||||
<%= assert('word is links[links.length-1].toString()') %>
|
||||
<%= assert('.tests_enabled', 'word is links[links.length-1].toString()') %>
|
||||
|
||||
break unless test.lastIndex and node is endNode
|
||||
|
||||
|
||||
@ -4,29 +4,26 @@ var _ = require('lodash');
|
||||
// disable ES6 delimiters
|
||||
_.templateSettings.interpolate = /<%=([\s\S]+?)%>/g;
|
||||
|
||||
var pkg = {};
|
||||
var obj = {};
|
||||
|
||||
var read = pkg.read = filename => fs.readFileSync(filename, 'utf8').replace(/\r\n/g, '\n');
|
||||
var readJSON = pkg.readJSON = filename => JSON.parse(read(filename));
|
||||
pkg.readBase64 = filename => fs.readFileSync(filename).toString('base64');
|
||||
pkg.ls = pathname => fs.readdirSync(pathname);
|
||||
|
||||
_.assign(pkg, readJSON('package.json'));
|
||||
_.assign(pkg.meta, readJSON('version.json'));
|
||||
var read = obj.read = filename => fs.readFileSync(filename, 'utf8').replace(/\r\n/g, '\n');
|
||||
var readJSON = obj.readJSON = filename => JSON.parse(read(filename));
|
||||
obj.readBase64 = filename => fs.readFileSync(filename).toString('base64');
|
||||
obj.ls = pathname => fs.readdirSync(pathname);
|
||||
|
||||
// Convert JSON object to Coffeescript expression (via embedded JS).
|
||||
var constExpression = data => '`' + JSON.stringify(data).replace(/`/g, '\\`') + '`';
|
||||
|
||||
pkg.importCSS = function() {
|
||||
obj.importCSS = function() {
|
||||
var text = Array.prototype.slice.call(arguments).map(name => read(`src/css/${name}.css`)).join('');
|
||||
text = _.template(text)(pkg);
|
||||
text = _.template(text)(pkg); // variables only; no recursive imports
|
||||
return text.trim().replace(/\n+/g, '\n').split(/^/m).map(JSON.stringify).join(' +\n').replace(/`/g, '\\`');
|
||||
};
|
||||
|
||||
pkg.importHTML = function(filename) {
|
||||
obj.importHTML = function(filename) {
|
||||
var text = read(`src/${filename}.html`).replace(/^ +/gm, '').replace(/\r?\n/g, '');
|
||||
text = _.template(text)(pkg);
|
||||
return pkg.html(text);
|
||||
text = _.template(text)(pkg); // variables only; no recursive imports
|
||||
return obj.html(text);
|
||||
};
|
||||
|
||||
function TextStream(text) {
|
||||
@ -155,7 +152,7 @@ Placeholder.prototype.build = function() {
|
||||
|
||||
// HTML template generator with placeholders of forms ${}, &{}, @{}, and ?{}{}{} (see Placeholder.prototype.build)
|
||||
// that checks safety of generated expressions at compile time.
|
||||
pkg.html = function(template) {
|
||||
obj.html = function(template) {
|
||||
var stream = new TextStream(template);
|
||||
var output = parseHTMLTemplate(stream);
|
||||
if (stream.text) {
|
||||
@ -164,16 +161,23 @@ pkg.html = function(template) {
|
||||
return `(innerHTML: ${output})`;
|
||||
};
|
||||
|
||||
pkg.assert = function(statement) {
|
||||
if (!pkg.tests_enabled) return '';
|
||||
obj.assert = function(flagFile, statement) {
|
||||
if (!readJSON(flagFile)) return '';
|
||||
return `throw new Error 'Assertion failed: ' + ${constExpression(statement)} unless ${statement}`;
|
||||
};
|
||||
|
||||
// Import variables from package.json and version.json.
|
||||
var pkg = readJSON('package.json');
|
||||
_.assign(pkg.meta, readJSON('version.json'));
|
||||
|
||||
// Take variables from command line.
|
||||
for (var i = 4; i < process.argv.length; i++) {
|
||||
var m = process.argv[i].match(/(.*?)=(.*)/);
|
||||
pkg[m[1]] = m[2];
|
||||
}
|
||||
|
||||
_.assign(obj, pkg);
|
||||
|
||||
var text = read(process.argv[2]);
|
||||
text = _.template(text)(pkg);
|
||||
text = _.template(text)(obj);
|
||||
fs.writeFileSync(process.argv[3], text);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user