Skip to content

Commit 2e74fe9

Browse files
committed
Learning to use GitHub...
1 parent ddc4daf commit 2e74fe9

29 files changed

Lines changed: 8671 additions & 162 deletions

js/almcss3/almcss.js

Lines changed: 100 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,111 +4,138 @@ var ALMCSS = function() {
44

55
'use strict';
66

7+
var SCRIPT_NAME = 'almcss.js';
8+
9+
// AlmcssError
10+
711
var AlmcssError = function(message) {
812
this.name = 'AlmcssError';
913
this.message = message;
1014
};
1115

1216
AlmcssError.prototype = Object.create(Error.prototype);
1317

14-
return {
15-
AlmcssError: AlmcssError
16-
};
18+
// basePath
1719

18-
}();
20+
// http://stackoverflow.com/questions/2161159/get-script-path
21+
var getBasePath = function() {
22+
var scripts = document.getElementsByTagName('script'),
23+
i, length;
24+
25+
for (i = 0; i < scripts.length; i++) {
26+
var src = scripts[i].getAttribute('src');
27+
length = src.length - SCRIPT_NAME.length;
28+
var name = src.substr(length);
29+
if (name === SCRIPT_NAME) {
30+
return src.substr(0, length);
31+
}
32+
}
33+
};
1934

