haml_coffee_assets 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  # coding: UTF-8
2
2
 
3
3
  module HamlCoffeeAssets
4
- VERSION = '1.0.0' unless defined?(HamlCoffeeAssets::VERSION)
4
+ VERSION = '1.1.0' unless defined?(HamlCoffeeAssets::VERSION)
5
5
  end
@@ -618,7 +618,11 @@ require.define("/haml-coffee.js", function (require, module, exports, __dirname,
618
618
  if (this.options.customCleanValue) {
619
619
  fn += "$c = " + this.options.customCleanValue + "\n";
620
620
  } else {
621
- fn += "$c = (text) -> if text is null or text is undefined then '' else text\n";
621
+ fn += "$c = (text) ->\n";
622
+ fn += " switch text\n";
623
+ fn += " when null, undefined then ''\n";
624
+ fn += " when true, false then '\u0093' + text\n";
625
+ fn += " else text\n";
622
626
  }
623
627
  }
624
628
  if (code.indexOf('$p') !== -1 || code.indexOf('$fp') !== -1) {
@@ -738,9 +742,9 @@ require.define("/haml-coffee.js", function (require, module, exports, __dirname,
738
742
 
739
743
  HamlCoffee.prototype.convertBooleans = function(code) {
740
744
  if (this.options.format === 'xhtml') {
741
- return '.replace(/\\s(\\w+)=\'true\'/mg, " $1=\'$1\'").replace(/\\s(\\w+)=\'false\'/mg, \'\')';
745
+ return '.replace(/\\s(\\w+)=\'\u0093true\'/mg, " $1=\'$1\'").replace(/\\s(\\w+)=\'\u0093false\'/mg, \'\')';
742
746
  } else {
743
- return '.replace(/\\s(\\w+)=\'true\'/mg, \' $1\').replace(/\\s(\\w+)=\'false\'/mg, \'\')';
747
+ return '.replace(/\\s(\\w+)=\'\u0093true\'/mg, \' $1\').replace(/\\s(\\w+)=\'\u0093false\'/mg, \'\')';
744
748
  }
745
749
  };
746
750
 
@@ -1047,7 +1051,7 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
1047
1051
  return this.opener = this.markText("" + (escapeQuotes(this.buildDocType(tokens.doctype))));
1048
1052
  } else {
1049
1053
  if (this.isNotSelfClosing(tokens.tag)) {
1050
- prefix = escapeQuotes(this.buildHtmlTagPrefix(tokens));
1054
+ prefix = this.buildHtmlTagPrefix(tokens);
1051
1055
  if (tokens.assignment) {
1052
1056
  match = tokens.assignment.match(/^(=|!=|&=|~)\s*(.*)$/);
1053
1057
  identifier = match[1];
@@ -1094,36 +1098,36 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
1094
1098
  }
1095
1099
  } else {
1096
1100
  tokens.tag = tokens.tag.replace(/\/$/, '');
1097
- prefix = escapeQuotes(this.buildHtmlTagPrefix(tokens));
1101
+ prefix = this.buildHtmlTagPrefix(tokens);
1098
1102
  return this.opener = this.markText("" + prefix + (this.format === 'xhtml' ? ' /' : '') + ">");
1099
1103
  }
1100
1104
  }
1101
1105
  };
1102
1106
 
1103
1107
  Haml.prototype.parseExpression = function(exp) {
1104
- var attribute, attributes, classes, id, tag, _i, _len, _ref, _ref1;
1108
+ var attributes, classes, id, key, tag, value, _ref, _ref1;
1105
1109
  tag = this.parseTag(exp);
1106
1110
  if (this.preserveTags.indexOf(tag.tag) !== -1) {
1107
1111
  this.preserve = true;
1108
1112
  }
1109
- id = (_ref = tag.ids) != null ? _ref.pop() : void 0;
1113
+ id = this.wrapCode((_ref = tag.ids) != null ? _ref.pop() : void 0, true);
1110
1114
  classes = tag.classes;
1111
- attributes = [];
1115
+ attributes = {};
1112
1116
  if (tag.attributes) {
1113
1117
  _ref1 = tag.attributes;
1114
- for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
1115
- attribute = _ref1[_i];
1116
- if (attribute.key === 'id') {
1118
+ for (key in _ref1) {
1119
+ value = _ref1[key];
1120
+ if (key === 'id') {
1117
1121
  if (id) {
1118
- id += '_' + attribute.value;
1122
+ id += '_' + this.wrapCode(value, true);
1119
1123
  } else {
1120
- id = attribute.value;
1124
+ id = this.wrapCode(value, true);
1121
1125
  }
1122
- } else if (attribute.key === 'class') {
1126
+ } else if (key === 'class') {
1123
1127
  classes || (classes = []);
1124
- classes.push(attribute.value);
1128
+ classes.push(value);
1125
1129
  } else {
1126
- attributes.push(attribute);
1130
+ attributes[key] = value;
1127
1131
  }
1128
1132
  }
1129
1133
  }
@@ -1208,7 +1212,7 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
1208
1212
  _results = [];
1209
1213
  for (_j = 0, _len = ids.length; _j < _len; _j++) {
1210
1214
  id = ids[_j];
1211
- _results.push(id.substr(1));
1215
+ _results.push("'" + (id.substr(1)) + "'");
1212
1216
  }
1213
1217
  return _results;
1214
1218
  })() : void 0,
@@ -1217,7 +1221,7 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
1217
1221
  _results = [];
1218
1222
  for (_j = 0, _len = classes.length; _j < _len; _j++) {
1219
1223
  klass = classes[_j];
1220
- _results.push(klass.substr(1));
1224
+ _results.push("'" + (klass.substr(1)) + "'");
1221
1225
  }
1222
1226
  return _results;
1223
1227
  })() : void 0,
