Make globals.js more like Coffeescript output; move $$ to its own file.

This commit is contained in:
ccd0 2016-04-13 16:54:39 -07:00
parent 5ec7a559be
commit d82418ed45
5 changed files with 33 additions and 23 deletions

View File

@ -6,12 +6,14 @@ ifeq "$(OS)" "Windows_NT"
RM := -del
CP = copy /y $(subst /,\,$<) $(subst /,\,$@)
MKDIR = -mkdir $(subst /,\,$@)
ESC_DOLLAR = $$
else
BIN := node_modules/.bin/
RMDIR := rm -rf
RM := rm -rf
CP = cp $< $@
MKDIR = mkdir -p $@
ESC_DOLLAR = \$$
endif
coffee := $(BIN)coffee -c --no-header
@ -34,6 +36,7 @@ sources_Config := \
sources_API := \
src/General/$$.coffee \
src/General/$$$$.coffee \
src/General/CrossOrigin.coffee \
src/Images/ImageCommon.coffee
@ -148,14 +151,17 @@ tmp/$1.js : tmp/$1.coffee $(coffee_deps) tools/globalize.js
endef
$(foreach i,$(parts),$(eval $(call rules_part,$(i))))
$(foreach i,$(filter-out API,$(parts)),$(eval $(call rules_part,$(i))))
tmp/API.jst : $(sources_API) $(cat_deps) | tmp
$(cat) $(subst $$,$(ESC_DOLLAR),$(sources_API)) $@
tmp/API_%.coffee : tmp/API.jst $(template_deps)
$(template) $< $@ type=$*
tmp/API_%.js : tmp/API_%.coffee $(coffee_deps)
$(coffee) $<
node tools/globalize.js $@ $(sources_API)
node tools/globalize.js $@ $(subst $$,$(ESC_DOLLAR),$(sources_API))
tmp/eventPage.js : src/General/eventPage.coffee $(coffee_deps) | tmp
$(coffee) -o tmp src/General/eventPage.coffee

2
src/General/$$.coffee Normal file
View File

@ -0,0 +1,2 @@
$$ = (selector, root=d.body) ->
[root.querySelectorAll(selector)...]

View File

@ -1,20 +1,28 @@
var Conf, c, d, doc, g, E, $$;
var Conf, E, c, d, doc, g;
Conf = {};
c = console;
d = document;
doc = d.documentElement;
g = {
g = {
VERSION: '<%= readJSON('version.json').version %>',
NAMESPACE: '<%= meta.name %>.',
boards: {}
};
E = (function() {
var str = {'&': '&amp;', "'": '&#039;', '"': '&quot;', '<': '&lt;', '>': '&gt;'};
var r = String.prototype.replace;
var regex = /[&"'<>]/g;
var fn = function (x) {
var fn, r, regex, str;
str = {
'&': '&amp;',
"'": '&#039;',
'"': '&quot;',
'<': '&lt;',
'>': '&gt;'
};
r = String.prototype.replace;
regex = /[&"'<>]/g;
fn = function(x) {
return str[x];
};
return function(text) {
@ -23,20 +31,14 @@ E = (function() {
})();
E.cat = function(templates) {
var html = '';
for (var i = 0, len = templates.length; i < len; i++) {
var html, i, len;
html = '';
for (i = 0, len = templates.length; i < len; i++) {
html += templates[i].innerHTML;
}
return html;
};
E.url = function (content) {
return 'data:text/html;charset=utf-8,<!doctype html>' + encodeURIComponent(content.innerHTML);
};
$$ = function(selector, root) {
if (root == null) {
root = d.body;
}
return [].slice.call(root.querySelectorAll(selector));
E.url = function(content) {
return "data:text/html;charset=utf-8,<!doctype html>" + encodeURIComponent(content.innerHTML);
};

View File

@ -3,7 +3,7 @@ var fs = require('fs');
var names = [];
for (var d of fs.readdirSync('src')) {
for (var f of fs.readdirSync(`src/${d}`)) {
var m = f.match(/^([$A-Z]\w*)\.coffee$/);
var m = f.match(/^([$A-Z][$\w]*)\.coffee$/);
if (m) names.push(m[1]);
}
}

View File

@ -9,7 +9,7 @@ var sources = process.argv.slice(3);
var names = [];
for (var f of sources) {
f = f.match(/[^/]*$/)[0];
var m = f.match(/^([$A-Z]\w*)\.coffee$/);
var m = f.match(/^([$A-Z][$\w]*)\.coffee$/);
if (m) names.push(m[1]);
}
@ -20,10 +20,10 @@ var replaced = 0;
script = script.replace(
// matches declaration at the start of the function, not including helper function assignments
/ *\bvar\s+[\w$]+(,\s*[\w$]+)*(,\s*|;\n)/,
/ *\bvar\s+[$\w]+(,\s*[$\w]+)*(,\s*|;\n)/,
function(declaration) {
var parts = declaration.split(/([\w$]+)(?=[,;])/);
var parts = declaration.split(/([$\w]+)(?=[,;])/);
for (var name of names) {
var i = parts.indexOf(name);