haml_coffee_assets 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +9 -3
- data/lib/haml_coffee_assets/version.rb +1 -1
- data/lib/js/hamlcoffee.js +89 -15
- metadata +5 -2
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Haml Coffee Assets [](http://travis-ci.org/netzpirat/haml_coffee_assets)
|
2
2
|
|
3
3
|
Haml Coffee Assets compiles [Haml Coffee](https://github.com/netzpirat/haml-coffee) templates in the Rails 3.1
|
4
|
-
asset pipeline, so you can use them as JavaScript templates in your JavaScript heavy Rails application. It also works as
|
4
|
+
asset pipeline, so you can use them as JavaScript templates in your JavaScript heavy Rails application. It also works as
|
5
|
+
a pure [Sprockets](https://github.com/sstephenson/sprockets) engine without Rails.
|
5
6
|
|
6
7
|
Tested on MRI Ruby 1.8.7, 1.9.2, 1.9.3, REE and the latest version of JRuby.
|
7
8
|
|
@@ -25,6 +26,8 @@ Haml Coffee allows you to write inline [CoffeeScript](http://jashkenas.github.co
|
|
25
26
|
= I18n.t('js.cart.item.remove')
|
26
27
|
```
|
27
28
|
|
29
|
+
You can try Haml Coffee online by visiting [Haml Coffee Online](http://haml-coffee-online.herokuapp.com/).
|
30
|
+
|
28
31
|
Please note that the `I18n` object in the above example is not part ot Haml Coffee Assets, the internationalization
|
29
32
|
functions are provided by the [i18n.js](https://github.com/fnando/i18n-js) library.
|
30
33
|
|
@@ -52,6 +55,9 @@ below.
|
|
52
55
|
Please have a look at the [CHANGELOG](https://github.com/netzpirat/haml_coffee_assets/blob/master/CHANGELOG.md) when
|
53
56
|
upgrading to a newer Haml Coffee Assets version.
|
54
57
|
|
58
|
+
If you want to use Haml Coffee with Sinatra, please have a look at the
|
59
|
+
[Haml Coffee Sinatra](https://github.com/netzpirat/haml-coffee-sinatra) demo application.
|
60
|
+
|
55
61
|
## Usage
|
56
62
|
|
57
63
|
Haml Coffee Assets allows two different ways of generating your JavaScript templates:
|
@@ -108,8 +114,8 @@ rake assets:clean
|
|
108
114
|
```
|
109
115
|
|
110
116
|
For Rails, you can set the configuration options in your environment by accessing `config.hamlcoffee`, whereas
|
111
|
-
if you just use the
|
112
|
-
examples use the Rails way.
|
117
|
+
if you just use the plain Sprockets engine you can access the configuration with `HamlCoffeeAssets.config`. All the
|
118
|
+
following examples use the Rails way.
|
113
119
|
|
114
120
|
**Please note:** When you put Haml Coffee Assets into the `:assets` group within your `Gemfile` and precompile the
|
115
121
|
assets (the default Rails behaviour), then Haml Coffee Assets is not loaded in production and you can't set any
|
data/lib/js/hamlcoffee.js
CHANGED
@@ -363,6 +363,8 @@ require.define("/haml-coffee.js", function (require, module, exports, __dirname,
|
|
363
363
|
|
364
364
|
module.exports = HamlCoffee = (function() {
|
365
365
|
|
366
|
+
HamlCoffee.VERSION = '1.3.0';
|
367
|
+
|
366
368
|
function HamlCoffee(options) {
|
367
369
|
var _base, _base1, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
|
368
370
|
this.options = options != null ? options : {};
|
@@ -534,7 +536,7 @@ require.define("/haml-coffee.js", function (require, module, exports, __dirname,
|
|
534
536
|
if (/^\s*$/.test(line)) {
|
535
537
|
continue;
|
536
538
|
}
|
537
|
-
while (/^[%.#].*[{(]/.test(expression) && !/^(\s*)[
|
539
|
+
while (/^[%.#].*[{(]/.test(expression) && !/^(\s*)[-=&!~.%#</]/.test(lines[0]) && /([-\w]+[\w:-]*\w?)\s*=|('\w+[\w:-]*\w?')\s*=|("\w+[\w:-]*\w?")\s*=|(\w+[\w:-]*\w?):|('[-\w]+[\w:-]*\w?'):|("[-\w]+[\w:-]*\w?"):|:(\w+[\w:-]*\w?)\s*=>|:?'([-\w]+[\w:-]*\w?)'\s*=>|:?"([-\w]+[\w:-]*\w?)"\s*=>/.test(lines[0])) {
|
538
540
|
attributes = lines.shift();
|
539
541
|
expression = expression.replace(/(\s)+\|\s*$/, '');
|
540
542
|
expression += ' ' + attributes.match(/^\s*(.*?)(\s+\|\s*)?$/)[1];
|
@@ -979,7 +981,7 @@ require.define("/util/text.js", function (require, module, exports, __dirname, _
|
|
979
981
|
if (!text) {
|
980
982
|
return '';
|
981
983
|
}
|
982
|
-
return text.replace(/"/g, '\\"').replace(/\\\\\"/g, '"');
|
984
|
+
return text.replace(/"/g, '\\"').replace(/\\\\\"/g, '\\"');
|
983
985
|
},
|
984
986
|
unescapeQuotes: function(text) {
|
985
987
|
if (!text) {
|
@@ -1255,7 +1257,7 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
|
|
1255
1257
|
}
|
1256
1258
|
type = exp.substring(0, 1);
|
1257
1259
|
exp = exp.replace(/(=|:|=>)\s*('([^\\']|\\\\|\\')*'|"([^\\"]|\\\\|\\")*")/g, function(match, type, value) {
|
1258
|
-
return type + (value != null ? value.replace(/(:|=|=>)
|
1260
|
+
return type + (value != null ? value.replace(/(:|=|=>)/g, '\u0090$1') : void 0);
|
1259
1261
|
});
|
1260
1262
|
level = 0;
|
1261
1263
|
start = 0;
|
@@ -1289,7 +1291,7 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
|
|
1289
1291
|
_ref = markers.reverse();
|
1290
1292
|
for (_j = 0, _len = _ref.length; _j < _len; _j++) {
|
1291
1293
|
marker = _ref[_j];
|
1292
|
-
exp = exp.substring(0, marker.start) + exp.substring(marker.start, marker.end).replace(/(:|=|=>)
|
1294
|
+
exp = exp.substring(0, marker.start) + exp.substring(marker.start, marker.end).replace(/(:|=|=>)/g, '\u0090$1') + exp.substring(marker.end);
|
1293
1295
|
}
|
1294
1296
|
switch (type) {
|
1295
1297
|
case '(':
|
@@ -1307,7 +1309,7 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
|
|
1307
1309
|
if (quoted = key.match(/^("|')(.*)\1$/)) {
|
1308
1310
|
key = quoted[2];
|
1309
1311
|
}
|
1310
|
-
value = (_ref2 = keyValue[1]) != null ? _ref2.replace(/^\s+|[\s,]+$/g, '').replace(/\u0090
|
1312
|
+
value = (_ref2 = keyValue[1]) != null ? _ref2.replace(/^\s+|[\s,]+$/g, '').replace(/\u0090/g, '') : void 0;
|
1311
1313
|
if (key === 'data') {
|
1312
1314
|
inDataAttribute = true;
|
1313
1315
|
hasDataAttribute = true;
|
@@ -1419,7 +1421,7 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
|
|
1419
1421
|
};
|
1420
1422
|
|
1421
1423
|
Haml.prototype.quoteAndEscapeAttributeValue = function(value, code) {
|
1422
|
-
var quoted, result;
|
1424
|
+
var escaped, hasDoubleQuotes, hasInterpolation, hasSingleQuotes, quoted, result, token, tokens, _i, _len;
|
1423
1425
|
if (code == null) {
|
1424
1426
|
code = false;
|
1425
1427
|
}
|
@@ -1429,22 +1431,92 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
|
|
1429
1431
|
if (quoted = value.match(/^("|')(.*)\1$/)) {
|
1430
1432
|
value = quoted[2];
|
1431
1433
|
}
|
1434
|
+
tokens = this.splitInterpolations(value);
|
1435
|
+
hasSingleQuotes = false;
|
1436
|
+
hasDoubleQuotes = false;
|
1437
|
+
hasInterpolation = false;
|
1438
|
+
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
|
1439
|
+
token = tokens[_i];
|
1440
|
+
if (token.slice(0, 2) === '#{') {
|
1441
|
+
hasInterpolation = true;
|
1442
|
+
} else {
|
1443
|
+
if (!hasSingleQuotes) {
|
1444
|
+
hasSingleQuotes = token.indexOf("'") !== -1;
|
1445
|
+
}
|
1446
|
+
if (!hasDoubleQuotes) {
|
1447
|
+
hasDoubleQuotes = token.indexOf('"') !== -1;
|
1448
|
+
}
|
1449
|
+
}
|
1450
|
+
}
|
1432
1451
|
if (code) {
|
1433
|
-
if (
|
1434
|
-
result = "
|
1452
|
+
if (hasInterpolation) {
|
1453
|
+
result = "\"" + (tokens.join('')) + "\"";
|
1435
1454
|
} else {
|
1436
|
-
result = "
|
1455
|
+
result = "'" + (tokens.join('')) + "'";
|
1437
1456
|
}
|
1438
1457
|
} else {
|
1439
|
-
if (
|
1440
|
-
result = "'" + (
|
1441
|
-
}
|
1442
|
-
|
1458
|
+
if (!hasDoubleQuotes && !hasSingleQuotes) {
|
1459
|
+
result = "'" + (tokens.join('')) + "'";
|
1460
|
+
}
|
1461
|
+
if (hasSingleQuotes && !hasDoubleQuotes) {
|
1462
|
+
result = "\\\"" + (tokens.join('')) + "\\\"";
|
1463
|
+
}
|
1464
|
+
if (hasDoubleQuotes && !hasSingleQuotes) {
|
1465
|
+
escaped = (function() {
|
1466
|
+
var _j, _len1, _results;
|
1467
|
+
_results = [];
|
1468
|
+
for (_j = 0, _len1 = tokens.length; _j < _len1; _j++) {
|
1469
|
+
token = tokens[_j];
|
1470
|
+
_results.push(escapeQuotes(token));
|
1471
|
+
}
|
1472
|
+
return _results;
|
1473
|
+
})();
|
1474
|
+
result = "'" + (escaped.join('')) + "'";
|
1475
|
+
}
|
1476
|
+
if (hasSingleQuotes && hasDoubleQuotes) {
|
1477
|
+
escaped = (function() {
|
1478
|
+
var _j, _len1, _results;
|
1479
|
+
_results = [];
|
1480
|
+
for (_j = 0, _len1 = tokens.length; _j < _len1; _j++) {
|
1481
|
+
token = tokens[_j];
|
1482
|
+
_results.push(escapeQuotes(token).replace(/'/g, '''));
|
1483
|
+
}
|
1484
|
+
return _results;
|
1485
|
+
})();
|
1486
|
+
result = "'" + (escaped.join('')) + "'";
|
1443
1487
|
}
|
1444
1488
|
}
|
1445
1489
|
return result;
|
1446
1490
|
};
|
1447
1491
|
|
1492
|
+
Haml.prototype.splitInterpolations = function(value) {
|
1493
|
+
var ch, ch2, level, pos, quoted, start, tokens, _i, _ref;
|
1494
|
+
level = 0;
|
1495
|
+
start = 0;
|
1496
|
+
tokens = [];
|
1497
|
+
quoted = false;
|
1498
|
+
for (pos = _i = 0, _ref = value.length; 0 <= _ref ? _i < _ref : _i > _ref; pos = 0 <= _ref ? ++_i : --_i) {
|
1499
|
+
ch = value[pos];
|
1500
|
+
ch2 = value.slice(pos, (pos + 1) + 1 || 9e9);
|
1501
|
+
if (ch === '{') {
|
1502
|
+
level += 1;
|
1503
|
+
}
|
1504
|
+
if (ch2 === '#{' && level === 0) {
|
1505
|
+
tokens.push(value.slice(start, pos));
|
1506
|
+
start = pos;
|
1507
|
+
}
|
1508
|
+
if (ch === '}') {
|
1509
|
+
level -= 1;
|
1510
|
+
if (level === 0) {
|
1511
|
+
tokens.push(value.slice(start, pos + 1 || 9e9));
|
1512
|
+
start = pos + 1;
|
1513
|
+
}
|
1514
|
+
}
|
1515
|
+
}
|
1516
|
+
tokens.push(value.slice(start, value.length));
|
1517
|
+
return tokens.filter(Boolean);
|
1518
|
+
};
|
1519
|
+
|
1448
1520
|
Haml.prototype.buildDocType = function(doctype) {
|
1449
1521
|
switch ("" + this.format + " " + doctype) {
|
1450
1522
|
case 'xhtml !!! XML':
|
@@ -1541,12 +1613,14 @@ require.define("/nodes/code.js", function (require, module, exports, __dirname,
|
|
1541
1613
|
|
1542
1614
|
require.define("/nodes/comment.js", function (require, module, exports, __dirname, __filename) {
|
1543
1615
|
(function() {
|
1544
|
-
var Comment, Node,
|
1616
|
+
var Comment, Node, escapeQuotes,
|
1545
1617
|
__hasProp = {}.hasOwnProperty,
|
1546
1618
|
__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; };
|
1547
1619
|
|
1548
1620
|
Node = require('./node');
|
1549
1621
|
|
1622
|
+
escapeQuotes = require('../util/text').escapeQuotes;
|
1623
|
+
|
1550
1624
|
module.exports = Comment = (function(_super) {
|
1551
1625
|
|
1552
1626
|
__extends(Comment, _super);
|
@@ -1567,7 +1641,7 @@ require.define("/nodes/comment.js", function (require, module, exports, __dirnam
|
|
1567
1641
|
return this.closer = this.markText('<![endif]-->');
|
1568
1642
|
case '\/':
|
1569
1643
|
if (comment) {
|
1570
|
-
this.opener = this.markText("<!-- " + comment);
|
1644
|
+
this.opener = this.markText("<!-- " + (escapeQuotes(comment)));
|
1571
1645
|
return this.closer = this.markText(' -->');
|
1572
1646
|
} else {
|
1573
1647
|
this.opener = this.markText("<!--");
|
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: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: execjs
|
@@ -107,6 +107,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
hash: 3865159740158855570
|
110
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
114
|
none: false
|
112
115
|
requirements:
|