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 RM := -del
CP = copy /y $(subst /,\,$<) $(subst /,\,$@) CP = copy /y $(subst /,\,$<) $(subst /,\,$@)
MKDIR = -mkdir $(subst /,\,$@) MKDIR = -mkdir $(subst /,\,$@)
ESC_DOLLAR = $$
else else
BIN := node_modules/.bin/ BIN := node_modules/.bin/
RMDIR := rm -rf RMDIR := rm -rf
RM := rm -rf RM := rm -rf
CP = cp $< $@ CP = cp $< $@
MKDIR = mkdir -p $@ MKDIR = mkdir -p $@
ESC_DOLLAR = \$$
endif endif
coffee := $(BIN)coffee -c --no-header coffee := $(BIN)coffee -c --no-header
@ -34,6 +36,7 @@ sources_Config := \
sources_API := \ sources_API := \
src/General/$$.coffee \ src/General/$$.coffee \
src/General/$$$$.coffee \
src/General/CrossOrigin.coffee \ src/General/CrossOrigin.coffee \
src/Images/ImageCommon.coffee src/Images/ImageCommon.coffee
@ -148,14 +151,17 @@ tmp/$1.js : tmp/$1.coffee $(coffee_deps) tools/globalize.js
endef 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) tmp/API_%.coffee : tmp/API.jst $(template_deps)
$(template) $< $@ type=$* $(template) $< $@ type=$*
tmp/API_%.js : tmp/API_%.coffee $(coffee_deps) tmp/API_%.js : tmp/API_%.coffee $(coffee_deps)
$(coffee) $< $(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 tmp/eventPage.js : src/General/eventPage.coffee $(coffee_deps) | tmp
$(coffee) -o tmp src/General/eventPage.coffee $(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,9 +1,10 @@
var Conf, c, d, doc, g, E, $$; var Conf, E, c, d, doc, g;
Conf = {}; Conf = {};
c = console; c = console;
d = document; d = document;
doc = d.documentElement; doc = d.documentElement;
g = { g = {
VERSION: '<%= readJSON('version.json').version %>', VERSION: '<%= readJSON('version.json').version %>',
NAMESPACE: '<%= meta.name %>.', NAMESPACE: '<%= meta.name %>.',
@ -11,10 +12,17 @@ g = {
}; };
E = (function() { E = (function() {
var str = {'&': '&amp;', "'": '&#039;', '"': '&quot;', '<': '&lt;', '>': '&gt;'}; var fn, r, regex, str;
var r = String.prototype.replace; str = {
var regex = /[&"'<>]/g; '&': '&amp;',
var fn = function (x) { "'": '&#039;',
'"': '&quot;',
'<': '&lt;',
'>': '&gt;'
};
r = String.prototype.replace;
regex = /[&"'<>]/g;
fn = function(x) {
return str[x]; return str[x];
}; };
return function(text) { return function(text) {
@ -23,20 +31,14 @@ E = (function() {
})(); })();
E.cat = function(templates) { E.cat = function(templates) {
var html = ''; var html, i, len;
for (var i = 0, len = templates.length; i < len; i++) { html = '';
for (i = 0, len = templates.length; i < len; i++) {
html += templates[i].innerHTML; html += templates[i].innerHTML;
} }
return html; return html;
}; };
E.url = function(content) { E.url = function(content) {
return 'data:text/html;charset=utf-8,<!doctype html>' + encodeURIComponent(content.innerHTML); 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));
}; };

View File

@ -3,7 +3,7 @@ var fs = require('fs');
var names = []; var names = [];
for (var d of fs.readdirSync('src')) { for (var d of fs.readdirSync('src')) {
for (var f of fs.readdirSync(`src/${d}`)) { 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]); if (m) names.push(m[1]);
} }
} }

View File

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