haml_coffee_assets 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -4
- data/lib/haml_coffee_assets/engine.rb +2 -0
- data/lib/haml_coffee_assets/haml_coffee.rb +9 -3
- data/lib/haml_coffee_assets/haml_coffee_assets.js +14 -6
- data/lib/haml_coffee_assets/haml_coffee_template.rb +2 -1
- data/lib/haml_coffee_assets/version.rb +1 -1
- data/lib/js/haml-coffee.js +389 -340
- metadata +19 -19
data/README.md
CHANGED
@@ -126,12 +126,23 @@ your `app/assets/javascripts/application.js.coffee`:
|
|
126
126
|
```coffeescript
|
127
127
|
#= require_tree ../templates
|
128
128
|
```
|
129
|
+
Now you can start to add your Haml Coffee templates to your template directory.
|
129
130
|
|
130
|
-
|
131
|
-
`.hamlc` extension to be recognized by Haml Coffee Assets.
|
131
|
+
### Sprocket JST processor template generation
|
132
132
|
|
133
|
-
|
134
|
-
|
133
|
+
* Extension: `.jst.hamlc`
|
134
|
+
|
135
|
+
When you give your templates the extension `.jst.hamlc`, Haml Coffee Assets will only generate the template function,
|
136
|
+
which then in turn will be further processed by the
|
137
|
+
[Sprocket JST processor](https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/jst_processor.rb).
|
138
|
+
This is the Rails way of asset processing and the only downside is that namespace definition is more cumbersome.
|
139
|
+
|
140
|
+
### Haml Coffee template generation
|
141
|
+
|
142
|
+
* Extension: `.hamlc`
|
143
|
+
|
144
|
+
If you omit the `.jst` and give your templates only a `.hamlc` extension, then Haml Coffee Assets will handle the
|
145
|
+
JavaScript template generation. With this approach you can easily define your own namespace with a simple configuration.
|
135
146
|
|
136
147
|
## Configuration
|
137
148
|
|
@@ -176,6 +187,24 @@ If you prefer another namespace, you can set it in your `config/application.rb`:
|
|
176
187
|
config.hamlcoffee.namespace = 'window.HAML'
|
177
188
|
```
|
178
189
|
|
190
|
+
You can even set a deep nested namespace like `window.templates.HAML` and Haml Coffee will handle creation all the way
|
191
|
+
down.
|
192
|
+
|
193
|
+
You can't use this configuration if you give your templates a `.jst.hamlc` extension, because the Sprockets JST
|
194
|
+
processor handles the template generation. In this case you have to subclass the JST processor:
|
195
|
+
|
196
|
+
```ruby
|
197
|
+
class MyJstProcessor < Sprockets::JstProcessor
|
198
|
+
def prepare
|
199
|
+
@namespace = 'MyApp.Tpl'
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
Foo::Application.assets.register_engine '.jst', MyJstProcessor
|
204
|
+
```
|
205
|
+
|
206
|
+
And you must make sure `MyApp` exists before any template is loaded.
|
207
|
+
|
179
208
|
#### Template name
|
180
209
|
|
181
210
|
The name under which the template can be addressed in the namespace depends not only from the filename, but also on
|
@@ -209,6 +238,15 @@ You can toggle HTML escaping in your `config/application.rb`:
|
|
209
238
|
config.hamlcoffee.escapeHtml = false
|
210
239
|
```
|
211
240
|
|
241
|
+
#### Clean values
|
242
|
+
|
243
|
+
Every value that is returned from inline CoffeeScript will be cleaned by default. The included implementation converts
|
244
|
+
`null` and `undefined` to an empty string. You can disable value cleaning in your `config/application.rb`:
|
245
|
+
|
246
|
+
```ruby
|
247
|
+
config.hamlcoffee.cleanValue = false
|
248
|
+
```
|
249
|
+
|
212
250
|
### Uglify generated HTML
|
213
251
|
|
214
252
|
By default all generated HTML is indented to have a nice reading experience. If you like to ignore indention to have a
|
@@ -14,6 +14,7 @@ module HamlCoffeeAssets
|
|
14
14
|
:uglify => false,
|
15
15
|
:escapeHtml => true,
|
16
16
|
:escapeAttributes => true,
|
17
|
+
:cleanValue => true,
|
17
18
|
:customHtmlEscape => 'HAML.escape',
|
18
19
|
:customCleanValue => 'HAML.cleanValue',
|
19
20
|
:customPreserve => 'HAML.escape',
|
@@ -40,6 +41,7 @@ module HamlCoffeeAssets
|
|
40
41
|
config.uglify = options[:uglify]
|
41
42
|
config.escapeHtml = options[:escapeHtml]
|
42
43
|
config.escapeAttributes = options[:escapeAttributes]
|
44
|
+
config.cleanValue = options[:cleanValue]
|
43
45
|
config.customHtmlEscape = options[:customHtmlEscape]
|
44
46
|
config.customCleanValue = options[:customCleanValue]
|
45
47
|
config.customPreserve = options[:customPreserve]
|
@@ -31,6 +31,11 @@ module HamlCoffeeAssets
|
|
31
31
|
mattr_accessor :escapeAttributes
|
32
32
|
self.escapeAttributes = true
|
33
33
|
|
34
|
+
# Clean inline CoffeeScript values
|
35
|
+
#
|
36
|
+
mattr_accessor :cleanValue
|
37
|
+
self.cleanValue = true
|
38
|
+
|
34
39
|
# Custom global HTML escaping function
|
35
40
|
#
|
36
41
|
mattr_accessor :customHtmlEscape
|
@@ -78,11 +83,12 @@ module HamlCoffeeAssets
|
|
78
83
|
#
|
79
84
|
# @param [String] name the template name
|
80
85
|
# @param [String] source the template source code
|
86
|
+
# @param [Boolean] jst if a JST template should be generated
|
81
87
|
# @return [String] the compiled template in JavaScript
|
82
88
|
#
|
83
|
-
def compile(name, source)
|
84
|
-
runtime.call('HamlCoffeeAssets.compile', name, source, HamlCoffee.namespace, HamlCoffee.format, HamlCoffee.uglify,
|
85
|
-
HamlCoffee.escapeHtml, HamlCoffee.escapeAttributes,
|
89
|
+
def compile(name, source, jst = true)
|
90
|
+
runtime.call('HamlCoffeeAssets.compile', name, source, jst, HamlCoffee.namespace, HamlCoffee.format, HamlCoffee.uglify,
|
91
|
+
HamlCoffee.escapeHtml, HamlCoffee.escapeAttributes, HamlCoffee.cleanValue,
|
86
92
|
HamlCoffee.customHtmlEscape, HamlCoffee.customCleanValue,
|
87
93
|
HamlCoffee.customPreserve, HamlCoffee.customFindAndPreserve,
|
88
94
|
HamlCoffee.preserveTags, HamlCoffee.selfCloseTags,
|
@@ -12,7 +12,7 @@ if (!String.prototype.trim) {
|
|
12
12
|
*/
|
13
13
|
var HamlCoffeeAssets = (function(){
|
14
14
|
|
15
|
-
var Compiler = require('/
|
15
|
+
var Compiler = require('/haml-coffee.js');
|
16
16
|
|
17
17
|
return {
|
18
18
|
|
@@ -22,6 +22,7 @@ var HamlCoffeeAssets = (function(){
|
|
22
22
|
* @param name [String] the name of the template that is registered to the namespace
|
23
23
|
* @param source [String] the template source code to be compiled
|
24
24
|
* @param namespace [String] the template namespace
|
25
|
+
* @param jst [Boolean] if a JST template should be generated
|
25
26
|
* @param format [String] output HTML format
|
26
27
|
* @param uglify [Boolean] skip HTML indention
|
27
28
|
* @param escapeHtml [Boolean] whether to escape HTML output by default or not
|
@@ -32,8 +33,8 @@ var HamlCoffeeAssets = (function(){
|
|
32
33
|
* @param selfCloseTags [String] comma separated list of tags to self-closing tags
|
33
34
|
* @param context [String] the name of the function to merge contexts
|
34
35
|
*/
|
35
|
-
compile: function(name, source, namespace, format, uglify,
|
36
|
-
escapeHtml, escapeAttributes,
|
36
|
+
compile: function(name, source, jst, namespace, format, uglify,
|
37
|
+
escapeHtml, escapeAttributes, cleanValue,
|
37
38
|
customHtmlEscape, customCleanValue, customPreserve, customFindAndPreserve,
|
38
39
|
preserveTags, selfCloseTags,
|
39
40
|
context) {
|
@@ -43,6 +44,7 @@ var HamlCoffeeAssets = (function(){
|
|
43
44
|
uglify: uglify,
|
44
45
|
escapeHtml: escapeHtml,
|
45
46
|
escapeAttributes: escapeAttributes,
|
47
|
+
cleanValue: cleanValue,
|
46
48
|
customHtmlEscape: customHtmlEscape,
|
47
49
|
customCleanValue: customCleanValue,
|
48
50
|
customPreserve: customPreserve,
|
@@ -53,13 +55,19 @@ var HamlCoffeeAssets = (function(){
|
|
53
55
|
|
54
56
|
compiler.parse(source);
|
55
57
|
|
56
|
-
var
|
58
|
+
var template;
|
59
|
+
|
60
|
+
if (jst) {
|
61
|
+
template = CoffeeScript.compile(compiler.render(name, namespace));
|
62
|
+
} else {
|
63
|
+
template = CoffeeScript.compile('(context) -> ( ->\n' + compiler.precompile().replace(/^(.*)$/mg, ' $1') + ').call(context)', { bare: true });
|
64
|
+
}
|
57
65
|
|
58
66
|
if (context !== '') {
|
59
|
-
|
67
|
+
template = template.replace('.call(context);', '.call(' + context +'(context));');
|
60
68
|
}
|
61
69
|
|
62
|
-
return
|
70
|
+
return template;
|
63
71
|
}
|
64
72
|
|
65
73
|
}
|
@@ -32,7 +32,8 @@ module HamlCoffeeAssets
|
|
32
32
|
# Compile the template.
|
33
33
|
#
|
34
34
|
def evaluate(scope, locals = { }, &block)
|
35
|
-
|
35
|
+
jst = scope.pathname.to_s =~ /\.jst\.hamlc$/ ? false : true
|
36
|
+
@output ||= HamlCoffee.compile(scope.logical_path, data, jst)
|
36
37
|
end
|
37
38
|
|
38
39
|
end
|
data/lib/js/haml-coffee.js
CHANGED
@@ -319,13 +319,346 @@ exports.extname = function(path) {
|
|
319
319
|
|
320
320
|
});
|
321
321
|
|
322
|
-
require.define("/
|
322
|
+
require.define("/haml-coffee.js", function (require, module, exports, __dirname, __filename) {
|
323
323
|
(function() {
|
324
|
-
var Node,
|
324
|
+
var Code, Comment, Filter, Haml, HamlCoffee, Node, Text, indent, whitespace;
|
325
|
+
|
326
|
+
Node = require('./nodes/node');
|
327
|
+
|
328
|
+
Text = require('./nodes/text');
|
329
|
+
|
330
|
+
Haml = require('./nodes/haml');
|
331
|
+
|
332
|
+
Code = require('./nodes/code');
|
333
|
+
|
334
|
+
Comment = require('./nodes/comment');
|
335
|
+
|
336
|
+
Filter = require('./nodes/filter');
|
337
|
+
|
338
|
+
whitespace = require('./util/text').whitespace;
|
339
|
+
|
340
|
+
indent = require('./util/text').indent;
|
341
|
+
|
342
|
+
module.exports = HamlCoffee = (function() {
|
343
|
+
|
344
|
+
function HamlCoffee(options) {
|
345
|
+
var _base, _base2, _base3, _base4, _base5, _base6, _base7, _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
|
346
|
+
this.options = options != null ? options : {};
|
347
|
+
if ((_ref = (_base = this.options).escapeHtml) == null) {
|
348
|
+
_base.escapeHtml = true;
|
349
|
+
}
|
350
|
+
if ((_ref2 = (_base2 = this.options).escapeAttributes) == null) {
|
351
|
+
_base2.escapeAttributes = true;
|
352
|
+
}
|
353
|
+
if ((_ref3 = (_base3 = this.options).cleanValue) == null) {
|
354
|
+
_base3.cleanValue = true;
|
355
|
+
}
|
356
|
+
if ((_ref4 = (_base4 = this.options).uglify) == null) _base4.uglify = false;
|
357
|
+
if ((_ref5 = (_base5 = this.options).format) == null) {
|
358
|
+
_base5.format = 'html5';
|
359
|
+
}
|
360
|
+
if ((_ref6 = (_base6 = this.options).preserveTags) == null) {
|
361
|
+
_base6.preserveTags = 'pre,textarea';
|
362
|
+
}
|
363
|
+
if ((_ref7 = (_base7 = this.options).selfCloseTags) == null) {
|
364
|
+
_base7.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base';
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
HamlCoffee.prototype.indentChanged = function() {
|
369
|
+
return this.currentIndent !== this.previousIndent;
|
370
|
+
};
|
371
|
+
|
372
|
+
HamlCoffee.prototype.isIndent = function() {
|
373
|
+
return this.currentIndent > this.previousIndent;
|
374
|
+
};
|
375
|
+
|
376
|
+
HamlCoffee.prototype.updateTabSize = function() {
|
377
|
+
if (this.tabSize === 0) {
|
378
|
+
return this.tabSize = this.currentIndent - this.previousIndent;
|
379
|
+
}
|
380
|
+
};
|
381
|
+
|
382
|
+
HamlCoffee.prototype.updateBlockLevel = function() {
|
383
|
+
this.currentBlockLevel = this.currentIndent / this.tabSize;
|
384
|
+
if (this.currentBlockLevel - Math.floor(this.currentBlockLevel) > 0) {
|
385
|
+
throw "Indentation error in line " + this.lineNumber;
|
386
|
+
}
|
387
|
+
if ((this.currentIndent - this.previousIndent) / this.tabSize > 1) {
|
388
|
+
throw "Block level too deep in line " + this.lineNumber;
|
389
|
+
}
|
390
|
+
return this.delta = this.previousBlockLevel - this.currentBlockLevel;
|
391
|
+
};
|
392
|
+
|
393
|
+
HamlCoffee.prototype.updateCodeBlockLevel = function(node) {
|
394
|
+
if (node instanceof Code) {
|
395
|
+
return this.currentCodeBlockLevel = node.codeBlockLevel + 1;
|
396
|
+
} else {
|
397
|
+
return this.currentCodeBlockLevel = node.codeBlockLevel;
|
398
|
+
}
|
399
|
+
};
|
400
|
+
|
401
|
+
HamlCoffee.prototype.updateParent = function() {
|
402
|
+
if (this.isIndent()) {
|
403
|
+
return this.pushParent();
|
404
|
+
} else {
|
405
|
+
return this.popParent();
|
406
|
+
}
|
407
|
+
};
|
408
|
+
|
409
|
+
HamlCoffee.prototype.pushParent = function() {
|
410
|
+
this.stack.push(this.parentNode);
|
411
|
+
return this.parentNode = this.node;
|
412
|
+
};
|
413
|
+
|
414
|
+
HamlCoffee.prototype.popParent = function() {
|
415
|
+
var i, _ref, _results;
|
416
|
+
_results = [];
|
417
|
+
for (i = 0, _ref = this.delta - 1; 0 <= _ref ? i <= _ref : i >= _ref; 0 <= _ref ? i++ : i--) {
|
418
|
+
_results.push(this.parentNode = this.stack.pop());
|
419
|
+
}
|
420
|
+
return _results;
|
421
|
+
};
|
422
|
+
|
423
|
+
HamlCoffee.prototype.getNodeOptions = function(override) {
|
424
|
+
if (override == null) override = {};
|
425
|
+
return {
|
426
|
+
parentNode: override.parentNode || this.parentNode,
|
427
|
+
blockLevel: override.blockLevel || this.currentBlockLevel,
|
428
|
+
codeBlockLevel: override.codeBlockLevel || this.currentCodeBlockLevel,
|
429
|
+
escapeHtml: override.escapeHtml || this.options.escapeHtml,
|
430
|
+
escapeAttributes: override.escapeAttributes || this.options.escapeAttributes,
|
431
|
+
cleanValue: override.cleanValue || this.options.cleanValue,
|
432
|
+
format: override.format || this.options.format,
|
433
|
+
preserveTags: override.preserveTags || this.options.preserveTags,
|
434
|
+
selfCloseTags: override.selfCloseTags || this.options.selfCloseTags,
|
435
|
+
uglify: override.uglify || this.options.uglify
|
436
|
+
};
|
437
|
+
};
|
438
|
+
|
439
|
+
HamlCoffee.prototype.nodeFactory = function(expression) {
|
440
|
+
var node, options, _ref;
|
441
|
+
if (expression == null) expression = '';
|
442
|
+
options = this.getNodeOptions();
|
443
|
+
if (expression.match(/^:(escaped|preserve|css|javascript|plain|cdata|coffeescript)/)) {
|
444
|
+
node = new Filter(expression, options);
|
445
|
+
} else if (expression.match(/^(\/|-#)(.*)/)) {
|
446
|
+
node = new Comment(expression, options);
|
447
|
+
} else if (expression.match(/^(-#|-|=|!=|\&=|~)\s*(.*)/)) {
|
448
|
+
node = new Code(expression, options);
|
449
|
+
} else if (expression.match(/^(%|#|\.|\!)(.*)/)) {
|
450
|
+
node = new Haml(expression, options);
|
451
|
+
} else {
|
452
|
+
node = new Text(expression, options);
|
453
|
+
}
|
454
|
+
if ((_ref = options.parentNode) != null) _ref.addChild(node);
|
455
|
+
return node;
|
456
|
+
};
|
325
457
|
|
326
|
-
|
458
|
+
HamlCoffee.prototype.parse = function(source) {
|
459
|
+
var attributes, expression, line, lines, result, text, ws, _ref;
|
460
|
+
if (source == null) source = '';
|
461
|
+
this.line_number = this.previousIndent = this.tabSize = this.currentBlockLevel = this.previousBlockLevel = 0;
|
462
|
+
this.currentCodeBlockLevel = this.previousCodeBlockLevel = 0;
|
463
|
+
this.node = null;
|
464
|
+
this.stack = [];
|
465
|
+
this.root = this.parentNode = new Node('', this.getNodeOptions());
|
466
|
+
lines = source.split("\n");
|
467
|
+
while ((line = lines.shift()) !== void 0) {
|
468
|
+
if ((this.node instanceof Filter) && !this.exitFilter) {
|
469
|
+
if (/^(\s)*$/.test(line)) {
|
470
|
+
this.node.addChild(new Text('', this.getNodeOptions({
|
471
|
+
parentNode: this.node
|
472
|
+
})));
|
473
|
+
} else {
|
474
|
+
result = line.match(/^(\s*)(.*)/);
|
475
|
+
ws = result[1];
|
476
|
+
expression = result[2];
|
477
|
+
if (this.node.blockLevel >= (ws.length / 2)) {
|
478
|
+
this.exitFilter = true;
|
479
|
+
lines.unshift(line);
|
480
|
+
continue;
|
481
|
+
}
|
482
|
+
text = line.match(RegExp("^\\s{" + ((this.node.blockLevel * 2) + 2) + "}(.*)"));
|
483
|
+
if (text) {
|
484
|
+
this.node.addChild(new Text(text[1], this.getNodeOptions({
|
485
|
+
parentNode: this.node
|
486
|
+
})));
|
487
|
+
}
|
488
|
+
}
|
489
|
+
} else {
|
490
|
+
this.exitFilter = false;
|
491
|
+
result = line.match(/^(\s*)(.*)/);
|
492
|
+
ws = result[1];
|
493
|
+
expression = result[2];
|
494
|
+
if (/^(\s)*$/.test(line)) continue;
|
495
|
+
while (/^%.*[{(]/.test(expression) && !/^(\s*)[.%#<]/.test(lines[0]) && /(?:(\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|"\w+[\w:-]*\w?")\s*=\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[\w@.]+)|(:\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|"\w+[\w:-]*\w?")\s*=>\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[-\w@.()\[\]'"]+)|(\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|'\w+[\w:-]*\w?'):\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[-\w@.()\[\]'"]+))/.test(lines[0])) {
|
496
|
+
attributes = lines.shift();
|
497
|
+
expression += ' ' + attributes.match(/^(\s*)(.*)/)[2];
|
498
|
+
this.line_number++;
|
499
|
+
}
|
500
|
+
if (expression.match(/(\s)+\|$/)) {
|
501
|
+
expression = expression.replace(/(\s)+\|$/, ' ');
|
502
|
+
while ((_ref = lines[0]) != null ? _ref.match(/(\s)+\|$/) : void 0) {
|
503
|
+
expression += lines.shift().match(/^(\s*)(.*)/)[2].replace(/(\s)+\|$/, '');
|
504
|
+
this.line_number++;
|
505
|
+
}
|
506
|
+
}
|
507
|
+
this.currentIndent = ws.length;
|
508
|
+
if (this.indentChanged()) {
|
509
|
+
this.updateTabSize();
|
510
|
+
this.updateBlockLevel();
|
511
|
+
this.updateParent();
|
512
|
+
this.updateCodeBlockLevel(this.parentNode);
|
513
|
+
}
|
514
|
+
this.node = this.nodeFactory(expression);
|
515
|
+
this.previousBlockLevel = this.currentBlockLevel;
|
516
|
+
this.previousIndent = this.currentIndent;
|
517
|
+
}
|
518
|
+
this.line_number++;
|
519
|
+
}
|
520
|
+
return this.evaluate(this.root);
|
521
|
+
};
|
522
|
+
|
523
|
+
HamlCoffee.prototype.evaluate = function(node) {
|
524
|
+
var child, _i, _len, _ref;
|
525
|
+
_ref = node.children;
|
526
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
527
|
+
child = _ref[_i];
|
528
|
+
this.evaluate(child);
|
529
|
+
}
|
530
|
+
return node.evaluate();
|
531
|
+
};
|
532
|
+
|
533
|
+
HamlCoffee.prototype.render = function(templateName, namespace) {
|
534
|
+
var segment, segments, template, _i, _len;
|
535
|
+
if (namespace == null) namespace = 'window.HAML';
|
536
|
+
template = '';
|
537
|
+
segments = ("" + namespace + "." + templateName).replace(/(\s|-)+/g, '_').split(/\./);
|
538
|
+
templateName = segments.pop();
|
539
|
+
namespace = segments.shift();
|
540
|
+
if (segments.length !== 0) {
|
541
|
+
for (_i = 0, _len = segments.length; _i < _len; _i++) {
|
542
|
+
segment = segments[_i];
|
543
|
+
namespace += "." + segment;
|
544
|
+
template += "" + namespace + " ?= {}\n";
|
545
|
+
}
|
546
|
+
} else {
|
547
|
+
template += "" + namespace + " ?= {}\n";
|
548
|
+
}
|
549
|
+
template += "" + namespace + "['" + templateName + "'] = (context) -> ( ->\n";
|
550
|
+
template += "" + (indent(this.precompile(), 1));
|
551
|
+
template += ").call(context)";
|
552
|
+
return template;
|
553
|
+
};
|
554
|
+
|
555
|
+
HamlCoffee.prototype.precompile = function() {
|
556
|
+
var code, fn;
|
557
|
+
fn = '';
|
558
|
+
code = this.createCode();
|
559
|
+
if (code.indexOf('$e') !== -1) {
|
560
|
+
if (this.options.customHtmlEscape) {
|
561
|
+
fn += "$e = " + this.options.customHtmlEscape + "\n";
|
562
|
+
} else {
|
563
|
+
fn += "$e = (text, escape) ->\n \"\#{ text }\"\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\'/g, ''')\n .replace(/\"/g, '"')\n";
|
564
|
+
}
|
565
|
+
}
|
566
|
+
if (code.indexOf('$c') !== -1) {
|
567
|
+
if (this.options.customCleanValue) {
|
568
|
+
fn += "$c = " + this.options.customCleanValue + "\n";
|
569
|
+
} else {
|
570
|
+
fn += "$c = (text) -> if text is null or text is undefined then '' else text\n";
|
571
|
+
}
|
572
|
+
}
|
573
|
+
if (code.indexOf('$p') !== -1 || code.indexOf('$fp') !== -1) {
|
574
|
+
if (this.options.customPreserve) {
|
575
|
+
fn += "$p = " + this.options.customPreserve + "\n";
|
576
|
+
} else {
|
577
|
+
fn += "$p = (text) -> text.replace /\\n/g, '
'\n";
|
578
|
+
}
|
579
|
+
}
|
580
|
+
if (code.indexOf('$fp') !== -1) {
|
581
|
+
if (this.options.customFindAndPreserve) {
|
582
|
+
fn += "$fp = " + this.options.customFindAndPreserve + "\n";
|
583
|
+
} else {
|
584
|
+
fn += "$fp = (text) ->\n text.replace /<(" + (this.options.preserveTags.split(',').join('|')) + ")>([^]*?)<\\/\\1>/g, (str, tag, content) ->\n \"<\#{ tag }>\#{ $p content }</\#{ tag }>\"\n";
|
585
|
+
}
|
586
|
+
}
|
587
|
+
fn += "$o = []\n";
|
588
|
+
fn += "" + code + "\n";
|
589
|
+
return fn += "return $o.join(\"\\n\")" + (this.cleanupWhitespace(code)) + "\n";
|
590
|
+
};
|
591
|
+
|
592
|
+
HamlCoffee.prototype.createCode = function() {
|
593
|
+
var child, code, line, processors, _i, _j, _len, _len2, _ref, _ref2;
|
594
|
+
code = [];
|
595
|
+
this.lines = [];
|
596
|
+
_ref = this.root.children;
|
597
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
598
|
+
child = _ref[_i];
|
599
|
+
this.lines = this.lines.concat(child.render());
|
600
|
+
}
|
601
|
+
this.lines = this.combineText(this.lines);
|
602
|
+
_ref2 = this.lines;
|
603
|
+
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
604
|
+
line = _ref2[_j];
|
605
|
+
if (line !== null) {
|
606
|
+
switch (line.type) {
|
607
|
+
case 'text':
|
608
|
+
code.push("" + (whitespace(line.cw)) + "$o.push \"" + (whitespace(line.hw)) + line.text + "\"");
|
609
|
+
break;
|
610
|
+
case 'run':
|
611
|
+
code.push("" + (whitespace(line.cw)) + line.code);
|
612
|
+
break;
|
613
|
+
case 'insert':
|
614
|
+
processors = '';
|
615
|
+
if (line.findAndPreserve) processors += '$fp ';
|
616
|
+
if (line.preserve) processors += '$p ';
|
617
|
+
if (line.escape) processors += '$e ';
|
618
|
+
if (this.options.cleanValue) processors += '$c ';
|
619
|
+
code.push("" + (whitespace(line.cw)) + "$o.push \"" + (whitespace(line.hw)) + "\" + " + processors + line.code);
|
620
|
+
}
|
621
|
+
}
|
622
|
+
}
|
623
|
+
return code.join('\n');
|
624
|
+
};
|
625
|
+
|
626
|
+
HamlCoffee.prototype.combineText = function(lines) {
|
627
|
+
var combined, line, nextLine;
|
628
|
+
combined = [];
|
629
|
+
while ((line = lines.shift()) !== void 0) {
|
630
|
+
if (line.type === 'text') {
|
631
|
+
while (lines[0] && lines[0].type === 'text' && line.cw === lines[0].cw) {
|
632
|
+
nextLine = lines.shift();
|
633
|
+
line.text += "\\n" + (whitespace(nextLine.hw)) + nextLine.text;
|
634
|
+
}
|
635
|
+
}
|
636
|
+
combined.push(line);
|
637
|
+
}
|
638
|
+
return combined;
|
639
|
+
};
|
640
|
+
|
641
|
+
HamlCoffee.prototype.cleanupWhitespace = function(code) {
|
642
|
+
if (/\u0091|\u0092/.test(code)) {
|
643
|
+
return ".replace(/[\\s\\n]*\\u0091/mg, '').replace(/\\u0092[\\s\\n]*/mg, '')";
|
644
|
+
} else {
|
645
|
+
return '';
|
646
|
+
}
|
647
|
+
};
|
648
|
+
|
649
|
+
return HamlCoffee;
|
650
|
+
|
651
|
+
})();
|
652
|
+
|
653
|
+
}).call(this);
|
654
|
+
|
655
|
+
});
|
656
|
+
|
657
|
+
require.define("/nodes/node.js", function (require, module, exports, __dirname, __filename) {
|
658
|
+
(function() {
|
659
|
+
var Node, escapeHTML;
|
327
660
|
|
328
|
-
|
661
|
+
escapeHTML = require('../util/text').escapeHTML;
|
329
662
|
|
330
663
|
module.exports = Node = (function() {
|
331
664
|
|
@@ -348,6 +681,7 @@ require.define("/nodes/node.js", function (require, module, exports, __dirname,
|
|
348
681
|
};
|
349
682
|
this.escapeHtml = options.escapeHtml;
|
350
683
|
this.escapeAttributes = options.escapeAttributes;
|
684
|
+
this.cleanValue = options.cleanValue;
|
351
685
|
this.format = options.format;
|
352
686
|
this.selfCloseTags = options.selfCloseTags.split(',');
|
353
687
|
this.uglify = options.uglify;
|
@@ -394,8 +728,8 @@ require.define("/nodes/node.js", function (require, module, exports, __dirname,
|
|
394
728
|
return {
|
395
729
|
type: 'text',
|
396
730
|
cw: this.codeBlockLevel,
|
397
|
-
hw: this.uglify ? 0 : this.blockLevel - this.codeBlockLevel
|
398
|
-
text: escape ?
|
731
|
+
hw: this.uglify ? 0 : this.blockLevel - this.codeBlockLevel,
|
732
|
+
text: escape ? escapeHTML(text) : text
|
399
733
|
};
|
400
734
|
};
|
401
735
|
|
@@ -414,7 +748,7 @@ require.define("/nodes/node.js", function (require, module, exports, __dirname,
|
|
414
748
|
return {
|
415
749
|
type: 'insert',
|
416
750
|
cw: this.codeBlockLevel,
|
417
|
-
hw: this.uglify ? 0 : this.blockLevel,
|
751
|
+
hw: this.uglify ? 0 : this.blockLevel - this.codeBlockLevel,
|
418
752
|
escape: escape,
|
419
753
|
preserve: preserve,
|
420
754
|
findAndPreserve: findAndPreserve,
|
@@ -491,7 +825,7 @@ require.define("/nodes/node.js", function (require, module, exports, __dirname,
|
|
491
825
|
|
492
826
|
});
|
493
827
|
|
494
|
-
require.define("/
|
828
|
+
require.define("/util/text.js", function (require, module, exports, __dirname, __filename) {
|
495
829
|
|
496
830
|
module.exports = {
|
497
831
|
whitespace: function(n) {
|
@@ -517,6 +851,9 @@ require.define("/helper.js", function (require, module, exports, __dirname, __fi
|
|
517
851
|
return text.replace('\\n', '\&\#x000A;');
|
518
852
|
});
|
519
853
|
}
|
854
|
+
},
|
855
|
+
indent: function(text, spaces) {
|
856
|
+
return text.replace(/^(.*)$/mg, module.exports.whitespace(spaces) + '$1');
|
520
857
|
}
|
521
858
|
};
|
522
859
|
|
@@ -524,12 +861,12 @@ require.define("/helper.js", function (require, module, exports, __dirname, __fi
|
|
524
861
|
|
525
862
|
require.define("/nodes/text.js", function (require, module, exports, __dirname, __filename) {
|
526
863
|
(function() {
|
527
|
-
var Node, Text,
|
864
|
+
var Node, Text, escapeQuotes;
|
528
865
|
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; };
|
529
866
|
|
530
867
|
Node = require('./node');
|
531
868
|
|
532
|
-
|
869
|
+
escapeQuotes = require('../util/text').escapeQuotes;
|
533
870
|
|
534
871
|
module.exports = Text = (function() {
|
535
872
|
|
@@ -540,7 +877,7 @@ require.define("/nodes/text.js", function (require, module, exports, __dirname,
|
|
540
877
|
}
|
541
878
|
|
542
879
|
Text.prototype.evaluate = function() {
|
543
|
-
return this.opener = this.markText(
|
880
|
+
return this.opener = this.markText(escapeQuotes(this.expression));
|
544
881
|
};
|
545
882
|
|
546
883
|
return Text;
|
@@ -553,14 +890,12 @@ require.define("/nodes/text.js", function (require, module, exports, __dirname,
|
|
553
890
|
|
554
891
|
require.define("/nodes/haml.js", function (require, module, exports, __dirname, __filename) {
|
555
892
|
(function() {
|
556
|
-
var Haml, Node,
|
893
|
+
var Haml, Node, escapeQuotes;
|
557
894
|
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; };
|
558
895
|
|
559
896
|
Node = require('./node');
|
560
897
|
|
561
|
-
|
562
|
-
|
563
|
-
p = require('../helper').preserve;
|
898
|
+
escapeQuotes = require('../util/text').escapeQuotes;
|
564
899
|
|
565
900
|
module.exports = Haml = (function() {
|
566
901
|
|
@@ -574,27 +909,43 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
|
|
574
909
|
var assignment, code, identifier, match, prefix, tokens;
|
575
910
|
tokens = this.parseExpression(this.expression);
|
576
911
|
if (tokens.doctype) {
|
577
|
-
return this.opener = this.markText("" + (
|
912
|
+
return this.opener = this.markText("" + (escapeQuotes(this.buildDocType(tokens.doctype))));
|
578
913
|
} else {
|
579
914
|
if (this.isNotSelfClosing(tokens.tag)) {
|
580
|
-
prefix =
|
915
|
+
prefix = escapeQuotes(this.buildHtmlTagPrefix(tokens));
|
581
916
|
if (tokens.assignment) {
|
582
917
|
match = tokens.assignment.match(/^(=|!=|&=|~)\s*(.*)$/);
|
583
918
|
identifier = match[1];
|
584
919
|
assignment = match[2];
|
585
920
|
if (identifier === '~') {
|
586
|
-
code = "\#{fp
|
921
|
+
code = "\#{$fp " + assignment + " }";
|
587
922
|
} else if (identifier === '&=' || (identifier === '=' && this.escapeHtml)) {
|
588
923
|
if (this.preserve) {
|
589
|
-
|
924
|
+
if (this.cleanValue) {
|
925
|
+
code = "\#{ $p($e($c(" + assignment + "))) }";
|
926
|
+
} else {
|
927
|
+
code = "\#{ $p($e(" + assignment + ")) }";
|
928
|
+
}
|
590
929
|
} else {
|
591
|
-
|
930
|
+
if (this.cleanValue) {
|
931
|
+
code = "\#{ $e($c(" + assignment + ")) }";
|
932
|
+
} else {
|
933
|
+
code = "\#{ $e(" + assignment + ") }";
|
934
|
+
}
|
592
935
|
}
|
593
936
|
} else if (identifier === '!=' || (identifier === '=' && !this.escapeHtml)) {
|
594
937
|
if (this.preserve) {
|
595
|
-
|
938
|
+
if (this.cleanValue) {
|
939
|
+
code = "\#{ $p($c(" + assignment + ")) }";
|
940
|
+
} else {
|
941
|
+
code = "\#{ $p(" + assignment + ") }";
|
942
|
+
}
|
596
943
|
} else {
|
597
|
-
|
944
|
+
if (this.cleanValue) {
|
945
|
+
code = "\#{ $c(" + assignment + ") }";
|
946
|
+
} else {
|
947
|
+
code = "\#{ " + assignment + " }";
|
948
|
+
}
|
598
949
|
}
|
599
950
|
}
|
600
951
|
this.opener = this.markText("" + prefix + ">" + code);
|
@@ -608,7 +959,7 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
|
|
608
959
|
}
|
609
960
|
} else {
|
610
961
|
tokens.tag = tokens.tag.replace(/\/$/, '');
|
611
|
-
prefix =
|
962
|
+
prefix = escapeQuotes(this.buildHtmlTagPrefix(tokens));
|
612
963
|
return this.opener = this.markText("" + prefix + (this.format === 'xhtml' ? ' /' : '') + ">");
|
613
964
|
}
|
614
965
|
}
|
@@ -712,7 +1063,7 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
|
|
712
1063
|
attributes = [];
|
713
1064
|
if (exp === void 0) return attributes;
|
714
1065
|
_ref = this.getDataAttributes(exp), exp = _ref[0], datas = _ref[1];
|
715
|
-
findAttributes = /(?:(\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|"\w+[\w:-]*\w?")\s*=\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[\w@.]+)|(:\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|"\w+[\w:-]*\w?")\s*=>\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[-\w@.()\[\]'"]+)|(\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|
|
1066
|
+
findAttributes = /(?:(\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|"\w+[\w:-]*\w?")\s*=\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[\w@.]+)|(:\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|"\w+[\w:-]*\w?")\s*=>\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[-\w@.()\[\]'"]+)|(\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|"\w+[\w:-]*\w?"):\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[-\w@.()\[\]'"]+))/g;
|
716
1067
|
while (match = findAttributes.exec(exp)) {
|
717
1068
|
key = (match[1] || match[3] || match[5]).replace(/^:/, '');
|
718
1069
|
value = match[2] || match[4] || match[6];
|
@@ -723,9 +1074,17 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
|
|
723
1074
|
bool = true;
|
724
1075
|
} else if (!value.match(/^("|').*\1$/)) {
|
725
1076
|
if (this.escapeAttributes) {
|
726
|
-
|
1077
|
+
if (this.cleanValue) {
|
1078
|
+
value = '\'#{ $e($c(' + value + ')) }\'';
|
1079
|
+
} else {
|
1080
|
+
value = '\'#{ $e(' + value + ') }\'';
|
1081
|
+
}
|
727
1082
|
} else {
|
728
|
-
|
1083
|
+
if (this.cleanValue) {
|
1084
|
+
value = '\'#{ $c(' + value + ') }\'';
|
1085
|
+
} else {
|
1086
|
+
value = '\'#{ (' + value + ') }\'';
|
1087
|
+
}
|
729
1088
|
}
|
730
1089
|
}
|
731
1090
|
if (quoted = value.match(/^("|')(.*)\1$/)) value = quoted[2];
|
@@ -841,13 +1200,11 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
|
|
841
1200
|
|
842
1201
|
require.define("/nodes/code.js", function (require, module, exports, __dirname, __filename) {
|
843
1202
|
(function() {
|
844
|
-
var Code, Node
|
1203
|
+
var Code, Node;
|
845
1204
|
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; };
|
846
1205
|
|
847
1206
|
Node = require('./node');
|
848
1207
|
|
849
|
-
p = require('../helper').preserve;
|
850
|
-
|
851
1208
|
module.exports = Code = (function() {
|
852
1209
|
|
853
1210
|
__extends(Code, Node);
|
@@ -933,12 +1290,12 @@ require.define("/nodes/comment.js", function (require, module, exports, __dirnam
|
|
933
1290
|
|
934
1291
|
require.define("/nodes/filter.js", function (require, module, exports, __dirname, __filename) {
|
935
1292
|
(function() {
|
936
|
-
var Filter, Node,
|
1293
|
+
var Filter, Node, whitespace;
|
937
1294
|
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; };
|
938
1295
|
|
939
1296
|
Node = require('./node');
|
940
1297
|
|
941
|
-
|
1298
|
+
whitespace = require('../util/text').whitespace;
|
942
1299
|
|
943
1300
|
module.exports = Filter = (function() {
|
944
1301
|
|
@@ -1035,7 +1392,7 @@ require.define("/nodes/filter.js", function (require, module, exports, __dirname
|
|
1035
1392
|
for (e = 0; 0 <= empty ? e < empty : e > empty; 0 <= empty ? e++ : e--) {
|
1036
1393
|
output.push(this.markText(""));
|
1037
1394
|
}
|
1038
|
-
output.push(this.markText("" + (
|
1395
|
+
output.push(this.markText("" + (whitespace(indent)) + line));
|
1039
1396
|
break;
|
1040
1397
|
case 'run':
|
1041
1398
|
output.push(this.markRunningCode("" + line));
|
@@ -1053,311 +1410,3 @@ require.define("/nodes/filter.js", function (require, module, exports, __dirname
|
|
1053
1410
|
}).call(this);
|
1054
1411
|
|
1055
1412
|
});
|
1056
|
-
|
1057
|
-
require.define("/compiler.js", function (require, module, exports, __dirname, __filename) {
|
1058
|
-
(function() {
|
1059
|
-
var Code, Comment, Compiler, Filter, Haml, Node, Text, w;
|
1060
|
-
|
1061
|
-
Node = require('./nodes/node');
|
1062
|
-
|
1063
|
-
Text = require('./nodes/text');
|
1064
|
-
|
1065
|
-
Haml = require('./nodes/haml');
|
1066
|
-
|
1067
|
-
Code = require('./nodes/code');
|
1068
|
-
|
1069
|
-
Comment = require('./nodes/comment');
|
1070
|
-
|
1071
|
-
Filter = require('./nodes/filter');
|
1072
|
-
|
1073
|
-
w = require('./helper').whitespace;
|
1074
|
-
|
1075
|
-
module.exports = Compiler = (function() {
|
1076
|
-
|
1077
|
-
function Compiler(options) {
|
1078
|
-
var _base, _base2, _base3, _base4, _base5, _base6, _ref, _ref2, _ref3, _ref4, _ref5, _ref6;
|
1079
|
-
this.options = options != null ? options : {};
|
1080
|
-
if ((_ref = (_base = this.options).escapeHtml) == null) {
|
1081
|
-
_base.escapeHtml = true;
|
1082
|
-
}
|
1083
|
-
if ((_ref2 = (_base2 = this.options).escapeAttributes) == null) {
|
1084
|
-
_base2.escapeAttributes = true;
|
1085
|
-
}
|
1086
|
-
if ((_ref3 = (_base3 = this.options).uglify) == null) _base3.uglify = false;
|
1087
|
-
if ((_ref4 = (_base4 = this.options).format) == null) {
|
1088
|
-
_base4.format = 'html5';
|
1089
|
-
}
|
1090
|
-
if ((_ref5 = (_base5 = this.options).preserveTags) == null) {
|
1091
|
-
_base5.preserveTags = 'pre,textarea';
|
1092
|
-
}
|
1093
|
-
if ((_ref6 = (_base6 = this.options).selfCloseTags) == null) {
|
1094
|
-
_base6.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base';
|
1095
|
-
}
|
1096
|
-
}
|
1097
|
-
|
1098
|
-
Compiler.prototype.indentChanged = function() {
|
1099
|
-
return this.currentIndent !== this.previousIndent;
|
1100
|
-
};
|
1101
|
-
|
1102
|
-
Compiler.prototype.isIndent = function() {
|
1103
|
-
return this.currentIndent > this.previousIndent;
|
1104
|
-
};
|
1105
|
-
|
1106
|
-
Compiler.prototype.updateTabSize = function() {
|
1107
|
-
if (this.tabSize === 0) {
|
1108
|
-
return this.tabSize = this.currentIndent - this.previousIndent;
|
1109
|
-
}
|
1110
|
-
};
|
1111
|
-
|
1112
|
-
Compiler.prototype.updateBlockLevel = function() {
|
1113
|
-
this.currentBlockLevel = this.currentIndent / this.tabSize;
|
1114
|
-
if (this.currentBlockLevel - Math.floor(this.currentBlockLevel) > 0) {
|
1115
|
-
throw "Indentation error in line " + this.lineNumber;
|
1116
|
-
}
|
1117
|
-
if ((this.currentIndent - this.previousIndent) / this.tabSize > 1) {
|
1118
|
-
throw "Block level too deep in line " + this.lineNumber;
|
1119
|
-
}
|
1120
|
-
return this.delta = this.previousBlockLevel - this.currentBlockLevel;
|
1121
|
-
};
|
1122
|
-
|
1123
|
-
Compiler.prototype.updateCodeBlockLevel = function(node) {
|
1124
|
-
if (node instanceof Code) {
|
1125
|
-
return this.currentCodeBlockLevel = node.codeBlockLevel + 1;
|
1126
|
-
} else {
|
1127
|
-
return this.currentCodeBlockLevel = node.codeBlockLevel;
|
1128
|
-
}
|
1129
|
-
};
|
1130
|
-
|
1131
|
-
Compiler.prototype.updateParent = function() {
|
1132
|
-
if (this.isIndent()) {
|
1133
|
-
return this.pushParent();
|
1134
|
-
} else {
|
1135
|
-
return this.popParent();
|
1136
|
-
}
|
1137
|
-
};
|
1138
|
-
|
1139
|
-
Compiler.prototype.pushParent = function() {
|
1140
|
-
this.stack.push(this.parentNode);
|
1141
|
-
return this.parentNode = this.node;
|
1142
|
-
};
|
1143
|
-
|
1144
|
-
Compiler.prototype.popParent = function() {
|
1145
|
-
var i, _ref, _results;
|
1146
|
-
_results = [];
|
1147
|
-
for (i = 0, _ref = this.delta - 1; 0 <= _ref ? i <= _ref : i >= _ref; 0 <= _ref ? i++ : i--) {
|
1148
|
-
_results.push(this.parentNode = this.stack.pop());
|
1149
|
-
}
|
1150
|
-
return _results;
|
1151
|
-
};
|
1152
|
-
|
1153
|
-
Compiler.prototype.getNodeOptions = function(override) {
|
1154
|
-
if (override == null) override = {};
|
1155
|
-
return {
|
1156
|
-
parentNode: override.parentNode || this.parentNode,
|
1157
|
-
blockLevel: override.blockLevel || this.currentBlockLevel,
|
1158
|
-
codeBlockLevel: override.codeBlockLevel || this.currentCodeBlockLevel,
|
1159
|
-
escapeHtml: override.escapeHtml || this.options.escapeHtml,
|
1160
|
-
escapeAttributes: override.escapeAttributes || this.options.escapeAttributes,
|
1161
|
-
format: override.format || this.options.format,
|
1162
|
-
preserveTags: override.preserveTags || this.options.preserveTags,
|
1163
|
-
selfCloseTags: override.selfCloseTags || this.options.selfCloseTags,
|
1164
|
-
uglify: override.uglify || this.options.uglify
|
1165
|
-
};
|
1166
|
-
};
|
1167
|
-
|
1168
|
-
Compiler.prototype.nodeFactory = function(expression) {
|
1169
|
-
var node, options, _ref;
|
1170
|
-
if (expression == null) expression = '';
|
1171
|
-
options = this.getNodeOptions();
|
1172
|
-
if (expression.match(/^:(escaped|preserve|css|javascript|plain|cdata|coffeescript)/)) {
|
1173
|
-
node = new Filter(expression, options);
|
1174
|
-
} else if (expression.match(/^(\/|-#)(.*)/)) {
|
1175
|
-
node = new Comment(expression, options);
|
1176
|
-
} else if (expression.match(/^(-#|-|=|!=|\&=|~)\s*(.*)/)) {
|
1177
|
-
node = new Code(expression, options);
|
1178
|
-
} else if (expression.match(/^(%|#|\.|\!)(.*)/)) {
|
1179
|
-
node = new Haml(expression, options);
|
1180
|
-
} else {
|
1181
|
-
node = new Text(expression, options);
|
1182
|
-
}
|
1183
|
-
if ((_ref = options.parentNode) != null) _ref.addChild(node);
|
1184
|
-
return node;
|
1185
|
-
};
|
1186
|
-
|
1187
|
-
Compiler.prototype.parse = function(source) {
|
1188
|
-
var attributes, expression, line, lines, result, text, whitespace, _ref;
|
1189
|
-
this.line_number = this.previousIndent = this.tabSize = this.currentBlockLevel = this.previousBlockLevel = 0;
|
1190
|
-
this.currentCodeBlockLevel = this.previousCodeBlockLevel = 2;
|
1191
|
-
this.node = null;
|
1192
|
-
this.stack = [];
|
1193
|
-
this.root = this.parentNode = new Node('', this.getNodeOptions());
|
1194
|
-
lines = source.split("\n");
|
1195
|
-
while ((line = lines.shift()) !== void 0) {
|
1196
|
-
if ((this.node instanceof Filter) && !this.exitFilter) {
|
1197
|
-
if (/^(\s)*$/.test(line)) {
|
1198
|
-
this.node.addChild(new Text('', this.getNodeOptions({
|
1199
|
-
parentNode: this.node
|
1200
|
-
})));
|
1201
|
-
} else {
|
1202
|
-
result = line.match(/^(\s*)(.*)/);
|
1203
|
-
whitespace = result[1];
|
1204
|
-
expression = result[2];
|
1205
|
-
if (this.node.blockLevel >= (whitespace.length / 2)) {
|
1206
|
-
this.exitFilter = true;
|
1207
|
-
lines.unshift(line);
|
1208
|
-
continue;
|
1209
|
-
}
|
1210
|
-
text = line.match(RegExp("^\\s{" + ((this.node.blockLevel * 2) + 2) + "}(.*)"));
|
1211
|
-
if (text) {
|
1212
|
-
this.node.addChild(new Text(text[1], this.getNodeOptions({
|
1213
|
-
parentNode: this.node
|
1214
|
-
})));
|
1215
|
-
}
|
1216
|
-
}
|
1217
|
-
} else {
|
1218
|
-
this.exitFilter = false;
|
1219
|
-
result = line.match(/^(\s*)(.*)/);
|
1220
|
-
whitespace = result[1];
|
1221
|
-
expression = result[2];
|
1222
|
-
if (/^(\s)*$/.test(line)) continue;
|
1223
|
-
while (/^%.*[{(]/.test(expression) && !/^(\s*)[.%#<]/.test(lines[0]) && /(?:(\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|"\w+[\w:-]*\w?")\s*=\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[\w@.]+)|(:\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|"\w+[\w:-]*\w?")\s*=>\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[-\w@.()\[\]'"]+)|(\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|'\w+[\w:-]*\w?'):\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[-\w@.()\[\]'"]+))/.test(lines[0])) {
|
1224
|
-
attributes = lines.shift();
|
1225
|
-
expression += ' ' + attributes.match(/^(\s*)(.*)/)[2];
|
1226
|
-
this.line_number++;
|
1227
|
-
}
|
1228
|
-
if (expression.match(/(\s)+\|$/)) {
|
1229
|
-
expression = expression.replace(/(\s)+\|$/, ' ');
|
1230
|
-
while ((_ref = lines[0]) != null ? _ref.match(/(\s)+\|$/) : void 0) {
|
1231
|
-
expression += lines.shift().match(/^(\s*)(.*)/)[2].replace(/(\s)+\|$/, '');
|
1232
|
-
this.line_number++;
|
1233
|
-
}
|
1234
|
-
}
|
1235
|
-
this.currentIndent = whitespace.length;
|
1236
|
-
if (this.indentChanged()) {
|
1237
|
-
this.updateTabSize();
|
1238
|
-
this.updateBlockLevel();
|
1239
|
-
this.updateParent();
|
1240
|
-
this.updateCodeBlockLevel(this.parentNode);
|
1241
|
-
}
|
1242
|
-
this.node = this.nodeFactory(expression);
|
1243
|
-
this.previousBlockLevel = this.currentBlockLevel;
|
1244
|
-
this.previousIndent = this.currentIndent;
|
1245
|
-
}
|
1246
|
-
this.line_number++;
|
1247
|
-
}
|
1248
|
-
return this.evaluate(this.root);
|
1249
|
-
};
|
1250
|
-
|
1251
|
-
Compiler.prototype.evaluate = function(node) {
|
1252
|
-
var child, _i, _len, _ref;
|
1253
|
-
_ref = node.children;
|
1254
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1255
|
-
child = _ref[_i];
|
1256
|
-
this.evaluate(child);
|
1257
|
-
}
|
1258
|
-
return node.evaluate();
|
1259
|
-
};
|
1260
|
-
|
1261
|
-
Compiler.prototype.render = function(templateName, namespace) {
|
1262
|
-
var cleanFn, code, escapeFn, findAndPreserveFn, output, preserveFn, segment, segments, _i, _len;
|
1263
|
-
if (namespace == null) namespace = 'window.HAML';
|
1264
|
-
output = '';
|
1265
|
-
segments = ("" + namespace + "." + templateName).replace(/(\s|-)+/g, '_').split(/\./);
|
1266
|
-
templateName = segments.pop();
|
1267
|
-
namespace = segments.shift();
|
1268
|
-
if (segments.length !== 0) {
|
1269
|
-
for (_i = 0, _len = segments.length; _i < _len; _i++) {
|
1270
|
-
segment = segments[_i];
|
1271
|
-
namespace += "." + segment;
|
1272
|
-
output += "" + namespace + " ?= {}\n";
|
1273
|
-
}
|
1274
|
-
} else {
|
1275
|
-
output += "" + namespace + " ?= {}\n";
|
1276
|
-
}
|
1277
|
-
if (this.options.customHtmlEscape) {
|
1278
|
-
escapeFn = this.options.customHtmlEscape;
|
1279
|
-
} else {
|
1280
|
-
escapeFn = "" + namespace + ".htmlEscape";
|
1281
|
-
output += escapeFn + '||= (text, escape) ->\n "#{ text }"\n .replace(/&/g, \'&\')\n .replace(/</g, \'<\')\n .replace(/>/g, \'>\')\n .replace(/\'/g, \''\')\n .replace(/\"/g, \'"\')\n';
|
1282
|
-
}
|
1283
|
-
if (this.options.customCleanValue) {
|
1284
|
-
cleanFn = this.options.customCleanValue;
|
1285
|
-
} else {
|
1286
|
-
cleanFn = "" + namespace + ".cleanValue";
|
1287
|
-
output += cleanFn + '||= (text) -> if text is null or text is undefined then \'\' else text\n';
|
1288
|
-
}
|
1289
|
-
if (this.options.customPreserve) {
|
1290
|
-
preserveFn = this.options.customPreserve;
|
1291
|
-
} else {
|
1292
|
-
preserveFn = "" + namespace + ".preserve";
|
1293
|
-
output += preserveFn + "||= (text) -> text.replace /\\n/g, '
'\n";
|
1294
|
-
}
|
1295
|
-
if (this.options.customFindAndPreserve) {
|
1296
|
-
findAndPreserveFn = this.options.customFindAndPreserve;
|
1297
|
-
} else {
|
1298
|
-
findAndPreserveFn = "" + namespace + ".findAndPreserve";
|
1299
|
-
output += findAndPreserveFn + ("||= (text) ->\n text.replace /<(" + (this.options.preserveTags.split(',').join('|')) + ")>([^]*?)<\\/\\1>/g, (str, tag, content) ->\n \"<\#{ tag }>\#{ " + preserveFn + "(content) }</\#{ tag }>\"\n");
|
1300
|
-
}
|
1301
|
-
output += "" + namespace + "['" + templateName + "'] = (context) ->\n";
|
1302
|
-
output += " fn = (context) ->\n";
|
1303
|
-
output += " o = []\n";
|
1304
|
-
output += " e = " + escapeFn + "\n";
|
1305
|
-
output += " c = " + cleanFn + "\n";
|
1306
|
-
output += " p = " + preserveFn + "\n";
|
1307
|
-
output += " fp = findAndPreserve = " + findAndPreserveFn + "\n";
|
1308
|
-
code = this.createCode();
|
1309
|
-
output += "" + code + "\n";
|
1310
|
-
output += " return o.join(\"\\n\")" + (this.cleanupWhitespace(code)) + "\n";
|
1311
|
-
output += " return fn.call(context)";
|
1312
|
-
return output;
|
1313
|
-
};
|
1314
|
-
|
1315
|
-
Compiler.prototype.createCode = function() {
|
1316
|
-
var child, code, line, _i, _j, _len, _len2, _ref, _ref2;
|
1317
|
-
code = [];
|
1318
|
-
this.lines = [];
|
1319
|
-
_ref = this.root.children;
|
1320
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1321
|
-
child = _ref[_i];
|
1322
|
-
this.lines = this.lines.concat(child.render());
|
1323
|
-
}
|
1324
|
-
_ref2 = this.lines;
|
1325
|
-
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
1326
|
-
line = _ref2[_j];
|
1327
|
-
if (line !== null) {
|
1328
|
-
switch (line.type) {
|
1329
|
-
case 'text':
|
1330
|
-
code.push("" + (w(line.cw)) + "o.push \"" + (w(line.hw)) + line.text + "\"");
|
1331
|
-
break;
|
1332
|
-
case 'run':
|
1333
|
-
code.push("" + (w(line.cw)) + line.code);
|
1334
|
-
break;
|
1335
|
-
case 'insert':
|
1336
|
-
if (line.hw === 0) {
|
1337
|
-
code.push("" + (w(line.cw)) + "o.push " + (w(line.findAndPreserve) ? 'fp ' : '') + (w(line.preserve) ? 'p ' : '') + (w(line.escape) ? 'e ' : '') + "c " + line.code);
|
1338
|
-
} else {
|
1339
|
-
code.push("" + (w(line.cw)) + "o.push \"" + (w(line.hw - line.cw + 2)) + "\" + " + (w(line.findAndPreserve) ? 'fp ' : '') + (w(line.preserve) ? 'p ' : '') + (w(line.escape) ? 'e ' : '') + "c " + line.code);
|
1340
|
-
}
|
1341
|
-
}
|
1342
|
-
}
|
1343
|
-
}
|
1344
|
-
return code.join('\n');
|
1345
|
-
};
|
1346
|
-
|
1347
|
-
Compiler.prototype.cleanupWhitespace = function(code) {
|
1348
|
-
if (/\u0091|\u0092/.test(code)) {
|
1349
|
-
return ".replace(/[\\s\\n]*\\u0091/mg, '').replace(/\\u0092[\\s\\n]*/mg, '')";
|
1350
|
-
} else {
|
1351
|
-
return '';
|
1352
|
-
}
|
1353
|
-
};
|
1354
|
-
|
1355
|
-
return Compiler;
|
1356
|
-
|
1357
|
-
})();
|
1358
|
-
|
1359
|
-
}).call(this);
|
1360
|
-
|
1361
|
-
});
|
1362
|
-
require("/compiler.js");
|
1363
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml_coffee_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-13 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70261194150620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70261194150620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: execjs
|
27
|
-
requirement: &
|
27
|
+
requirement: &70261194114620 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.2.9
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70261194114620
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70261194112960 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70261194112960
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70261194046800 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.7.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70261194046800
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: guard-rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &70261194040560 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.5.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70261194040560
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yard
|
71
|
-
requirement: &
|
71
|
+
requirement: &70261194030260 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 0.7.3
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70261194030260
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: redcarpet
|
82
|
-
requirement: &
|
82
|
+
requirement: &70261194023480 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 1.17.2
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70261194023480
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: pry
|
93
|
-
requirement: &
|
93
|
+
requirement: &70261194017020 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 0.9.6.2
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70261194017020
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: rake
|
104
|
-
requirement: &
|
104
|
+
requirement: &70261194008940 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: 0.9.2.2
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70261194008940
|
113
113
|
description: Compile Haml CoffeeScript templates in the Rails asset pipeline.
|
114
114
|
email:
|
115
115
|
- michi@netzpiraten.ch
|