haml_coffee_assets 1.8.2 → 1.9.1
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/LICENSE +1 -1
- data/README.md +2 -2
- data/lib/haml_coffee_assets/compiler.rb +1 -1
- data/lib/haml_coffee_assets/configuration.rb +5 -0
- data/lib/haml_coffee_assets/version.rb +1 -1
- data/lib/js/haml_coffee_assets.js +4 -2
- data/lib/js/hamlcoffee.js +83 -33
- data/vendor/assets/javascripts/hamlcoffee.js.coffee.erb +27 -0
- data/vendor/assets/javascripts/hamlcoffee_amd.js.coffee.erb +27 -0
- metadata +3 -3
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2011-
|
1
|
+
Copyright (c) 2011-2013 Michael Kessler <michi@netzpiraten.ch>
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -436,7 +436,7 @@ by default. This allows you to render a template within another template like:
|
|
436
436
|
|
437
437
|
```
|
438
438
|
%h1 Comments for this article
|
439
|
-
- for comment in @article.comments
|
439
|
+
- for comment in @article.comments
|
440
440
|
!= JST['articles/comment'](comment)
|
441
441
|
```
|
442
442
|
|
@@ -508,7 +508,7 @@ See the [CHANGELOG](https://github.com/netzpirat/haml_coffee_assets/blob/master/
|
|
508
508
|
|
509
509
|
(The MIT License)
|
510
510
|
|
511
|
-
Copyright (c) 2011-
|
511
|
+
Copyright (c) 2011-2013 Michael Kessler
|
512
512
|
|
513
513
|
Permission is hereby granted, free of charge, to any person obtaining
|
514
514
|
a copy of this software and associated documentation files (the
|
@@ -26,7 +26,7 @@ module HamlCoffeeAssets
|
|
26
26
|
config.escapeHtml, config.escapeAttributes, config.cleanValue, config.placement, config.dependencies,
|
27
27
|
config.customHtmlEscape, config.customCleanValue,
|
28
28
|
config.customPreserve, config.customFindAndPreserve,
|
29
|
-
config.customSurround, config.customSucceed, config.customPrecede,
|
29
|
+
config.customSurround, config.customSucceed, config.customPrecede, config.customReference,
|
30
30
|
config.preserveTags, config.selfCloseTags,
|
31
31
|
config.context, config.extendScope)
|
32
32
|
end
|
@@ -33,6 +33,7 @@ module HamlCoffeeAssets
|
|
33
33
|
self.customSurround = 'window.HAML.surround'
|
34
34
|
self.customSucceed = 'window.HAML.succeed'
|
35
35
|
self.customPrecede = 'window.HAML.precede'
|
36
|
+
self.customReference = 'window.HAML.reference'
|
36
37
|
self.preserveTags = 'textarea,pre'
|
37
38
|
self.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base'
|
38
39
|
self.context = 'window.HAML.context'
|
@@ -100,6 +101,10 @@ module HamlCoffeeAssets
|
|
100
101
|
#
|
101
102
|
attr_accessor :customPreserve
|
102
103
|
|
104
|
+
# Custom object reference function
|
105
|
+
#
|
106
|
+
attr_accessor :customReference
|
107
|
+
|
103
108
|
# Custom find and preserve function
|
104
109
|
#
|
105
110
|
attr_accessor :customFindAndPreserve
|
@@ -27,6 +27,7 @@ var HamlCoffeeAssets = (function(){
|
|
27
27
|
* @param customSurround [String] the name of the function for the surround helper
|
28
28
|
* @param customSucceed [String] the name of the function for the succeed helper
|
29
29
|
* @param customPrecede [String] the name of the function for the precede helper
|
30
|
+
* @param customReference [String] the name of the function for the object reference helper
|
30
31
|
* @param preserveTags [String] comma separated list of tags to preserve whitespace
|
31
32
|
* @param selfCloseTags [String] comma separated list of tags to self-closing tags
|
32
33
|
* @param context [String] the name of the function to merge contexts
|
@@ -35,7 +36,7 @@ var HamlCoffeeAssets = (function(){
|
|
35
36
|
compile: function(name, source, jst, namespace, format, uglify, basename,
|
36
37
|
escapeHtml, escapeAttributes, cleanValue, placement, dependencies,
|
37
38
|
customHtmlEscape, customCleanValue, customPreserve, customFindAndPreserve,
|
38
|
-
customSurround, customSucceed, customPrecede,
|
39
|
+
customSurround, customSucceed, customPrecede, customReference,
|
39
40
|
preserveTags, selfCloseTags,
|
40
41
|
context, extendScope) {
|
41
42
|
|
@@ -55,6 +56,7 @@ var HamlCoffeeAssets = (function(){
|
|
55
56
|
customSurround: customSurround,
|
56
57
|
customSucceed: customSucceed,
|
57
58
|
customPrecede: customPrecede,
|
59
|
+
customReference: customReference,
|
58
60
|
preserveTags: preserveTags,
|
59
61
|
selfCloseTags: selfCloseTags,
|
60
62
|
extendScope: extendScope
|
@@ -78,7 +80,7 @@ var HamlCoffeeAssets = (function(){
|
|
78
80
|
}
|
79
81
|
|
80
82
|
if (context !== '' && context !== false) {
|
81
|
-
// With AMD we replace the context function with the one from the hamlcoffee AMD module if not set explicit
|
83
|
+
// With AMD we replace the context function with the one from the hamlcoffee AMD module if not set explicit
|
82
84
|
if (placement === 'amd' && context === 'window.HAML.context' && /^hamlcoffee/.test(dependencies['hc'])) {
|
83
85
|
context = 'hc.context';
|
84
86
|
}
|
data/lib/js/hamlcoffee.js
CHANGED
@@ -363,7 +363,7 @@ require.define("/haml-coffee.coffee", function (require, module, exports, __dirn
|
|
363
363
|
|
364
364
|
module.exports = HamlCoffee = (function() {
|
365
365
|
|
366
|
-
HamlCoffee.VERSION = '1.
|
366
|
+
HamlCoffee.VERSION = '1.9.1';
|
367
367
|
|
368
368
|
function HamlCoffee(options) {
|
369
369
|
var _base, _base10, _base11, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _base9, _ref, _ref10, _ref11, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
|
@@ -591,6 +591,7 @@ require.define("/haml-coffee.coffee", function (require, module, exports, __dirn
|
|
591
591
|
this.options.customSurround = 'hc.surround';
|
592
592
|
this.options.customSucceed = 'hc.succeed';
|
593
593
|
this.options.customPrecede = 'hc.precede';
|
594
|
+
this.options.customReference = 'hc.reference';
|
594
595
|
}
|
595
596
|
modules = [];
|
596
597
|
params = [];
|
@@ -711,6 +712,13 @@ require.define("/haml-coffee.coffee", function (require, module, exports, __dirn
|
|
711
712
|
fn += "precede = (start, fn) => start + fn.call(@)?.replace(/^\s+/g, '')\n";
|
712
713
|
}
|
713
714
|
}
|
715
|
+
if (code.indexOf('$r') !== -1) {
|
716
|
+
if (this.options.customReference) {
|
717
|
+
fn += "$r = " + this.options.customReference + "\n";
|
718
|
+
} else {
|
719
|
+
fn += "$r = (object, prefix) ->\n name = if prefix then prefix + '_' else ''\n\n if typeof(object.hamlObjectRef) is 'function'\n name += object.hamlObjectRef()\n else\n name += (object.constructor?.name || 'object').replace(/\W+/g, '_').replace(/([a-z\d])([A-Z])/g, '$1_$2').toLowerCase()\n\n id = if typeof(object.to_key) is 'function'\n object.to_key()\n else if typeof(object.id) is 'function'\n object.id()\n else if object.id\n object.id\n else\n object\n\n result = \"class='\#{ name }'\"\n result += \" id='\#{ name }_\#{ id }'\" if id\n";
|
720
|
+
}
|
721
|
+
}
|
714
722
|
fn += "$o = []\n";
|
715
723
|
fn += "" + code + "\n";
|
716
724
|
return fn += "return $o.join(\"\\n\")" + (this.convertBooleans(code)) + (this.removeEmptyIDAndClass(code)) + (this.cleanupWhitespace(code)) + "\n";
|
@@ -1187,12 +1195,13 @@ require.define("/nodes/haml.coffee", function (require, module, exports, __dirna
|
|
1187
1195
|
classes: classes,
|
1188
1196
|
text: escapeQuotes(tag.text),
|
1189
1197
|
attributes: attributes,
|
1190
|
-
assignment: tag.assignment
|
1198
|
+
assignment: tag.assignment,
|
1199
|
+
reference: tag.reference
|
1191
1200
|
};
|
1192
1201
|
};
|
1193
1202
|
|
1194
1203
|
Haml.prototype.parseTag = function(exp) {
|
1195
|
-
var assignment, attributes, ch, classes, doctype, end, haml, id, ids, klass, level, pos, rest, start, tag, text, whitespace, _ref, _ref2, _ref3;
|
1204
|
+
var assignment, attr, attributes, ch, classes, doctype, end, haml, htmlAttributes, id, ids, key, klass, level, pos, reference, rest, rubyAttributes, start, tag, text, val, whitespace, _i, _j, _len, _len2, _ref, _ref2, _ref3, _ref4, _ref5;
|
1196
1205
|
try {
|
1197
1206
|
doctype = (_ref = exp.match(/^(\!{3}.*)/)) != null ? _ref[1] : void 0;
|
1198
1207
|
if (doctype) {
|
@@ -1202,35 +1211,68 @@ require.define("/nodes/haml.coffee", function (require, module, exports, __dirna
|
|
1202
1211
|
}
|
1203
1212
|
haml = exp.match(/^((?:[#%\.][a-z0-9_:\-]*[\/]?)+)/i)[0];
|
1204
1213
|
rest = exp.substring(haml.length);
|
1205
|
-
if (rest.match(/^[{(]/)) {
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
}
|
1223
|
-
|
1214
|
+
if (rest.match(/^[{([]/)) {
|
1215
|
+
reference = '';
|
1216
|
+
htmlAttributes = '';
|
1217
|
+
rubyAttributes = '';
|
1218
|
+
_ref2 = ['[', '{', '(', '[', '{', '('];
|
1219
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1220
|
+
start = _ref2[_i];
|
1221
|
+
if (start === rest[0]) {
|
1222
|
+
end = (function() {
|
1223
|
+
switch (start) {
|
1224
|
+
case '{':
|
1225
|
+
return '}';
|
1226
|
+
case '(':
|
1227
|
+
return ')';
|
1228
|
+
case '[':
|
1229
|
+
return ']';
|
1230
|
+
}
|
1231
|
+
})();
|
1232
|
+
level = 0;
|
1233
|
+
for (pos = 0, _ref3 = rest.length; 0 <= _ref3 ? pos <= _ref3 : pos >= _ref3; 0 <= _ref3 ? pos++ : pos--) {
|
1234
|
+
ch = rest[pos];
|
1235
|
+
if (ch === start) level += 1;
|
1236
|
+
if (ch === end) {
|
1237
|
+
if (level === 1) {
|
1238
|
+
break;
|
1239
|
+
} else {
|
1240
|
+
level -= 1;
|
1241
|
+
}
|
1242
|
+
}
|
1243
|
+
}
|
1244
|
+
switch (start) {
|
1245
|
+
case '{':
|
1246
|
+
rubyAttributes += rest.substring(0, pos + 1);
|
1247
|
+
rest = rest.substring(pos + 1);
|
1248
|
+
break;
|
1249
|
+
case '(':
|
1250
|
+
htmlAttributes += rest.substring(0, pos + 1);
|
1251
|
+
rest = rest.substring(pos + 1);
|
1252
|
+
break;
|
1253
|
+
case '[':
|
1254
|
+
reference = rest.substring(1, pos);
|
1255
|
+
rest = rest.substring(pos + 1);
|
1224
1256
|
}
|
1225
1257
|
}
|
1226
1258
|
}
|
1227
|
-
|
1228
|
-
assignment = rest.substring(pos + 1);
|
1259
|
+
assignment = rest || '';
|
1229
1260
|
} else {
|
1230
|
-
|
1261
|
+
reference = '';
|
1262
|
+
htmlAttributes = '';
|
1263
|
+
rubyAttributes = '';
|
1231
1264
|
assignment = rest;
|
1232
1265
|
}
|
1233
|
-
|
1266
|
+
attributes = {};
|
1267
|
+
_ref4 = [this.parseAttributes(htmlAttributes), this.parseAttributes(rubyAttributes)];
|
1268
|
+
for (_j = 0, _len2 = _ref4.length; _j < _len2; _j++) {
|
1269
|
+
attr = _ref4[_j];
|
1270
|
+
for (key in attr) {
|
1271
|
+
val = attr[key];
|
1272
|
+
attributes[key] = val;
|
1273
|
+
}
|
1274
|
+
}
|
1275
|
+
if (whitespace = (_ref5 = assignment.match(/^[<>]{0,2}/)) != null ? _ref5[0] : void 0) {
|
1234
1276
|
assignment = assignment.substring(whitespace.length);
|
1235
1277
|
}
|
1236
1278
|
if (assignment[0] === ' ') assignment = assignment.substring(1);
|
@@ -1251,25 +1293,26 @@ require.define("/nodes/haml.coffee", function (require, module, exports, __dirna
|
|
1251
1293
|
return {
|
1252
1294
|
tag: tag ? tag[1] : 'div',
|
1253
1295
|
ids: ids ? (function() {
|
1254
|
-
var
|
1296
|
+
var _k, _len3, _results;
|
1255
1297
|
_results = [];
|
1256
|
-
for (
|
1257
|
-
id = ids[
|
1298
|
+
for (_k = 0, _len3 = ids.length; _k < _len3; _k++) {
|
1299
|
+
id = ids[_k];
|
1258
1300
|
_results.push("'" + (id.substr(1)) + "'");
|
1259
1301
|
}
|
1260
1302
|
return _results;
|
1261
1303
|
})() : void 0,
|
1262
1304
|
classes: classes ? (function() {
|
1263
|
-
var
|
1305
|
+
var _k, _len3, _results;
|
1264
1306
|
_results = [];
|
1265
|
-
for (
|
1266
|
-
klass = classes[
|
1307
|
+
for (_k = 0, _len3 = classes.length; _k < _len3; _k++) {
|
1308
|
+
klass = classes[_k];
|
1267
1309
|
_results.push("'" + (klass.substr(1)) + "'");
|
1268
1310
|
}
|
1269
1311
|
return _results;
|
1270
1312
|
})() : void 0,
|
1271
|
-
attributes:
|
1313
|
+
attributes: attributes,
|
1272
1314
|
assignment: assignment,
|
1315
|
+
reference: reference,
|
1273
1316
|
text: text
|
1274
1317
|
};
|
1275
1318
|
} catch (error) {
|
@@ -1385,6 +1428,13 @@ require.define("/nodes/haml.coffee", function (require, module, exports, __dirna
|
|
1385
1428
|
tagParts.push("class='" + classes + "'");
|
1386
1429
|
}
|
1387
1430
|
if (tokens.id) tagParts.push("id='" + tokens.id + "'");
|
1431
|
+
if (tokens.reference) {
|
1432
|
+
if (tokens.attributes) {
|
1433
|
+
delete tokens.attributes['class'];
|
1434
|
+
delete tokens.attributes['id'];
|
1435
|
+
}
|
1436
|
+
tagParts.push("\#{$r(" + tokens.reference + ")}");
|
1437
|
+
}
|
1388
1438
|
if (tokens.attributes) {
|
1389
1439
|
_ref = tokens.attributes;
|
1390
1440
|
for (key in _ref) {
|
@@ -108,3 +108,30 @@ class window.HAML
|
|
108
108
|
#
|
109
109
|
@precede: (start, fn) ->
|
110
110
|
start + fn.call(@)?.replace(/^\s+/g, '')
|
111
|
+
|
112
|
+
# The reference helper creates id and class attributes
|
113
|
+
# for an object reference.
|
114
|
+
#
|
115
|
+
# @param [Object] object the referenced object
|
116
|
+
# @param [String] prefix the optional id and class prefix
|
117
|
+
# @return [String] the id and class attributes
|
118
|
+
#
|
119
|
+
@reference: (object, prefix) ->
|
120
|
+
name = if prefix then prefix + '_' else ''
|
121
|
+
|
122
|
+
if typeof(object.hamlObjectRef) is 'function'
|
123
|
+
name += object.hamlObjectRef()
|
124
|
+
else
|
125
|
+
name += (object.constructor?.name || 'object').replace(/\W+/g, '_').replace(/([a-z\d])([A-Z])/g, '$1_$2').toLowerCase()
|
126
|
+
|
127
|
+
id = if typeof(object.to_key) is 'function'
|
128
|
+
object.to_key()
|
129
|
+
else if typeof(object.id) is 'function'
|
130
|
+
object.id()
|
131
|
+
else if object.id
|
132
|
+
object.id
|
133
|
+
else
|
134
|
+
object
|
135
|
+
|
136
|
+
result = "class='#{ name }'"
|
137
|
+
result += " id='#{ name }_#{ id }'" if id
|
@@ -89,3 +89,30 @@ define ->
|
|
89
89
|
# @return [Object] the merged context
|
90
90
|
#
|
91
91
|
context: (locals) -> locals
|
92
|
+
|
93
|
+
# The reference helper creates id and class attributes
|
94
|
+
# for an object reference.
|
95
|
+
#
|
96
|
+
# @param [Object] object the referenced object
|
97
|
+
# @param [String] prefix the optional id and class prefix
|
98
|
+
# @return [String] the id and class attributes
|
99
|
+
#
|
100
|
+
reference: (object, prefix) ->
|
101
|
+
name = if prefix then prefix + '_' else ''
|
102
|
+
|
103
|
+
if typeof(object.hamlObjectRef) is 'function'
|
104
|
+
name += object.hamlObjectRef()
|
105
|
+
else
|
106
|
+
name += (object.constructor?.name || 'object').replace(/\W+/g, '_').replace(/([a-z\d])([A-Z])/g, '$1_$2').toLowerCase()
|
107
|
+
|
108
|
+
id = if typeof(object.to_key) is 'function'
|
109
|
+
object.to_key()
|
110
|
+
else if typeof(object.id) is 'function'
|
111
|
+
object.id()
|
112
|
+
else if object.id
|
113
|
+
object.id
|
114
|
+
else
|
115
|
+
object
|
116
|
+
|
117
|
+
result = "class='#{ name }'"
|
118
|
+
result += " id='#{ name }_#{ id }'" if i
|
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.9.1
|
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:
|
12
|
+
date: 2013-01-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: coffee-script
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
version: 1.3.6
|
116
116
|
requirements: []
|
117
117
|
rubyforge_project: haml_coffee_assets
|
118
|
-
rubygems_version: 1.8.
|
118
|
+
rubygems_version: 1.8.23
|
119
119
|
signing_key:
|
120
120
|
specification_version: 3
|
121
121
|
summary: Haml CoffeeScript templates
|