@@ -1231,53 +1235,11 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
1231
1235
  };
1232
1236
 
1233
1237
  Haml.prototype.parseAttributes = function(exp) {
1234
- var attributes, bool, key, quoted, value, _ref;
1235
- attributes = [];
1238
+ var attributes, hasDataAttribute, inDataAttribute, key, keyValue, keys, pairs, quoted, type, value, _ref, _ref1;
1239
+ attributes = {};
1236
1240
  if (exp === void 0) {
1237
1241
  return attributes;
1238
1242
  }
1239
- _ref = this.extractAttributes(exp);
1240
- for (key in _ref) {
1241
- value = _ref[key];
1242
- bool = false;
1243
- if (['false', ''].indexOf(value) === -1) {
1244
- if (['true'].indexOf(value) !== -1) {
1245
- value = "'" + key + "'";
1246
- bool = true;
1247
- } else if (!value.match(/^("|').*\1$/)) {
1248
- if (this.escapeAttributes) {
1249
- if (this.cleanValue) {
1250
- value = '\'#{ $e($c(' + value + ')) }\'';
1251
- } else {
1252
- value = '\'#{ $e(' + value + ') }\'';
1253
- }
1254
- } else {
1255
- if (this.cleanValue) {
1256
- value = '\'#{ $c(' + value + ') }\'';
1257
- } else {
1258
- value = '\'#{ (' + value + ') }\'';
1259
- }
1260
- }
1261
- }
1262
- if (quoted = value.match(/^("|')(.*)\1$/)) {
1263
- value = quoted[2];
1264
- }
1265
- if (quoted = key.match(/^("|')(.*)\1$/)) {
1266
- key = quoted[2];
1267
- }
1268
- attributes.push({
1269
- key: key,
1270
- value: value,
1271
- bool: bool
1272
- });
1273
- }
1274
- }
1275
- return attributes;
1276
- };
1277
-
1278
- Haml.prototype.extractAttributes = function(exp) {
1279
- var attributes, dataAttribute, key, keyValue, keys, pairs, quoted, type, value, _ref, _ref1;
1280
- attributes = {};
1281
1243
  type = exp.substring(0, 1);
1282
1244
  exp = exp.replace(/(=|:|=>)\s*('([^\\']|\\\\|\\')*'|"([^\\"]|\\\\|\\")*")/g, function(match, type, value) {
1283
1245
  return type + (value != null ? value.replace(/(:|=|=>)/, '\u0090$1') : void 0);
@@ -1290,7 +1252,8 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
1290
1252
  keys = /[{,]\s*(\w+[\w:-]*\w?):|[{,]\s*('[-\w]+[\w:-]*\w?'):|[{,]\s*("[-\w]+[\w:-]*\w?"):|[{,]\s*:(\w+[\w:-]*\w?)\s*=>|[{,]\s*:?'([-\w]+[\w:-]*\w?)'\s*=>|[{,]\s*:?"([-\w]+[\w:-]*\w?)"\s*=>/g;
1291
1253
  }
1292
1254
  pairs = exp.split(keys).filter(Boolean);
1293
- dataAttribute = false;
1255
+ inDataAttribute = false;
1256
+ hasDataAttribute = false;
1294
1257
  while (pairs.length) {
1295
1258
  keyValue = pairs.splice(0, 2);
1296
1259
  key = (_ref = keyValue[0]) != null ? _ref.replace(/^\s+|\s+$/g, '').replace(/^:/, '') : void 0;
@@ -1299,12 +1262,13 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
1299
1262
  }
1300
1263
  value = (_ref1 = keyValue[1]) != null ? _ref1.replace(/^\s+|[\s,]+$/g, '').replace(/\u0090/, '') : void 0;
1301
1264
  if (key === 'data') {
1302
- dataAttribute = true;
1265
+ inDataAttribute = true;
1266
+ hasDataAttribute = true;
1303
1267
  } else if (key && value) {
1304
- if (dataAttribute) {
1268
+ if (inDataAttribute) {
1305
1269
  key = "data-" + key;
1306
1270
  if (/}\s*$/.test(value)) {
1307
- dataAttribute = false;
1271
+ inDataAttribute = false;
1308
1272
  }
1309
1273
  }
1310
1274
  }
@@ -1316,28 +1280,40 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
1316
1280
  attributes[key] = value.replace(/^\s+|[\s}]+$/g, '');
1317
1281
  }
1318
1282
  }
1283
+ if (hasDataAttribute) {
1284
+ delete attributes['data'];
1285
+ }
1319
1286
  return attributes;
1320
1287
  };
1321
1288
 
1322
1289
  Haml.prototype.buildHtmlTagPrefix = function(tokens) {
1323
- var attribute, classes, interpolation, klass, tagParts, _i, _j, _len, _len1, _ref, _ref1;
1290
+ var classList, classes, hasDynamicClass, key, klass, name, tagParts, value, _i, _len, _ref;
1324
1291
  tagParts = ["<" + tokens.tag];
1325
1292
  if (tokens.classes) {
1326
- classes = tokens.classes.sort().join(' ');
1327
- if (tokens.classes.length > 1 && classes.match(/#\{/)) {
1328
- classes = '#{ [';
1293
+ hasDynamicClass = false;
1294
+ classList = (function() {
1295
+ var _i, _len, _ref, _results;
1329
1296
  _ref = tokens.classes;
1297
+ _results = [];
1330
1298
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1331
- klass = _ref[_i];
1332
- if (interpolation = klass.match(/^#{(.*)}$/)) {
1333
- classes += "(" + interpolation[1] + "),";
1334
- } else if (interpolation = klass.match(/#{(.*)}/)) {
1335
- classes += "\\\"" + klass + "\\\"";
1336
- } else {
1337
- classes += "'" + klass + "',";
1299
+ name = _ref[_i];
1300
+ name = this.wrapCode(name, true);
1301
+ if (name.indexOf('#{') !== -1) {
1302
+ hasDynamicClass = true;
1338
1303
  }
1304
+ _results.push(name);
1305
+ }
1306
+ return _results;
1307
+ }).call(this);
1308
+ if (hasDynamicClass && classList.length > 1) {
1309
+ classes = '#{ [';
1310
+ for (_i = 0, _len = classList.length; _i < _len; _i++) {
1311
+ klass = classList[_i];
1312
+ classes += "" + (this.quoteAndEscapeAttributeValue(klass, true)) + ",";
1339
1313
  }
1340
- classes += '].sort().join(\' \') }';
1314
+ classes = classes.substring(0, classes.length - 1) + '].sort().join(\' \').trim() }';
1315
+ } else {
1316
+ classes = classList.sort().join(' ');
1341
1317
  }
1342
1318
  tagParts.push("class='" + classes + "'");
1343
1319
  }
@@ -1345,27 +1321,81 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
1345
1321
  tagParts.push("id='" + tokens.id + "'");
1346
1322
  }
1347
1323
  if (tokens.attributes) {
1348
- _ref1 = tokens.attributes;
1349
- for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
1350
- attribute = _ref1[_j];
1351
- if (attribute.bool && this.format === 'html5') {
1352
- tagParts.push("" + attribute.key);
1324
+ _ref = tokens.attributes;
1325
+ for (key in _ref) {
1326
+ value = _ref[key];
1327
+ if (value === 'true' || value === 'false') {
1328
+ if (value === 'true') {
1329
+ if (this.format === 'html5') {
1330
+ tagParts.push("" + key);
1331
+ } else {
1332
+ tagParts.push("" + key + "=" + (this.quoteAndEscapeAttributeValue(key)));
1333
+ }
1334
+ }
1353
1335
  } else {
1354
- tagParts.push("" + attribute.key + "=" + (this.quoteAttributeValue(attribute.value)));
1336
+ tagParts.push("" + key + "=" + (this.quoteAndEscapeAttributeValue(this.wrapCode(value))));
1355
1337
  }
1356
1338
  }
1357
1339
  }
1358
1340
  return tagParts.join(' ');
1359
1341
  };
1360
1342
 
1361
- Haml.prototype.quoteAttributeValue = function(value) {
1343
+ Haml.prototype.wrapCode = function(text, unwrap) {
1362
1344
  var quoted;
1363
- if (value.indexOf("'") === -1) {
1364
- quoted = "'" + value + "'";
1345
+ if (unwrap == null) {
1346
+ unwrap = false;
1347
+ }
1348
+ if (!text) {
1349
+ return;
1350
+ }
1351
+ if (!text.match(/^("|').*\1$/)) {
1352
+ if (this.escapeAttributes) {
1353
+ if (this.cleanValue) {
1354
+ text = '#{ $e($c(' + text + ')) }';
1355
+ } else {
1356
+ text = '#{ $e(' + text + ') }';
1357
+ }
1358
+ } else {
1359
+ if (this.cleanValue) {
1360
+ text = '#{ $c(' + text + ') }';
1361
+ } else {
1362
+ text = '#{ (' + text + ') }';
1363
+ }
1364
+ }
1365
+ }
1366
+ if (unwrap) {
1367
+ if (quoted = text.match(/^("|')(.*)\1$/)) {
1368
+ text = quoted[2];
1369
+ }
1370
+ }
1371
+ return text;
1372
+ };
1373
+
1374
+ Haml.prototype.quoteAndEscapeAttributeValue = function(value, code) {
1375
+ var quoted, result;
1376
+ if (code == null) {
1377
+ code = false;
1378
+ }
1379
+ if (!value) {
1380
+ return;
1381
+ }
1382
+ if (quoted = value.match(/^("|')(.*)\1$/)) {
1383
+ value = quoted[2];
1384
+ }
1385
+ if (code) {
1386
+ if (value.indexOf('#{') === -1) {
1387
+ result = "'" + value + "'";
1388
+ } else {
1389
+ result = "\"" + value + "\"";
1390
+ }
1365
1391
  } else {
1366
- quoted = "\"" + value + "\"";
1392
+ if (value.indexOf('#{') === -1) {
1393
+ result = "'" + (value.replace(/'/g, '\\\"')) + "'";
1394
+ } else {
1395
+ result = "'" + value + "'";
1396
+ }
1367
1397
  }
1368
- return quoted;
1398
+ return result;
1369
1399
  };
1370
1400
 
1371
1401
  Haml.prototype.buildDocType = function(doctype) {
@@ -2,7 +2,7 @@
2
2
  #
3
3
  class window.HAML
4
4
 
5
- # HAML Coffee html escape function
5
+ # HAML Coffee html escape function.
6
6
  #
7
7
  # @param text [String] the text to escape
8
8
  # @return [String] the escaped text
@@ -15,13 +15,21 @@ class window.HAML
15
15
  .replace(/"/g, "&quot;")
16
16
  .replace(/'/g, "&apos;")
17
17
 
18
- # HAML Coffee clean value function
18
+ # HAML Coffee clean value function. Beside just
19
+ # cleaning `null` and `undefined` values, it
20
+ # adds a hidden unicode marker character to
21
+ # boolean values, so that the render time boolean
22
+ # logic can distinguish between real booleans and
23
+ # boolean-like strings.
19
24
  #
20
25
  # @param text [String] the text to be cleaned
21
26
  # @return [String] the cleaned text
22
27
  #
23
28
  @cleanValue: (text) ->
24
- if text is null or text is undefined then '' else text
29
+ switch text
30
+ when null, undefined then ''
31
+ when true, false then '\u0093' + text
32
+ else text
25
33
 
26
34
  # Extends an object with the properties from
27
35
  # the source objects.
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.0.0
4
+ version: 1.1.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-06-10 00:00:00.000000000 Z
12
+ date: 2012-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: execjs
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  segments:
111
111
  - 0
112
- hash: -738589441708461623
112
+ hash: 845884151955554491
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  none: false
115
115
  requirements: