haml_coffee_assets 0.0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +107 -42
- data/lib/haml_coffee_assets/engine.rb +12 -6
- data/lib/haml_coffee_assets/haml_coffee.rb +4 -2
- data/lib/haml_coffee_assets/haml_coffee_assets.js +41 -12
- data/lib/haml_coffee_assets/haml_coffee_template.rb +1 -1
- data/lib/haml_coffee_assets/version.rb +1 -1
- data/lib/js/haml-coffee.js +813 -269
- metadata +4 -4
data/lib/js/haml-coffee.js
CHANGED
@@ -23,33 +23,33 @@ require._core = {
|
|
23
23
|
require.resolve = (function () {
|
24
24
|
return function (x, cwd) {
|
25
25
|
if (!cwd) cwd = '/';
|
26
|
-
|
26
|
+
|
27
27
|
if (require._core[x]) return x;
|
28
28
|
var path = require.modules.path();
|
29
29
|
var y = cwd || '.';
|
30
|
-
|
30
|
+
|
31
31
|
if (x.match(/^(?:\.\.?\/|\/)/)) {
|
32
32
|
var m = loadAsFileSync(path.resolve(y, x))
|
33
33
|
|| loadAsDirectorySync(path.resolve(y, x));
|
34
34
|
if (m) return m;
|
35
35
|
}
|
36
|
-
|
36
|
+
|
37
37
|
var n = loadNodeModulesSync(x, y);
|
38
38
|
if (n) return n;
|
39
|
-
|
39
|
+
|
40
40
|
throw new Error("Cannot find module '" + x + "'");
|
41
|
-
|
41
|
+
|
42
42
|
function loadAsFileSync (x) {
|
43
43
|
if (require.modules[x]) {
|
44
44
|
return x;
|
45
45
|
}
|
46
|
-
|
46
|
+
|
47
47
|
for (var i = 0; i < require.extensions.length; i++) {
|
48
48
|
var ext = require.extensions[i];
|
49
49
|
if (require.modules[x + ext]) return x + ext;
|
50
50
|
}
|
51
51
|
}
|
52
|
-
|
52
|
+
|
53
53
|
function loadAsDirectorySync (x) {
|
54
54
|
x = x.replace(/\/+$/, '');
|
55
55
|
var pkgfile = x + '/package.json';
|
@@ -69,10 +69,10 @@ require.resolve = (function () {
|
|
69
69
|
if (m) return m;
|
70
70
|
}
|
71
71
|
}
|
72
|
-
|
72
|
+
|
73
73
|
return loadAsFileSync(x + '/index');
|
74
74
|
}
|
75
|
-
|
75
|
+
|
76
76
|
function loadNodeModulesSync (x, start) {
|
77
77
|
var dirs = nodeModulesPathsSync(start);
|
78
78
|
for (var i = 0; i < dirs.length; i++) {
|
@@ -82,23 +82,23 @@ require.resolve = (function () {
|
|
82
82
|
var n = loadAsDirectorySync(dir + '/' + x);
|
83
83
|
if (n) return n;
|
84
84
|
}
|
85
|
-
|
85
|
+
|
86
86
|
var m = loadAsFileSync(x);
|
87
87
|
if (m) return m;
|
88
88
|
}
|
89
|
-
|
89
|
+
|
90
90
|
function nodeModulesPathsSync (start) {
|
91
91
|
var parts;
|
92
92
|
if (start === '/') parts = [ '' ];
|
93
93
|
else parts = path.normalize(start).split('/');
|
94
|
-
|
94
|
+
|
95
95
|
var dirs = [];
|
96
96
|
for (var i = parts.length - 1; i >= 0; i--) {
|
97
97
|
if (parts[i] === 'node_modules') continue;
|
98
98
|
var dir = parts.slice(0, i + 1).join('/') + '/node_modules';
|
99
99
|
dirs.push(dir);
|
100
100
|
}
|
101
|
-
|
101
|
+
|
102
102
|
return dirs;
|
103
103
|
}
|
104
104
|
};
|
@@ -114,9 +114,9 @@ require.alias = function (from, to) {
|
|
114
114
|
res = require.resolve(from, '/');
|
115
115
|
}
|
116
116
|
var basedir = path.dirname(res);
|
117
|
-
|
117
|
+
|
118
118
|
var keys = Object_keys(require.modules);
|
119
|
-
|
119
|
+
|
120
120
|
for (var i = 0; i < keys.length; i++) {
|
121
121
|
var key = keys[i];
|
122
122
|
if (key.slice(0, basedir.length + 1) === basedir + '/') {
|
@@ -134,7 +134,7 @@ require.define = function (filename, fn) {
|
|
134
134
|
? ''
|
135
135
|
: require.modules.path().dirname(filename)
|
136
136
|
;
|
137
|
-
|
137
|
+
|
138
138
|
var require_ = function (file) {
|
139
139
|
return require(file, dirname)
|
140
140
|
};
|
@@ -144,7 +144,7 @@ require.define = function (filename, fn) {
|
|
144
144
|
require_.modules = require.modules;
|
145
145
|
require_.define = require.define;
|
146
146
|
var module_ = { exports : {} };
|
147
|
-
|
147
|
+
|
148
148
|
require.modules[filename] = function () {
|
149
149
|
require.modules[filename]._cached = module_.exports;
|
150
150
|
fn.call(
|
@@ -272,7 +272,7 @@ path = normalizeArray(filter(path.split('/'), function(p) {
|
|
272
272
|
if (path && trailingSlash) {
|
273
273
|
path += '/';
|
274
274
|
}
|
275
|
-
|
275
|
+
|
276
276
|
return (isAbsolute ? '/' : '') + path;
|
277
277
|
};
|
278
278
|
|
@@ -322,58 +322,166 @@ exports.extname = function(path) {
|
|
322
322
|
require.define("/nodes/node.js", function (require, module, exports, __dirname, __filename) {
|
323
323
|
(function() {
|
324
324
|
var Node, e, w;
|
325
|
-
|
325
|
+
|
326
|
+
e = require('../helper').escapeHTML;
|
327
|
+
|
326
328
|
w = require('../helper').whitespace;
|
329
|
+
|
327
330
|
module.exports = Node = (function() {
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
331
|
+
|
332
|
+
Node.CLEAR_WHITESPACE_LEFT = '\u0091';
|
333
|
+
|
334
|
+
Node.CLEAR_WHITESPACE_RIGHT = '\u0092';
|
335
|
+
|
336
|
+
function Node(expression, options) {
|
337
|
+
this.expression = expression != null ? expression : '';
|
338
|
+
if (options == null) options = {};
|
339
|
+
this.parentNode = options.parentNode;
|
332
340
|
this.children = [];
|
333
|
-
this.opener = this.closer =
|
334
|
-
this.
|
335
|
-
this.
|
341
|
+
this.opener = this.closer = null;
|
342
|
+
this.silent = false;
|
343
|
+
this.preserve = false;
|
344
|
+
this.wsRemoval = {
|
345
|
+
around: false,
|
346
|
+
inside: false
|
347
|
+
};
|
348
|
+
this.escapeHtml = options.escapeHtml;
|
349
|
+
this.escapeAttributes = options.escapeAttributes;
|
350
|
+
this.format = options.format;
|
351
|
+
this.codeBlockLevel = options.codeBlockLevel;
|
352
|
+
this.blockLevel = options.blockLevel;
|
336
353
|
}
|
354
|
+
|
337
355
|
Node.prototype.addChild = function(child) {
|
338
356
|
this.children.push(child);
|
339
357
|
return this;
|
340
358
|
};
|
359
|
+
|
341
360
|
Node.prototype.getOpener = function() {
|
342
|
-
this.
|
361
|
+
if (this.wsRemoval.around && this.opener.text) {
|
362
|
+
this.opener.text = Node.CLEAR_WHITESPACE_LEFT + this.opener.text;
|
363
|
+
}
|
364
|
+
if (this.wsRemoval.inside && this.opener.text) {
|
365
|
+
this.opener.text += Node.CLEAR_WHITESPACE_RIGHT;
|
366
|
+
}
|
343
367
|
return this.opener;
|
344
368
|
};
|
369
|
+
|
345
370
|
Node.prototype.getCloser = function() {
|
346
|
-
this.
|
371
|
+
if (this.wsRemoval.inside && this.closer.text) {
|
372
|
+
this.closer.text = Node.CLEAR_WHITESPACE_LEFT + this.closer.text;
|
373
|
+
}
|
374
|
+
if (this.wsRemoval.around && this.closer.text) {
|
375
|
+
this.closer.text += Node.CLEAR_WHITESPACE_RIGHT;
|
376
|
+
}
|
347
377
|
return this.closer;
|
348
378
|
};
|
349
|
-
|
350
|
-
|
351
|
-
|
379
|
+
|
380
|
+
Node.prototype.isPreserved = function() {
|
381
|
+
if (this.preserve) return true;
|
382
|
+
if (this.parentNode) {
|
383
|
+
return this.parentNode.isPreserved();
|
384
|
+
} else {
|
385
|
+
return false;
|
352
386
|
}
|
353
|
-
return this.evaluated = true;
|
354
387
|
};
|
388
|
+
|
389
|
+
Node.prototype.markText = function(text, escape) {
|
390
|
+
if (escape == null) escape = false;
|
391
|
+
return {
|
392
|
+
type: 'text',
|
393
|
+
cw: this.codeBlockLevel,
|
394
|
+
hw: this.blockLevel - this.codeBlockLevel + 2,
|
395
|
+
text: escape ? e(text) : text
|
396
|
+
};
|
397
|
+
};
|
398
|
+
|
399
|
+
Node.prototype.markRunningCode = function(code) {
|
400
|
+
return {
|
401
|
+
type: 'run',
|
402
|
+
cw: this.codeBlockLevel,
|
403
|
+
code: code
|
404
|
+
};
|
405
|
+
};
|
406
|
+
|
407
|
+
Node.prototype.markInsertingCode = function(code, escape) {
|
408
|
+
if (escape == null) escape = false;
|
409
|
+
return {
|
410
|
+
type: 'insert',
|
411
|
+
cw: this.codeBlockLevel,
|
412
|
+
hw: this.blockLevel,
|
413
|
+
escape: escape,
|
414
|
+
code: code
|
415
|
+
};
|
416
|
+
};
|
417
|
+
|
355
418
|
Node.prototype.evaluate = function() {};
|
419
|
+
|
356
420
|
Node.prototype.render = function() {
|
357
|
-
var child, output, _i, _len, _ref;
|
358
|
-
output =
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
421
|
+
var child, output, preserve, tag, _i, _j, _k, _l, _len, _len2, _len3, _len4, _ref, _ref2, _ref3, _ref4;
|
422
|
+
output = [];
|
423
|
+
if (this.silent) return output;
|
424
|
+
if (this.children.length === 0) {
|
425
|
+
if (this.opener && this.closer) {
|
426
|
+
tag = this.getOpener();
|
427
|
+
tag.text += this.getCloser().text;
|
428
|
+
output.push(tag);
|
429
|
+
} else {
|
430
|
+
if (!this.preserve && this.isPreserved()) {
|
431
|
+
output.push(this.getOpener());
|
432
|
+
} else {
|
433
|
+
output.push(this.getOpener());
|
434
|
+
}
|
435
|
+
}
|
436
|
+
} else {
|
437
|
+
if (this.opener && this.closer) {
|
438
|
+
if (this.preserve) {
|
439
|
+
preserve = this.getOpener().text;
|
440
|
+
_ref = this.children;
|
441
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
442
|
+
child = _ref[_i];
|
443
|
+
preserve += "" + (child.render()[0].text) + "\\n" + (w(this.blockLevel));
|
444
|
+
}
|
445
|
+
preserve = preserve.replace(/\\n\s*$/, '');
|
446
|
+
preserve += this.getCloser().text;
|
447
|
+
output.push(this.markText(preserve));
|
448
|
+
} else {
|
449
|
+
output.push(this.getOpener());
|
450
|
+
_ref2 = this.children;
|
451
|
+
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
452
|
+
child = _ref2[_j];
|
453
|
+
output = output.concat(child.render());
|
454
|
+
}
|
455
|
+
output.push(this.getCloser());
|
456
|
+
}
|
457
|
+
} else if (this.opener) {
|
458
|
+
output.push(this.getOpener());
|
459
|
+
_ref3 = this.children;
|
460
|
+
for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) {
|
461
|
+
child = _ref3[_k];
|
462
|
+
output = output.concat(child.render());
|
463
|
+
}
|
464
|
+
} else {
|
465
|
+
_ref4 = this.children;
|
466
|
+
for (_l = 0, _len4 = _ref4.length; _l < _len4; _l++) {
|
467
|
+
child = _ref4[_l];
|
468
|
+
output.push(this.markText(child.render().text));
|
469
|
+
}
|
470
|
+
}
|
366
471
|
}
|
367
472
|
return output;
|
368
473
|
};
|
474
|
+
|
369
475
|
return Node;
|
476
|
+
|
370
477
|
})();
|
478
|
+
|
371
479
|
}).call(this);
|
372
480
|
|
373
481
|
});
|
374
482
|
|
375
483
|
require.define("/helper.js", function (require, module, exports, __dirname, __filename) {
|
376
|
-
|
484
|
+
|
377
485
|
module.exports = {
|
378
486
|
whitespace: function(n) {
|
379
487
|
var a;
|
@@ -384,115 +492,161 @@ require.define("/helper.js", function (require, module, exports, __dirname, __fi
|
|
384
492
|
}
|
385
493
|
return a.join('');
|
386
494
|
},
|
387
|
-
|
388
|
-
|
495
|
+
escapeQuotes: function(text) {
|
496
|
+
if (!text) return '';
|
497
|
+
return text.replace(/"/g, '\\"');
|
498
|
+
},
|
499
|
+
escapeHTML: function(text) {
|
500
|
+
if (!text) return '';
|
501
|
+
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"');
|
389
502
|
}
|
390
503
|
};
|
391
|
-
}).call(this);
|
392
504
|
|
393
505
|
});
|
394
506
|
|
395
507
|
require.define("/nodes/text.js", function (require, module, exports, __dirname, __filename) {
|
396
508
|
(function() {
|
397
|
-
var Node, Text;
|
398
|
-
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
|
399
|
-
|
400
|
-
function ctor() { this.constructor = child; }
|
401
|
-
ctor.prototype = parent.prototype;
|
402
|
-
child.prototype = new ctor;
|
403
|
-
child.__super__ = parent.prototype;
|
404
|
-
return child;
|
405
|
-
};
|
509
|
+
var Node, Text, eq;
|
510
|
+
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
|
511
|
+
|
406
512
|
Node = require('./node');
|
513
|
+
|
514
|
+
eq = require('../helper').escapeQuotes;
|
515
|
+
|
407
516
|
module.exports = Text = (function() {
|
517
|
+
|
408
518
|
__extends(Text, Node);
|
519
|
+
|
409
520
|
function Text() {
|
410
521
|
Text.__super__.constructor.apply(this, arguments);
|
411
522
|
}
|
523
|
+
|
412
524
|
Text.prototype.evaluate = function() {
|
413
|
-
return this.opener =
|
525
|
+
return this.opener = this.markText(eq(this.expression));
|
414
526
|
};
|
527
|
+
|
415
528
|
return Text;
|
529
|
+
|
416
530
|
})();
|
531
|
+
|
417
532
|
}).call(this);
|
418
533
|
|
419
534
|
});
|
420
535
|
|
421
536
|
require.define("/nodes/haml.js", function (require, module, exports, __dirname, __filename) {
|
422
537
|
(function() {
|
423
|
-
var Haml, Node,
|
424
|
-
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
|
425
|
-
|
426
|
-
function ctor() { this.constructor = child; }
|
427
|
-
ctor.prototype = parent.prototype;
|
428
|
-
child.prototype = new ctor;
|
429
|
-
child.__super__ = parent.prototype;
|
430
|
-
return child;
|
431
|
-
};
|
538
|
+
var Haml, Node, eq;
|
539
|
+
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
|
540
|
+
|
432
541
|
Node = require('./node');
|
433
|
-
|
542
|
+
|
543
|
+
eq = require('../helper').escapeQuotes;
|
544
|
+
|
434
545
|
module.exports = Haml = (function() {
|
546
|
+
|
435
547
|
__extends(Haml, Node);
|
436
|
-
|
437
|
-
function Haml(
|
438
|
-
this
|
439
|
-
Haml.__super__.constructor.call(this, expression, block_level, code_block_level);
|
548
|
+
|
549
|
+
function Haml() {
|
550
|
+
Haml.__super__.constructor.apply(this, arguments);
|
440
551
|
}
|
552
|
+
|
553
|
+
Haml.selfCloseTags = ['meta', 'img', 'link', 'br', 'hr', 'input', 'area', 'param', 'col', 'base'];
|
554
|
+
|
555
|
+
Haml.preserveTags = ['pre', 'textarea'];
|
556
|
+
|
441
557
|
Haml.prototype.evaluate = function() {
|
442
|
-
var
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
this.opener = "" + this.cw + "o.push \"" + this.hw + (qe(htmlTagPrefix)) + ">";
|
447
|
-
this.closer = "" + this.cw + "o.push \"" + this.hw + "</" + parsedExpression.tag + ">\"";
|
558
|
+
var code, prefix, tokens;
|
559
|
+
tokens = this.parseExpression(this.expression);
|
560
|
+
if (tokens.doctype) {
|
561
|
+
return this.opener = this.markText("" + (eq(this.buildDocType(tokens.doctype))));
|
448
562
|
} else {
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
563
|
+
if (this.isNotSelfClosing(tokens.tag)) {
|
564
|
+
prefix = eq(this.buildHtmlTagPrefix(tokens));
|
565
|
+
if (tokens.assignment) {
|
566
|
+
code = this.escapeHtml ? "\#{e " + tokens.assignment + "}" : "\#{" + tokens.assignment + "}";
|
567
|
+
this.opener = this.markText("" + prefix + ">" + code);
|
568
|
+
return this.closer = this.markText("</" + tokens.tag + ">");
|
569
|
+
} else if (tokens.text) {
|
570
|
+
this.opener = this.markText("" + prefix + ">" + tokens.text);
|
571
|
+
return this.closer = this.markText("</" + tokens.tag + ">");
|
572
|
+
} else {
|
573
|
+
this.opener = this.markText(prefix + '>');
|
574
|
+
return this.closer = this.markText("</" + tokens.tag + ">");
|
575
|
+
}
|
576
|
+
} else {
|
577
|
+
tokens.tag = tokens.tag.replace(/\/$/, '');
|
578
|
+
prefix = eq(this.buildHtmlTagPrefix(tokens));
|
579
|
+
return this.opener = this.markText("" + prefix + (this.format === 'xhtml' ? ' /' : '') + ">");
|
580
|
+
}
|
453
581
|
}
|
454
|
-
return this.opener += '"';
|
455
582
|
};
|
583
|
+
|
456
584
|
Haml.prototype.parseExpression = function(exp) {
|
457
|
-
var
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
480
|
-
pair = _ref[_i];
|
481
|
-
tagParts.push("" + pair.key + "=" + pair.value);
|
585
|
+
var attribute, attributes, classes, id, tag, _i, _len, _ref, _ref2;
|
586
|
+
tag = this.parseTag(exp);
|
587
|
+
if (Haml.preserveTags.indexOf(tag.tag) !== -1) this.preserve = true;
|
588
|
+
id = (_ref = tag.ids) != null ? _ref.pop() : void 0;
|
589
|
+
classes = tag.classes;
|
590
|
+
attributes = [];
|
591
|
+
if (tag.attributes) {
|
592
|
+
_ref2 = tag.attributes;
|
593
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
594
|
+
attribute = _ref2[_i];
|
595
|
+
if (attribute.key === 'id') {
|
596
|
+
if (id) {
|
597
|
+
id += '_' + attribute.value;
|
598
|
+
} else {
|
599
|
+
id = attribute.value;
|
600
|
+
}
|
601
|
+
} else if (attribute.key === 'class') {
|
602
|
+
classes || (classes = []);
|
603
|
+
classes.push(attribute.value);
|
604
|
+
} else {
|
605
|
+
attributes.push(attribute);
|
606
|
+
}
|
482
607
|
}
|
483
608
|
}
|
484
|
-
return
|
609
|
+
return {
|
610
|
+
doctype: tag.doctype,
|
611
|
+
tag: tag.tag,
|
612
|
+
id: id,
|
613
|
+
classes: classes,
|
614
|
+
text: tag.text,
|
615
|
+
attributes: attributes,
|
616
|
+
assignment: tag.assignment
|
617
|
+
};
|
485
618
|
};
|
619
|
+
|
486
620
|
Haml.prototype.parseTag = function(exp) {
|
487
|
-
var classes, id, ids, klass, tag,
|
621
|
+
var assignment, attributes, classes, doctype, haml, id, ids, klass, tag, text, tokens, whitespace, _ref, _ref2, _ref3;
|
488
622
|
try {
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
623
|
+
doctype = (_ref = exp.match(/^(\!{3}.*)/)) != null ? _ref[1] : void 0;
|
624
|
+
if (doctype) {
|
625
|
+
return {
|
626
|
+
doctype: doctype
|
627
|
+
};
|
628
|
+
}
|
629
|
+
tokens = exp.match(/^((?:[#%\.][a-z0-9_:\-]*[\/]?)+)(?:([\(\{].*[\)\}])?([\<\>]{0,2})(?==)|([\(\{].*[\)\}])?([\<\>]{0,2}))(.*)?/i);
|
630
|
+
haml = tokens[1];
|
631
|
+
attributes = tokens[2] || tokens[4];
|
632
|
+
whitespace = tokens[3] || tokens[5];
|
633
|
+
if (tokens[6] && !tokens[6].match(/^=/)) {
|
634
|
+
text = tokens[6].replace(/^ /, '');
|
635
|
+
} else {
|
636
|
+
assignment = (_ref2 = tokens[6]) != null ? (_ref3 = _ref2.match(/\=\s*(\S+.*)$/)) != null ? _ref3[1] : void 0 : void 0;
|
637
|
+
}
|
638
|
+
if (whitespace) {
|
639
|
+
if (whitespace.indexOf('>') !== -1) this.wsRemoval.around = true;
|
640
|
+
if (whitespace.indexOf('<') !== -1) {
|
641
|
+
this.wsRemoval.inside = true;
|
642
|
+
this.preserve = true;
|
643
|
+
}
|
644
|
+
}
|
645
|
+
tag = haml.match(/\%([a-z_\-][a-z0-9_:\-]*[\/]?)/i);
|
646
|
+
ids = haml.match(/\#([a-z_\-][a-z0-9_\-]*)/gi);
|
647
|
+
classes = haml.match(/\.([a-z0-9_\-]*)/gi);
|
494
648
|
return {
|
495
|
-
tag: tag,
|
649
|
+
tag: tag ? tag[1] : 'div',
|
496
650
|
ids: ids ? (function() {
|
497
651
|
var _i, _len, _results;
|
498
652
|
_results = [];
|
@@ -510,241 +664,631 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
|
|
510
664
|
_results.push(klass.substr(1));
|
511
665
|
}
|
512
666
|
return _results;
|
513
|
-
})() : void 0
|
667
|
+
})() : void 0,
|
668
|
+
attributes: this.parseAttributes(attributes),
|
669
|
+
assignment: assignment,
|
670
|
+
text: text
|
514
671
|
};
|
515
672
|
} catch (error) {
|
516
673
|
throw "Unable to parse tag from " + exp + ": " + error;
|
517
674
|
}
|
518
675
|
};
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
676
|
+
|
677
|
+
Haml.prototype.parseAttributes = function(exp) {
|
678
|
+
var attributes, datas, findAttributes, key, match, quoted, value, _ref;
|
679
|
+
attributes = [];
|
680
|
+
if (exp === void 0) return attributes;
|
681
|
+
_ref = this.getDataAttributes(exp), exp = _ref[0], datas = _ref[1];
|
682
|
+
findAttributes = /(?:(['"]?\w+[\w:-]*['"]?)\s*=\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[\w@.]+)|(['"]?\w+[\w:-]*['"]?)\s*=>\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[-\w@.()'"]+)|(['"]?\w+[\w:-]*['"]?):\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[-\w@.()'"]+))/g;
|
683
|
+
while (match = findAttributes.exec(exp)) {
|
684
|
+
key = match[1] || match[3] || match[5];
|
685
|
+
value = match[2] || match[4] || match[6];
|
686
|
+
if (['false', '"false"', "'false'", '', '""', "''"].indexOf(value) === -1) {
|
687
|
+
if (['true', '"true"', "'true'"].indexOf(value) !== -1) {
|
688
|
+
value = "'" + key + "'";
|
689
|
+
} else if (!value.match(/^("|').*\1$/)) {
|
690
|
+
if (this.escapeAttributes) {
|
691
|
+
value = '\'#{ e(' + value + ') }\'';
|
692
|
+
} else {
|
693
|
+
value = '\'#{ ' + value + ' }\'';
|
694
|
+
}
|
528
695
|
}
|
529
|
-
|
530
|
-
|
531
|
-
|
696
|
+
if (quoted = value.match(/^("|')(.*)\1$/)) value = quoted[2];
|
697
|
+
if (quoted = key.match(/^("|')(.*)\1$/)) key = quoted[2];
|
698
|
+
attributes.push({
|
699
|
+
key: key,
|
700
|
+
value: value
|
701
|
+
});
|
532
702
|
}
|
533
|
-
if (assignment) {
|
534
|
-
assignment = assignment[1];
|
535
|
-
}
|
536
|
-
pairs = this.parseAttributes(attributesExp);
|
537
703
|
}
|
538
|
-
return
|
539
|
-
assignment: assignment,
|
540
|
-
pairs: pairs || []
|
541
|
-
};
|
704
|
+
return attributes.concat(datas);
|
542
705
|
};
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
attributes =
|
706
|
+
|
707
|
+
Haml.prototype.getDataAttributes = function(exp) {
|
708
|
+
var attribute, attributes, data, _i, _len;
|
709
|
+
data = /:?data:?\s*(?:=>\s*)?\{([^}]*)\},?/gi.exec(exp);
|
710
|
+
if (!(data != null ? data[1] : void 0)) return [exp, []];
|
711
|
+
exp = exp.replace(data[0], '');
|
712
|
+
attributes = this.parseAttributes(data[1]);
|
550
713
|
for (_i = 0, _len = attributes.length; _i < _len; _i++) {
|
551
714
|
attribute = attributes[_i];
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
715
|
+
attribute.key = "data-" + attribute.key;
|
716
|
+
}
|
717
|
+
return [exp, attributes];
|
718
|
+
};
|
719
|
+
|
720
|
+
Haml.prototype.buildHtmlTagPrefix = function(tokens) {
|
721
|
+
var attribute, classes, interpolation, klass, tagParts, _i, _j, _len, _len2, _ref, _ref2;
|
722
|
+
tagParts = ["<" + tokens.tag];
|
723
|
+
if (tokens.classes) {
|
724
|
+
classes = tokens.classes.sort().join(' ');
|
725
|
+
if (tokens.classes.length > 1 && classes.match(/#\{/)) {
|
726
|
+
classes = '#{ [';
|
727
|
+
_ref = tokens.classes;
|
728
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
729
|
+
klass = _ref[_i];
|
730
|
+
if (interpolation = klass.match(/#{(.*)}/)) {
|
731
|
+
classes += interpolation[1] + ',';
|
732
|
+
} else {
|
733
|
+
classes += "'" + klass + "',";
|
734
|
+
}
|
735
|
+
}
|
736
|
+
classes += '].sort().join(\' \') }';
|
737
|
+
}
|
738
|
+
tagParts.push("class='" + classes + "'");
|
739
|
+
}
|
740
|
+
if (tokens.id) tagParts.push("id='" + tokens.id + "'");
|
741
|
+
if (tokens.attributes) {
|
742
|
+
_ref2 = tokens.attributes;
|
743
|
+
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
744
|
+
attribute = _ref2[_j];
|
745
|
+
if (attribute.key !== attribute.value || this.format !== 'html5') {
|
746
|
+
tagParts.push("" + attribute.key + "=" + (this.quoteAttributeValue(attribute.value)));
|
747
|
+
} else {
|
748
|
+
tagParts.push("" + attribute.key);
|
749
|
+
}
|
557
750
|
}
|
558
|
-
value = pair[1].trim();
|
559
|
-
valueIsLiteral = value.match(/^("|').*\1$/);
|
560
|
-
value = value.replace(/,$/, '');
|
561
|
-
pairs.push({
|
562
|
-
key: key,
|
563
|
-
value: valueIsLiteral ? value : '"#{' + value + '}"'
|
564
|
-
});
|
565
751
|
}
|
566
|
-
return
|
752
|
+
return tagParts.join(' ');
|
753
|
+
};
|
754
|
+
|
755
|
+
Haml.prototype.quoteAttributeValue = function(value) {
|
756
|
+
var quoted;
|
757
|
+
if (value.indexOf("'") === -1) {
|
758
|
+
quoted = "'" + value + "'";
|
759
|
+
} else {
|
760
|
+
quoted = "\"" + value + "\"";
|
761
|
+
}
|
762
|
+
return quoted;
|
567
763
|
};
|
568
|
-
|
569
|
-
|
764
|
+
|
765
|
+
Haml.prototype.buildDocType = function(doctype) {
|
766
|
+
switch ("" + this.format + " " + doctype) {
|
767
|
+
case 'xhtml !!! XML':
|
768
|
+
return '<?xml version=\'1.0\' encoding=\'utf-8\' ?>';
|
769
|
+
case 'xhtml !!!':
|
770
|
+
return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
771
|
+
case 'xhtml !!! 1.1':
|
772
|
+
return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
|
773
|
+
case 'xhtml !!! mobile':
|
774
|
+
return '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">';
|
775
|
+
case 'xhtml !!! basic':
|
776
|
+
return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">';
|
777
|
+
case 'xhtml !!! frameset':
|
778
|
+
return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">';
|
779
|
+
case 'xhtml !!! 5':
|
780
|
+
case 'html5 !!!':
|
781
|
+
return '<!DOCTYPE html>';
|
782
|
+
case 'html5 !!! XML':
|
783
|
+
case 'html4 !!! XML':
|
784
|
+
return '';
|
785
|
+
case 'html4 !!!':
|
786
|
+
return '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
|
787
|
+
case 'html4 !!! frameset':
|
788
|
+
return '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">';
|
789
|
+
case 'html4 !!! strict':
|
790
|
+
return '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
|
791
|
+
}
|
792
|
+
};
|
793
|
+
|
794
|
+
Haml.prototype.isNotSelfClosing = function(tag) {
|
795
|
+
return Haml.selfCloseTags.indexOf(tag) === -1 && !tag.match(/\/$/);
|
570
796
|
};
|
797
|
+
|
571
798
|
return Haml;
|
799
|
+
|
572
800
|
})();
|
801
|
+
|
573
802
|
}).call(this);
|
574
803
|
|
575
804
|
});
|
576
805
|
|
577
806
|
require.define("/nodes/code.js", function (require, module, exports, __dirname, __filename) {
|
578
807
|
(function() {
|
579
|
-
var Code, Node
|
580
|
-
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
|
581
|
-
|
582
|
-
function ctor() { this.constructor = child; }
|
583
|
-
ctor.prototype = parent.prototype;
|
584
|
-
child.prototype = new ctor;
|
585
|
-
child.__super__ = parent.prototype;
|
586
|
-
return child;
|
587
|
-
};
|
808
|
+
var Code, Node;
|
809
|
+
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
|
810
|
+
|
588
811
|
Node = require('./node');
|
589
|
-
|
812
|
+
|
590
813
|
module.exports = Code = (function() {
|
814
|
+
|
591
815
|
__extends(Code, Node);
|
592
|
-
|
593
|
-
|
594
|
-
Code.__super__.constructor.
|
816
|
+
|
817
|
+
function Code() {
|
818
|
+
Code.__super__.constructor.apply(this, arguments);
|
595
819
|
}
|
820
|
+
|
596
821
|
Code.prototype.evaluate = function() {
|
597
|
-
var code,
|
598
|
-
|
599
|
-
|
822
|
+
var code, codeBlock, identifier;
|
823
|
+
codeBlock = this.expression.match(/(-|!=|\&=|=|~)\s?(.*)?/);
|
824
|
+
identifier = codeBlock[1];
|
825
|
+
code = codeBlock[2];
|
826
|
+
if (identifier === '-') {
|
827
|
+
this.opener = this.markRunningCode(code);
|
828
|
+
if (this.children.length !== 0 && this.opener.code.match(/(->|=>)/)) {
|
829
|
+
return this.closer = this.markRunningCode(" ''");
|
830
|
+
}
|
831
|
+
} else if (identifier === '~') {
|
832
|
+
return this.opener = this.markInsertingCode(this.findAndPreserve(code));
|
833
|
+
} else if (identifier === '&=' || (identifier === '=' && this.escapeHtml)) {
|
834
|
+
return this.opener = this.markInsertingCode(code, true);
|
835
|
+
} else if (identifier === '!=' || (identifier === '=' && !this.escapeHtml)) {
|
836
|
+
return this.opener = this.markInsertingCode(code);
|
837
|
+
}
|
600
838
|
};
|
839
|
+
|
840
|
+
Code.prototype.findAndPreserve = function(code) {
|
841
|
+
return code.replace(/<(pre|textarea)>(.*?)<\/\1>/g, function(text) {
|
842
|
+
return text.replace('\\n', '\&\#x000A;');
|
843
|
+
});
|
844
|
+
};
|
845
|
+
|
601
846
|
return Code;
|
847
|
+
|
848
|
+
})();
|
849
|
+
|
850
|
+
}).call(this);
|
851
|
+
|
852
|
+
});
|
853
|
+
|
854
|
+
require.define("/nodes/comment.js", function (require, module, exports, __dirname, __filename) {
|
855
|
+
(function() {
|
856
|
+
var Comment, Node;
|
857
|
+
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
|
858
|
+
|
859
|
+
Node = require('./node');
|
860
|
+
|
861
|
+
module.exports = Comment = (function() {
|
862
|
+
|
863
|
+
__extends(Comment, Node);
|
864
|
+
|
865
|
+
function Comment() {
|
866
|
+
Comment.__super__.constructor.apply(this, arguments);
|
867
|
+
}
|
868
|
+
|
869
|
+
Comment.prototype.evaluate = function() {
|
870
|
+
var comment, expression, identifier, _ref;
|
871
|
+
_ref = this.expression.match(/(-#|\/\[|\/)\s?(.*)?/), expression = _ref[0], identifier = _ref[1], comment = _ref[2];
|
872
|
+
switch (identifier) {
|
873
|
+
case '-#':
|
874
|
+
this.silent = true;
|
875
|
+
return this.opener = this.markText('');
|
876
|
+
case '\/[':
|
877
|
+
this.opener = this.markText("<!--[" + comment + ">");
|
878
|
+
return this.closer = this.markText('<![endif]-->');
|
879
|
+
case '\/':
|
880
|
+
if (comment) {
|
881
|
+
this.opener = this.markText("<!-- " + comment);
|
882
|
+
return this.closer = this.markText(' -->');
|
883
|
+
} else {
|
884
|
+
this.opener = this.markText("<!--");
|
885
|
+
return this.closer = this.markText('-->');
|
886
|
+
}
|
887
|
+
}
|
888
|
+
};
|
889
|
+
|
890
|
+
return Comment;
|
891
|
+
|
892
|
+
})();
|
893
|
+
|
894
|
+
}).call(this);
|
895
|
+
|
896
|
+
});
|
897
|
+
|
898
|
+
require.define("/nodes/filter.js", function (require, module, exports, __dirname, __filename) {
|
899
|
+
(function() {
|
900
|
+
var Filter, Node, w;
|
901
|
+
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
|
902
|
+
|
903
|
+
Node = require('./node');
|
904
|
+
|
905
|
+
w = require('../helper').whitespace;
|
906
|
+
|
907
|
+
module.exports = Filter = (function() {
|
908
|
+
|
909
|
+
__extends(Filter, Node);
|
910
|
+
|
911
|
+
function Filter() {
|
912
|
+
Filter.__super__.constructor.apply(this, arguments);
|
913
|
+
}
|
914
|
+
|
915
|
+
Filter.prototype.evaluate = function() {
|
916
|
+
var _ref;
|
917
|
+
return this.filter = (_ref = this.expression.match(/:(escaped|preserve|css|javascript|coffeescript|plain|cdata|coffeescript)(.*)?/)) != null ? _ref[1] : void 0;
|
918
|
+
};
|
919
|
+
|
920
|
+
Filter.prototype.render = function() {
|
921
|
+
var child, indent, output, preserve, _i, _j, _len, _len2, _ref, _ref2;
|
922
|
+
output = [];
|
923
|
+
switch (this.filter) {
|
924
|
+
case 'escaped':
|
925
|
+
_ref = this.children;
|
926
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
927
|
+
child = _ref[_i];
|
928
|
+
output.push(this.markText(child.render()[0].text, true));
|
929
|
+
}
|
930
|
+
break;
|
931
|
+
case 'preserve':
|
932
|
+
preserve = '';
|
933
|
+
_ref2 = this.children;
|
934
|
+
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
935
|
+
child = _ref2[_j];
|
936
|
+
preserve += "" + (child.render()[0].text) + "
";
|
937
|
+
}
|
938
|
+
preserve = preserve.replace(/\&\#x000A;$/, '');
|
939
|
+
output.push(this.markText(preserve));
|
940
|
+
break;
|
941
|
+
case 'plain':
|
942
|
+
this.renderFilterContent(0, output);
|
943
|
+
break;
|
944
|
+
case 'css':
|
945
|
+
if (this.format === 'html5') {
|
946
|
+
output.push(this.markText('<style>'));
|
947
|
+
} else {
|
948
|
+
output.push(this.markText('<style type=\'text/css\'>'));
|
949
|
+
}
|
950
|
+
if (this.format === 'xhtml') {
|
951
|
+
output.push(this.markText(' /*<![CDATA[*/'));
|
952
|
+
}
|
953
|
+
indent = this.format === 'xhtml' ? 2 : 1;
|
954
|
+
this.renderFilterContent(indent, output);
|
955
|
+
if (this.format === 'xhtml') output.push(this.markText(' /*]]>*/'));
|
956
|
+
output.push(this.markText('</style>'));
|
957
|
+
break;
|
958
|
+
case 'javascript':
|
959
|
+
if (this.format === 'html5') {
|
960
|
+
output.push(this.markText('<script>'));
|
961
|
+
} else {
|
962
|
+
output.push(this.markText('<script type=\'text/javascript\'>'));
|
963
|
+
}
|
964
|
+
if (this.format === 'xhtml') output.push(this.markText(' //<![CDATA['));
|
965
|
+
indent = this.format === 'xhtml' ? 2 : 1;
|
966
|
+
this.renderFilterContent(indent, output);
|
967
|
+
if (this.format === 'xhtml') output.push(this.markText(' //]]>'));
|
968
|
+
output.push(this.markText('</script>'));
|
969
|
+
break;
|
970
|
+
case 'cdata':
|
971
|
+
output.push(this.markText('<![CDATA['));
|
972
|
+
this.renderFilterContent(2, output);
|
973
|
+
output.push(this.markText(']]>'));
|
974
|
+
break;
|
975
|
+
case 'coffeescript':
|
976
|
+
this.renderFilterContent(0, output, 'run');
|
977
|
+
}
|
978
|
+
return output;
|
979
|
+
};
|
980
|
+
|
981
|
+
Filter.prototype.renderFilterContent = function(indent, output, type) {
|
982
|
+
var child, content, e, empty, line, _i, _j, _len, _len2, _ref, _results;
|
983
|
+
if (type == null) type = 'text';
|
984
|
+
content = [];
|
985
|
+
empty = 0;
|
986
|
+
_ref = this.children;
|
987
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
988
|
+
child = _ref[_i];
|
989
|
+
content.push(child.render()[0].text);
|
990
|
+
}
|
991
|
+
_results = [];
|
992
|
+
for (_j = 0, _len2 = content.length; _j < _len2; _j++) {
|
993
|
+
line = content[_j];
|
994
|
+
if (line === '') {
|
995
|
+
_results.push(empty += 1);
|
996
|
+
} else {
|
997
|
+
switch (type) {
|
998
|
+
case 'text':
|
999
|
+
for (e = 0; 0 <= empty ? e < empty : e > empty; 0 <= empty ? e++ : e--) {
|
1000
|
+
output.push(this.markText(""));
|
1001
|
+
}
|
1002
|
+
output.push(this.markText("" + (w(indent)) + line));
|
1003
|
+
break;
|
1004
|
+
case 'run':
|
1005
|
+
output.push(this.markRunningCode("" + line));
|
1006
|
+
}
|
1007
|
+
_results.push(empty = 0);
|
1008
|
+
}
|
1009
|
+
}
|
1010
|
+
return _results;
|
1011
|
+
};
|
1012
|
+
|
1013
|
+
return Filter;
|
1014
|
+
|
602
1015
|
})();
|
1016
|
+
|
603
1017
|
}).call(this);
|
604
1018
|
|
605
1019
|
});
|
606
1020
|
|
607
1021
|
require.define("/compiler.js", function (require, module, exports, __dirname, __filename) {
|
608
1022
|
(function() {
|
609
|
-
var Code, Compiler, Haml, Node, Text;
|
610
|
-
|
1023
|
+
var Code, Comment, Compiler, Filter, Haml, Node, Text, w;
|
1024
|
+
|
611
1025
|
Node = require('./nodes/node');
|
1026
|
+
|
612
1027
|
Text = require('./nodes/text');
|
1028
|
+
|
613
1029
|
Haml = require('./nodes/haml');
|
1030
|
+
|
614
1031
|
Code = require('./nodes/code');
|
1032
|
+
|
1033
|
+
Comment = require('./nodes/comment');
|
1034
|
+
|
1035
|
+
Filter = require('./nodes/filter');
|
1036
|
+
|
1037
|
+
w = require('./helper').whitespace;
|
1038
|
+
|
615
1039
|
module.exports = Compiler = (function() {
|
1040
|
+
|
616
1041
|
function Compiler(options) {
|
617
|
-
var _base, _ref;
|
1042
|
+
var _base, _base2, _base3, _ref, _ref2, _ref3;
|
618
1043
|
this.options = options != null ? options : {};
|
619
|
-
if ((_ref = (_base = this.options).
|
620
|
-
_base.
|
1044
|
+
if ((_ref = (_base = this.options).escapeHtml) == null) {
|
1045
|
+
_base.escapeHtml = true;
|
621
1046
|
}
|
622
|
-
|
623
|
-
|
624
|
-
var node;
|
625
|
-
if (expression.match(/^(-|=|!=)\s*(.*)/)) {
|
626
|
-
node = new Code(expression, current_block_level, current_code_block_level, this.options.escape_html);
|
627
|
-
} else if (expression.match(/^(%|#|\.)(.*)/)) {
|
628
|
-
node = new Haml(expression, current_block_level, current_code_block_level, this.options.escape_html);
|
629
|
-
} else {
|
630
|
-
node = new Text(expression, current_block_level, current_code_block_level);
|
1047
|
+
if ((_ref2 = (_base2 = this.options).escapeAttributes) == null) {
|
1048
|
+
_base2.escapeAttributes = true;
|
631
1049
|
}
|
632
|
-
|
633
|
-
|
634
|
-
Compiler.prototype.update_code_block_level = function(node) {
|
635
|
-
if (node instanceof Code) {
|
636
|
-
return this.current_code_block_level = node.code_block_level + 1;
|
637
|
-
} else {
|
638
|
-
return this.current_code_block_level = node.code_block_level;
|
1050
|
+
if ((_ref3 = (_base3 = this.options).format) == null) {
|
1051
|
+
_base3.format = 'html5';
|
639
1052
|
}
|
1053
|
+
}
|
1054
|
+
|
1055
|
+
Compiler.prototype.indentChanged = function() {
|
1056
|
+
return this.currentIndent !== this.previousIndent;
|
640
1057
|
};
|
641
|
-
|
642
|
-
|
1058
|
+
|
1059
|
+
Compiler.prototype.isIndent = function() {
|
1060
|
+
return this.currentIndent > this.previousIndent;
|
643
1061
|
};
|
644
|
-
|
645
|
-
|
1062
|
+
|
1063
|
+
Compiler.prototype.updateTabSize = function() {
|
1064
|
+
if (this.tabSize === 0) {
|
1065
|
+
return this.tabSize = this.currentIndent - this.previousIndent;
|
1066
|
+
}
|
646
1067
|
};
|
647
|
-
|
648
|
-
|
649
|
-
|
1068
|
+
|
1069
|
+
Compiler.prototype.updateBlockLevel = function() {
|
1070
|
+
this.currentBlockLevel = this.currentIndent / this.tabSize;
|
1071
|
+
if (this.currentBlockLevel - Math.floor(this.currentBlockLevel) > 0) {
|
1072
|
+
throw "Indentation error in line " + this.lineNumber;
|
650
1073
|
}
|
1074
|
+
if ((this.currentIndent - this.previousIndent) / this.tabSize > 1) {
|
1075
|
+
throw "Block level too deep in line " + this.lineNumber;
|
1076
|
+
}
|
1077
|
+
return this.delta = this.previousBlockLevel - this.currentBlockLevel;
|
651
1078
|
};
|
652
|
-
|
653
|
-
|
654
|
-
if (
|
655
|
-
|
1079
|
+
|
1080
|
+
Compiler.prototype.updateCodeBlockLevel = function(node) {
|
1081
|
+
if (node instanceof Code) {
|
1082
|
+
return this.currentCodeBlockLevel = node.codeBlockLevel + 1;
|
1083
|
+
} else {
|
1084
|
+
return this.currentCodeBlockLevel = node.codeBlockLevel;
|
656
1085
|
}
|
657
|
-
|
658
|
-
|
1086
|
+
};
|
1087
|
+
|
1088
|
+
Compiler.prototype.updateParent = function() {
|
1089
|
+
if (this.isIndent()) {
|
1090
|
+
return this.pushParent();
|
1091
|
+
} else {
|
1092
|
+
return this.popParent();
|
659
1093
|
}
|
660
|
-
return this.delta = this.previous_block_level - this.current_block_level;
|
661
1094
|
};
|
662
|
-
|
663
|
-
|
664
|
-
|
1095
|
+
|
1096
|
+
Compiler.prototype.pushParent = function() {
|
1097
|
+
this.stack.push(this.parentNode);
|
1098
|
+
return this.parentNode = this.node;
|
665
1099
|
};
|
666
|
-
|
1100
|
+
|
1101
|
+
Compiler.prototype.popParent = function() {
|
667
1102
|
var i, _ref, _results;
|
668
1103
|
_results = [];
|
669
1104
|
for (i = 0, _ref = this.delta - 1; 0 <= _ref ? i <= _ref : i >= _ref; 0 <= _ref ? i++ : i--) {
|
670
|
-
_results.push(this.
|
1105
|
+
_results.push(this.parentNode = this.stack.pop());
|
671
1106
|
}
|
672
1107
|
return _results;
|
673
1108
|
};
|
1109
|
+
|
1110
|
+
Compiler.prototype.getNodeOptions = function(override) {
|
1111
|
+
if (override == null) override = {};
|
1112
|
+
return {
|
1113
|
+
parentNode: override.parentNode || this.parentNode,
|
1114
|
+
blockLevel: override.blockLevel || this.currentBlockLevel,
|
1115
|
+
codeBlockLevel: override.codeBlockLevel || this.currentCodeBlockLevel,
|
1116
|
+
escapeHtml: override.escapeHtml || this.options.escapeHtml,
|
1117
|
+
escapeAttributes: override.escapeAttributes || this.options.escapeAttributes,
|
1118
|
+
format: override.format || this.options.format
|
1119
|
+
};
|
1120
|
+
};
|
1121
|
+
|
1122
|
+
Compiler.prototype.nodeFactory = function(expression) {
|
1123
|
+
var node, options, _ref;
|
1124
|
+
if (expression == null) expression = '';
|
1125
|
+
options = this.getNodeOptions();
|
1126
|
+
if (expression.match(/^:(escaped|preserve|css|javascript|plain|cdata|coffeescript)/)) {
|
1127
|
+
node = new Filter(expression, options);
|
1128
|
+
} else if (expression.match(/^(\/|-#)(.*)/)) {
|
1129
|
+
node = new Comment(expression, options);
|
1130
|
+
} else if (expression.match(/^(-#|-|=|!=|\&=|~)\s*(.*)/)) {
|
1131
|
+
node = new Code(expression, options);
|
1132
|
+
} else if (expression.match(/^(%|#|\.|\!)(.*)/)) {
|
1133
|
+
node = new Haml(expression, options);
|
1134
|
+
} else {
|
1135
|
+
node = new Text(expression, options);
|
1136
|
+
}
|
1137
|
+
if ((_ref = options.parentNode) != null) _ref.addChild(node);
|
1138
|
+
return node;
|
1139
|
+
};
|
1140
|
+
|
674
1141
|
Compiler.prototype.parse = function(source) {
|
675
|
-
|
676
|
-
this.
|
677
|
-
this.
|
678
|
-
this.current_block_level = this.previous_block_level = 0;
|
679
|
-
this.current_code_block_level = this.previous_code_block_level = 2;
|
680
|
-
this.root = this.parent_node = new Node("", this.current_block_level, this.current_code_block_level);
|
1142
|
+
var attributes, expression, line, lines, result, text, whitespace, _ref;
|
1143
|
+
this.line_number = this.previousIndent = this.tabSize = this.currentBlockLevel = this.previousBlockLevel = 0;
|
1144
|
+
this.currentCodeBlockLevel = this.previousCodeBlockLevel = 2;
|
681
1145
|
this.node = null;
|
682
1146
|
this.stack = [];
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
1147
|
+
this.root = this.parentNode = new Node('', this.getNodeOptions());
|
1148
|
+
lines = source.split("\n");
|
1149
|
+
while ((line = lines.shift()) !== void 0) {
|
1150
|
+
if ((this.node instanceof Filter) && !this.exitFilter) {
|
1151
|
+
if (line === '') {
|
1152
|
+
this.node.addChild(new Text('', this.getNodeOptions({
|
1153
|
+
parentNode: this.node
|
1154
|
+
})));
|
1155
|
+
} else {
|
1156
|
+
result = line.match(/^(\s*)(.*)/);
|
1157
|
+
whitespace = result[1];
|
1158
|
+
expression = result[2];
|
1159
|
+
if (this.node.blockLevel >= (whitespace.length / 2)) {
|
1160
|
+
this.exitFilter = true;
|
1161
|
+
lines.unshift(line);
|
1162
|
+
continue;
|
1163
|
+
}
|
1164
|
+
text = line.match(RegExp("^\\s{" + ((this.node.blockLevel * 2) + 2) + "}(.*)"));
|
1165
|
+
if (text) {
|
1166
|
+
this.node.addChild(new Text(text[1], this.getNodeOptions({
|
1167
|
+
parentNode: this.node
|
1168
|
+
})));
|
700
1169
|
}
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
1170
|
+
}
|
1171
|
+
} else {
|
1172
|
+
this.exitFilter = false;
|
1173
|
+
result = line.match(/^(\s*)(.*)/);
|
1174
|
+
whitespace = result[1];
|
1175
|
+
expression = result[2];
|
1176
|
+
if (line === '') continue;
|
1177
|
+
while (/^%.*[{(]/.test(expression) && !/^(\s*)[%<]/.test(lines[0]) && /(?:(['"]?\w+[\w:-]*['"]?)\s*=\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[\w@.]+)|(['"]?\w+[\w:-]*['"]?)\s*=>\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[-\w@.()'"]+)|(['"]?\w+[\w:-]*['"]?):\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[-\w@.()'"]+))/.test(lines[0])) {
|
1178
|
+
attributes = lines.shift();
|
1179
|
+
expression += ' ' + attributes.match(/^(\s*)(.*)/)[2];
|
705
1180
|
this.line_number++;
|
706
1181
|
}
|
1182
|
+
if (expression.match(/(\s)+\|$/)) {
|
1183
|
+
expression = expression.replace(/(\s)+\|$/, ' ');
|
1184
|
+
while ((_ref = lines[0]) != null ? _ref.match(/(\s)+\|$/) : void 0) {
|
1185
|
+
expression += lines.shift().match(/^(\s*)(.*)/)[2].replace(/(\s)+\|$/, '');
|
1186
|
+
this.line_number++;
|
1187
|
+
}
|
1188
|
+
}
|
1189
|
+
this.currentIndent = whitespace.length;
|
1190
|
+
if (this.indentChanged()) {
|
1191
|
+
this.updateTabSize();
|
1192
|
+
this.updateBlockLevel();
|
1193
|
+
this.updateParent();
|
1194
|
+
this.updateCodeBlockLevel(this.parentNode);
|
1195
|
+
}
|
1196
|
+
this.node = this.nodeFactory(expression);
|
1197
|
+
this.previousBlockLevel = this.currentBlockLevel;
|
1198
|
+
this.previousIndent = this.currentIndent;
|
707
1199
|
}
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
s = s.replace(/(\s|-)+/g, "_");
|
712
|
-
return s;
|
1200
|
+
this.line_number++;
|
1201
|
+
}
|
1202
|
+
return this.evaluate(this.root);
|
713
1203
|
};
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
1204
|
+
|
1205
|
+
Compiler.prototype.evaluate = function(node) {
|
1206
|
+
var child, _i, _len, _ref;
|
1207
|
+
_ref = node.children;
|
1208
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1209
|
+
child = _ref[_i];
|
1210
|
+
this.evaluate(child);
|
718
1211
|
}
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
1212
|
+
return node.evaluate();
|
1213
|
+
};
|
1214
|
+
|
1215
|
+
Compiler.prototype.render = function(templateName, namespace) {
|
1216
|
+
var code, escapeFn, output, segment, segments, _i, _len;
|
1217
|
+
if (namespace == null) namespace = 'window.HAML';
|
1218
|
+
output = '';
|
1219
|
+
segments = ("" + namespace + "." + templateName).replace(/(\s|-)+/g, '_').split(/\./);
|
1220
|
+
templateName = segments.pop();
|
1221
|
+
namespace = segments.shift();
|
1222
|
+
if (segments.length !== 0) {
|
1223
|
+
for (_i = 0, _len = segments.length; _i < _len; _i++) {
|
1224
|
+
segment = segments[_i];
|
1225
|
+
namespace += "." + segment;
|
1226
|
+
output += "" + namespace + " ?= {}\n";
|
726
1227
|
}
|
1228
|
+
} else {
|
1229
|
+
output += "" + namespace + " ?= {}\n";
|
727
1230
|
}
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
output += "window." + namespace + " ?= {}\n";
|
1231
|
+
if (this.options.customHtmlEscape) {
|
1232
|
+
escapeFn = this.options.customHtmlEscape;
|
1233
|
+
} else {
|
1234
|
+
escapeFn = "" + namespace + ".htmlEscape";
|
1235
|
+
output += escapeFn + '||= (text) ->\n "#{ text }"\n .replace(/&/g, \'&\')\n .replace(/</g, \'<\')\n .replace(/>/g, \'>\')\n .replace(/\'/g, \''\')\n .replace(/\"/g, \'"\')\n';
|
734
1236
|
}
|
735
|
-
output += "
|
1237
|
+
output += "" + namespace + "['" + templateName + "'] = (context) ->\n";
|
736
1238
|
output += " fn = (context) ->\n";
|
737
|
-
output += " o = []";
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
output += this.
|
742
|
-
output += "
|
743
|
-
output += " return fn.call(context)\n";
|
1239
|
+
output += " o = []\n";
|
1240
|
+
output += " e = " + escapeFn + "\n";
|
1241
|
+
code = this.createCode();
|
1242
|
+
output += "" + code + "\n";
|
1243
|
+
output += " return o.join(\"\\n\")" + (this.cleanupWhitespace(code)) + "\n";
|
1244
|
+
output += " return fn.call(context)";
|
744
1245
|
return output;
|
745
1246
|
};
|
1247
|
+
|
1248
|
+
Compiler.prototype.createCode = function() {
|
1249
|
+
var child, code, line, _i, _j, _len, _len2, _ref, _ref2;
|
1250
|
+
code = [];
|
1251
|
+
this.lines = [];
|
1252
|
+
_ref = this.root.children;
|
1253
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1254
|
+
child = _ref[_i];
|
1255
|
+
this.lines = this.lines.concat(child.render());
|
1256
|
+
}
|
1257
|
+
_ref2 = this.lines;
|
1258
|
+
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
1259
|
+
line = _ref2[_j];
|
1260
|
+
if (line !== null) {
|
1261
|
+
switch (line.type) {
|
1262
|
+
case 'text':
|
1263
|
+
code.push("" + (w(line.cw)) + "o.push \"" + (w(line.hw)) + line.text + "\"");
|
1264
|
+
break;
|
1265
|
+
case 'run':
|
1266
|
+
code.push("" + (w(line.cw)) + line.code);
|
1267
|
+
break;
|
1268
|
+
case 'insert':
|
1269
|
+
if (line.hw === 0) {
|
1270
|
+
code.push("" + (w(line.cw)) + "o.push " + (w(line.escape) ? 'e ' : '') + line.code);
|
1271
|
+
} else {
|
1272
|
+
code.push("" + (w(line.cw)) + "o.push " + (w(line.escape) ? 'e' : '') + " \"" + (w(line.hw - line.cw + 2)) + "\" + " + line.code);
|
1273
|
+
}
|
1274
|
+
}
|
1275
|
+
}
|
1276
|
+
}
|
1277
|
+
return code.join('\n');
|
1278
|
+
};
|
1279
|
+
|
1280
|
+
Compiler.prototype.cleanupWhitespace = function(code) {
|
1281
|
+
if (/\u0091|\u0092/.test(code)) {
|
1282
|
+
return ".replace(/[\\s\\n]*\\u0091/mg, '').replace(/\\u0092[\\s\\n]*/mg, '')";
|
1283
|
+
} else {
|
1284
|
+
return '';
|
1285
|
+
}
|
1286
|
+
};
|
1287
|
+
|
746
1288
|
return Compiler;
|
1289
|
+
|
747
1290
|
})();
|
1291
|
+
|
748
1292
|
}).call(this);
|
749
1293
|
|
750
1294
|
});
|