20-
ALMCSS.module = function() {
35+
var basePath = getBasePath();
2136

22-
'use strict';
37+
var module = function() {
2338

24-
var loadedModules = [];
39+
var loadedModules = [];
2540

26-
var isAlreadyLoaded = function(file) {
27-
return loadedModules.indexOf(file) !== -1;
28-
};
41+
var isAlreadyLoaded = function(file) {
42+
return loadedModules.indexOf(file) !== -1;
43+
};
2944

30-
var load = function(file, whenDone) {
31-
var script = document.getElementsByTagName('script')[0];
32-
var module = document.createElement('script');
33-
module.setAttribute('type', 'text/javascript');
34-
module.onload = function() {
35-
loadedModules.push(file);
36-
whenDone.call(null);
45+
var load = function(file, whenDone) {
46+
var script = document.getElementsByTagName('script')[0];
47+
var module = document.createElement('script');
48+
module.setAttribute('type', 'text/javascript');
49+
module.onload = function() {
50+
loadedModules.push(file);
51+
whenDone.call(null);
52+
};
53+
module.setAttribute('src', file);
54+
script.parentNode.insertBefore(module, script);
3755
};
38-
module.setAttribute('src', file);
39-
script.parentNode.insertBefore(module, script);
40-
};
4156

42-
/*
43-
// http://www.denys-klymenko.com/blog/loading-external-javascript-files-dynamically-and-synchronously/
44-
var include = function(files, whenDone) {
57+
// http://www.denys-klymenko.com/blog/loading-external-javascript-files-dynamically-and-synchronously/
58+
var include = function(files, whenDone) {
4559

46-
function whenLoaded() {
47-
files.shift();
48-
if (files.length === 0) {
49-
whenDone.call(null);
50-
} else {
51-
include.apply(this, [files, whenDone]);
60+
var file = files[0];
61+
if (isAlreadyLoaded(file)) {
62+
return;
5263
}
53-
}
64+
var script = document.getElementsByTagName('script')[0];
65+
var module = document.createElement('script');
66+
module.setAttribute('type', 'text/javascript');
67+
module.onload = function() {
68+
files.shift();
69+
if (files.length === 0) {
70+
whenDone.call(null);
71+
} else {
72+
include.apply(this, [files, whenDone]);
73+
}
74+
};
75+
module.setAttribute('src', basePath + file);
76+
script.parentNode.insertBefore(module, script);
77+
loadedModules.push(file);
78+
};
5479

55-
var file = files[0];
80+
return {
81+
include: include
82+
};
5683

57-
if (!isAlreadyLoaded(file)) {
58-
load(file, whenLoaded);
84+
}(); // module
85+
86+
var init = function() {
87+
var LoggerLevel = ALMCSS.debug.LoggerLevel,
88+
logger = ALMCSS.debug.getLogger('ALMCSS3 Main Function', LoggerLevel.all),
89+
parser = ALMCSS.parser.Parser,
90+
log = logger.log,
91+
info = logger.info,
92+
templates = ALMCSS.template.templates,
93+
createTemplateElements = ALMCSS.template.dom.createTemplateElements,
94+
i;
95+
96+
info('Starting the main function of ALMCSS3...');
97+
var cssCache = ALMCSS.stylesheet.loadStyleSheets();
98+
parser.parse(cssCache);
99+
if (templates.length) {
100+
info(templates.length + ' templates were found:\n');
101+
for (i = 0; i < templates.length; i++) {
102+
info(templates[i] + '\n');
103+
if (i < templates.length - 1) {
104+
info('---------------------------\n');
105+
}
106+
}
107+
} else {
108+
info('No templates were found');
59109
}
110+
createTemplateElements(templates);
60111
};
61-
*/
62112

63-
var include = function(files, whenDone) {
113+
var loadModules = function() {
64114

65-
var file = files[0];
66-
if (isAlreadyLoaded(file)) {
67-
return;
68-
}
69-
var script = document.getElementsByTagName('script')[0];
70-
var module = document.createElement('script');
71-
module.setAttribute('type', 'text/javascript');
72-
module.onload = function() {
73-
files.shift();
74-
if (files.length === 0) {
75-
whenDone.call(null);
76-
} else {
77-
include.apply(this, [files, whenDone]);
78-
}
79-
};
80-
module.setAttribute('src', file);
81-
script.parentNode.insertBefore(module, script);
82-
loadedModules.push(file);
115+
var include = module.include;
83116

117+
include([
118+
'debug.js',
119+
'stylesheet.js',
120+
'css.js',
121+
'parser.js',
122+
'template.js',
123+
'template_dom.js'
124+
], init);
84125
};
85126

86-
87127
return {
88-
include: include
128+
module: module,
129+
AlmcssError: AlmcssError,
130+
start: loadModules
89131
};
90132

91133
}();
92134

93-
var init = function() {
94-
95-
ALMCSS.debug.init();
96-
var getLogger = ALMCSS.debug.getLogger;
97-
98-
var css = ALMCSS.stylesheet.loadStyleSheets();
99-
lexer.init(css);
100-
var token;
101-
while ((token = lexer.nextToken()) !== Token.EOF) {
102-
log(token.toString());
103-
}
104-
log('Fin de fichero');
105-
};
106-
107135
window.onload = function () {
108-
var include = ALMCSS.module.include;
109-
//include('js/almcss3/debug.js', init);
110-
include(['js/almcss3/debug.js', 'js/almcss3/stylesheet.js', 'js/almcss3/lexer.js'], init);
111-
//include(['js/almcss3/debug.js'], init);
112136

137+
'use strict';
138+
139+
ALMCSS.start();
113140

114141
};

js/almcss3/debug.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
var ALMCSS = ALMCSS || {};
1616

17-
ALMCSS.module.include(['lib/firebug-lite.js']);
17+
//ALMCSS.module.include(['lib/firebug-lite.js']);
1818

1919
ALMCSS.debug = function () {
2020

@@ -24,9 +24,9 @@ ALMCSS.debug = function () {
2424
loggers = {},
2525
console = window.console;
2626

27-
var init = function () {
27+
/*
28+
var init = function () {
2829
29-
/*
3030
var console = window.console;
3131
3232
// This array contains the names of the method that are going to be
@@ -74,8 +74,8 @@ ALMCSS.debug = function () {
7474
};
7575
}
7676
}
77-
*/
7877
};
78+
*/
7979

8080
// Returns the previously created logger of that name, if it exists, or
8181
// creates and returns a new one, adding it to the list of created
@@ -197,10 +197,10 @@ ALMCSS.debug = function () {
197197
}
198198
};
199199

200-
init();
200+
/* init(); */
201201

202202
return {
203-
init: init,
203+
// init: init,
204204
LoggerLevel: LoggerLevel,
205205
getLogger: getLogger,
206206
Assert: Assert,

js/almcss3/module.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ ALMCSS.module = function() {
4343
module.setAttribute('src', file);
4444
script.parentNode.insertBefore(module, script);
4545
loadedModules.push(file);
46-
4746
};
48-
4947
return {
5048
include: include
5149
};

js/almcss3/parser.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,8 @@ ALMCSS.parser = function() {
12111211

12121212
var Parser = function() {
12131213

1214-
var logger = ALMCSS.debug.getLogger('Parser'),
1214+
var LoggerLevel = ALMCSS.debug.LoggerLevel,
1215+
logger = ALMCSS.debug.getLogger('Parser', LoggerLevel.all),
12151216
log = logger.log,
12161217
info = logger.info,
12171218
error = logger.error,
@@ -1430,9 +1431,10 @@ ALMCSS.parser = function() {
14301431
var selectorText = '', hasTypeOrUniversal = false, hasAny = false;
14311432
if (currentToken.isIdent() || currentToken === Token.ASTERISK) {
14321433
selectorText = currentToken.isIdent() ? currentToken.name : '*';
1434+
log('Found a ident or universal selector: ' + selectorText);
14331435
hasTypeOrUniversal = true;
1436+
nextToken();
14341437
}
1435-
nextToken();
14361438
while (true) {
14371439
if (currentToken.isHash()) {
14381440
selectorText = selectorText + '#' + currentToken.name;
@@ -1447,6 +1449,7 @@ ALMCSS.parser = function() {
14471449
} else {
14481450
break;
14491451
}
1452+
log('Found a id, class, attribute, pseudo or negation selector: ' + selectorText);
14501453
hasAny = true;
14511454
nextToken();
14521455
}
@@ -1723,9 +1726,17 @@ ALMCSS.parser = function() {
17231726

17241727

17251728
var parse = function(input) {
1729+
var result;
1730+
logger.groupCollapsed('Parser');
1731+
info('Parsing the serialised stylesheet...');
1732+
log('The css being parsed is: \n' + input);
17261733
lexer.init(input);
17271734
nextToken();
1728-
return parseStyleSheet();
1735+
result = parseStyleSheet();
1736+
info('The parser has ended');
1737+
log('The parsed stylesheet is: ' + result);
1738+
logger.groupEnd();
1739+
return result;
17291740
};
17301741

17311742
return {

js/almcss3/stylesheet.js

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,7 @@ ALMCSS.stylesheet = function() {
1010
var log = logger.log;
1111
var warn = logger.warn;
1212

13-
//var cssCache = {};
1413
var cssCache = '';
15-
var howManyLoaded = 0;
16-
17-
// Initialise the `cssCache` object that will store the full text of all
18-
// the style sheets associated to this document, using as a property for
19-
// each style sheet the value of its `href` property, or `'inline'` for
20-
// the style included with the STYLE element.
21-
//
22-
// This function creates the properties for all the style sheets, which are
23-
// initially set to `false`, until the content of each style sheet is stored
24-
// in its associate property.
25-
//
26-
var init = function() {
27-
assert(document.styleSheets, 'This browser does not support document.styleSheets');
28-
for (var i = 0; i < document.styleSheets.length; i++) {
29-
var sheet = document.styleSheets[i];
30-
var key = sheet.href ? sheet.href : 'inline';
31-
cssCache[key] = false;
32-
}
33-
};
3414

3515
var getPath = function() {
3616
var result = window.location.href.substr(0, (location.href).lastIndexOf('/') + 1);
@@ -160,21 +140,21 @@ ALMCSS.stylesheet = function() {
160140
// with a LINK element.
161141

162142
var loadStyleSheets = function() {
163-
//init();
164-
//assert(cssCache.length === document.styleSheets.length, "'init' has not been called");
165-
logger.group('Loading style sheets...');
143+
logger.groupCollapsed('Style sheet loader');
144+
logger.info('Loading style sheets...');
166145
for (var i = 0; i < document.styleSheets.length; i++) {
167146
loadCssCache(document.styleSheets[i]);
168147
}
169-
log('All style sheets have been loaded.');
148+
logger.info('All style sheets have been loaded:\n');
170149
logger.info(cssCache);
171150
logger.groupEnd();
172151
return cssCache;
173152
};
174153

175154
return {
176155
readExternalStyleSheet: readExternalStyleSheet,
177-
readFile: readFile
156+
readFile: readFile,
157+
loadStyleSheets: loadStyleSheets
178158
};
179159

180160
}();

0 commit comments

Comments
 (0)