joosy 1.2.0.alpha.55 → 1.2.0.alpha.56
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.
- checksums.yaml +4 -4
- data/bower.json +1 -1
- data/build/joosy/extensions/resources-form.js +2 -2
- data/build/joosy/extensions/resources.js +19 -26
- data/build/joosy.js +3 -3
- data/package.json +1 -1
- data/source/joosy/extensions/resources/rest.coffee +16 -30
- data/source/joosy/extensions/resources-form/form.coffee +2 -2
- data/source/joosy/module.coffee +0 -4
- data/source/joosy/modules/dom.coffee +3 -3
- data/spec/joosy/extensions/resources/rest_spec.coffee +70 -57
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffe45ebccb32a88133ea2c952189ea4942d15e0e
|
4
|
+
data.tar.gz: 6abce34a7d8760160a0e5eccd8bbffb0a09c0e14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed3d5616f102390ddaec6797dac25c0d6842c93bfd7c4329350ba4ef0fe9bdd14cc27af709945fdb32326b63ca562b66431b799e1713815afd508022422d87f5
|
7
|
+
data.tar.gz: 3b6e52d5eb9e28b3916d5c931f17bf590a4ad42bdebad55a4d3ae5291334c2679a06597a224ce6b54630ab255d30eded88eb41384f34e91af5b18dd65801c321
|
data/bower.json
CHANGED
@@ -132,7 +132,7 @@
|
|
132
132
|
Object.each(data, function(property, val) {
|
133
133
|
var entity, i, input, key, _i, _len, _ref, _results;
|
134
134
|
key = _this.concatFieldName(scope, property);
|
135
|
-
input = _this.$fields("[name='" + key + "']:not(:file),[name='" + (key.underscore()) + "']:not(:file),[name='" + (key.camelize(false)) + "']:not(:file)");
|
135
|
+
input = _this.$fields().filter("[name='" + key + "']:not(:file),[name='" + (key.underscore()) + "']:not(:file),[name='" + (key.camelize(false)) + "']:not(:file)");
|
136
136
|
if (input.length > 0) {
|
137
137
|
if (input.is(':checkbox')) {
|
138
138
|
if (val) {
|
@@ -247,7 +247,7 @@
|
|
247
247
|
};
|
248
248
|
|
249
249
|
Form.prototype.findField = function(field) {
|
250
|
-
return this.$fields("[name='" + field + "']");
|
250
|
+
return this.$fields().filter("[name='" + field + "']");
|
251
251
|
};
|
252
252
|
|
253
253
|
Form.prototype.__markMethod = function(method) {
|
@@ -428,11 +428,14 @@
|
|
428
428
|
}, '');
|
429
429
|
};
|
430
430
|
|
431
|
-
REST.
|
431
|
+
REST.collectionPath = function(options) {
|
432
432
|
var path;
|
433
433
|
if (options == null) {
|
434
434
|
options = {};
|
435
435
|
}
|
436
|
+
if (options.url) {
|
437
|
+
return options.url;
|
438
|
+
}
|
436
439
|
if ((this.__source != null) && (options.parent == null)) {
|
437
440
|
path = this.__source;
|
438
441
|
} else {
|
@@ -447,52 +450,42 @@
|
|
447
450
|
if (options.parent != null) {
|
448
451
|
path = this.__parentsPath(Object.isArray(options.parent) ? options.parent : [options.parent]) + path;
|
449
452
|
}
|
450
|
-
return path;
|
451
|
-
};
|
452
|
-
|
453
|
-
REST.prototype.basePath = function(options) {
|
454
|
-
if (options == null) {
|
455
|
-
options = {};
|
456
|
-
}
|
457
|
-
return this.constructor.basePath(options);
|
458
|
-
};
|
459
|
-
|
460
|
-
REST.memberPath = function(id, options) {
|
461
|
-
var path;
|
462
|
-
if (options == null) {
|
463
|
-
options = {};
|
464
|
-
}
|
465
|
-
path = this.basePath(options) + ("/" + id);
|
466
453
|
if (options.from != null) {
|
467
454
|
path += "/" + options.from;
|
468
455
|
}
|
469
456
|
return path;
|
470
457
|
};
|
471
458
|
|
472
|
-
REST.prototype.
|
459
|
+
REST.prototype.collectionPath = function(options) {
|
473
460
|
if (options == null) {
|
474
461
|
options = {};
|
475
462
|
}
|
476
|
-
return this.constructor.
|
463
|
+
return this.constructor.collectionPath(options);
|
477
464
|
};
|
478
465
|
|
479
|
-
REST.
|
480
|
-
var path;
|
466
|
+
REST.memberPath = function(id, options) {
|
467
|
+
var from, path;
|
481
468
|
if (options == null) {
|
482
469
|
options = {};
|
483
470
|
}
|
484
|
-
|
485
|
-
|
486
|
-
|
471
|
+
if (options.url) {
|
472
|
+
return options.url;
|
473
|
+
}
|
474
|
+
from = options.from;
|
475
|
+
path = this.collectionPath(Object.merge(options, {
|
476
|
+
from: void 0
|
477
|
+
})) + ("/" + id);
|
478
|
+
if (from != null) {
|
479
|
+
path += "/" + from;
|
487
480
|
}
|
488
481
|
return path;
|
489
482
|
};
|
490
483
|
|
491
|
-
REST.prototype.
|
484
|
+
REST.prototype.memberPath = function(options) {
|
492
485
|
if (options == null) {
|
493
486
|
options = {};
|
494
487
|
}
|
495
|
-
return this.constructor.
|
488
|
+
return this.constructor.memberPath(this.id(), options);
|
496
489
|
};
|
497
490
|
|
498
491
|
REST.get = function(options, callback) {
|
data/build/joosy.js
CHANGED
@@ -496,11 +496,11 @@
|
|
496
496
|
},
|
497
497
|
__wrapElement: function(value) {
|
498
498
|
var _this = this;
|
499
|
-
return function(
|
500
|
-
if (!
|
499
|
+
return function(context) {
|
500
|
+
if (!context) {
|
501
501
|
return _this.$(value);
|
502
502
|
}
|
503
|
-
return _this.$(value)
|
503
|
+
return _this.$(value, context);
|
504
504
|
};
|
505
505
|
},
|
506
506
|
__delegateEvents: function() {
|
data/package.json
CHANGED
@@ -69,14 +69,16 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
|
|
69
69
|
, ''
|
70
70
|
|
71
71
|
#
|
72
|
-
# Builds
|
72
|
+
# Builds collection path
|
73
73
|
#
|
74
74
|
# @param [Hash] options See {Joosy.Resources.REST.find} for possible options
|
75
75
|
#
|
76
76
|
# @example Basic usage
|
77
|
-
# Resource.
|
77
|
+
# Resource.collectionPath() # /resources/
|
78
78
|
#
|
79
|
-
@
|
79
|
+
@collectionPath: (options={}) ->
|
80
|
+
return options.url if options.url
|
81
|
+
|
80
82
|
if @__source? && !options.parent?
|
81
83
|
path = @__source
|
82
84
|
else
|
@@ -87,15 +89,17 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
|
|
87
89
|
if options.parent?
|
88
90
|
path = @__parentsPath(if Object.isArray(options.parent) then options.parent else [options.parent]) + path
|
89
91
|
|
92
|
+
path += "/#{options.from}" if options.from?
|
93
|
+
|
90
94
|
path
|
91
95
|
|
92
96
|
#
|
93
|
-
# Builds
|
97
|
+
# Builds collection path
|
94
98
|
#
|
95
|
-
# @see Joosy.Resources.REST.
|
99
|
+
# @see Joosy.Resources.REST.collectionPath
|
96
100
|
#
|
97
|
-
|
98
|
-
@constructor.
|
101
|
+
collectionPath: (options={}) ->
|
102
|
+
@constructor.collectionPath options
|
99
103
|
|
100
104
|
#
|
101
105
|
# Builds member path based on the given id.
|
@@ -107,8 +111,11 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
|
|
107
111
|
# Resource.memberPath(1, from: 'foo') # /resources/1/foo
|
108
112
|
#
|
109
113
|
@memberPath: (id, options={}) ->
|
110
|
-
|
111
|
-
|
114
|
+
return options.url if options.url
|
115
|
+
|
116
|
+
from = options.from
|
117
|
+
path = @collectionPath(Object.merge(options, from: undefined)) + "/#{id}"
|
118
|
+
path += "/#{from}" if from?
|
112
119
|
path
|
113
120
|
|
114
121
|
#
|
@@ -122,27 +129,6 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
|
|
122
129
|
memberPath: (options={}) ->
|
123
130
|
@constructor.memberPath @id(), options
|
124
131
|
|
125
|
-
#
|
126
|
-
# Builds collection path
|
127
|
-
#
|
128
|
-
# @param [Hash] options See {Joosy.Resources.REST.find} for possible options
|
129
|
-
#
|
130
|
-
# @example Basic usage
|
131
|
-
# Resource.collectionPath() # /resources/
|
132
|
-
#
|
133
|
-
@collectionPath: (options={}) ->
|
134
|
-
path = @basePath(options)
|
135
|
-
path += "/#{options.from}" if options.from?
|
136
|
-
path
|
137
|
-
|
138
|
-
#
|
139
|
-
# Builds collection path
|
140
|
-
#
|
141
|
-
# @see Joosy.Resources.REST.collectionPath
|
142
|
-
#
|
143
|
-
collectionPath: (options={}) ->
|
144
|
-
@constructor.collectionPath options
|
145
|
-
|
146
132
|
#
|
147
133
|
# Sends the GET query using collectionPath.
|
148
134
|
# Callback will get parsed JSON object as a parameter.
|
@@ -179,7 +179,7 @@ class Joosy.Form extends Joosy.Module
|
|
179
179
|
data.__joosy_form_filler_lock = true
|
180
180
|
Object.each data, (property, val) =>
|
181
181
|
key = @concatFieldName scope, property
|
182
|
-
input = @$fields("[name='#{key}']:not(:file),[name='#{key.underscore()}']:not(:file),[name='#{key.camelize(false)}']:not(:file)")
|
182
|
+
input = @$fields().filter("[name='#{key}']:not(:file),[name='#{key.underscore()}']:not(:file),[name='#{key.camelize(false)}']:not(:file)")
|
183
183
|
if input.length > 0
|
184
184
|
if input.is ':checkbox'
|
185
185
|
if val
|
@@ -292,7 +292,7 @@ class Joosy.Form extends Joosy.Module
|
|
292
292
|
# @param [String] field Name of field to find
|
293
293
|
#
|
294
294
|
findField: (field) ->
|
295
|
-
@$fields("[name='#{field}']")
|
295
|
+
@$fields().filter("[name='#{field}']")
|
296
296
|
|
297
297
|
#
|
298
298
|
# Simulates REST methods by adding hidden _method input with real method
|
data/source/joosy/module.coffee
CHANGED
@@ -16,10 +16,6 @@ class Joosy.Module
|
|
16
16
|
# Remember: minifcation will rename your classes. Therefore it
|
17
17
|
# is only intended for development debugging purposes.
|
18
18
|
#
|
19
|
-
# @note Go @jashkenas Go! Give us https://github.com/jashkenas/coffee-script/issues/2052.
|
20
|
-
# Please go vote for this feature if you are reading this. It will
|
21
|
-
# give us ability to eleminate a lot of boilerplate for you.
|
22
|
-
#
|
23
19
|
# @return [String]
|
24
20
|
#
|
25
21
|
@__className: (klass) ->
|
@@ -90,9 +90,9 @@ Joosy.Modules.DOM =
|
|
90
90
|
# @private
|
91
91
|
#
|
92
92
|
__wrapElement: (value) ->
|
93
|
-
(
|
94
|
-
return @$(value) unless
|
95
|
-
return @$(value)
|
93
|
+
(context) =>
|
94
|
+
return @$(value) unless context
|
95
|
+
return @$(value, context)
|
96
96
|
|
97
97
|
#
|
98
98
|
# Binds events defined in 'events' to container
|
@@ -56,23 +56,26 @@ describe "Joosy.Resources.REST", ->
|
|
56
56
|
clone = @Test.at 'rumbas', 'salsas', Fluffy.build(1)
|
57
57
|
expect(clone.__source).toEqual '/rumbas/salsas/fluffies/1/tests'
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
describe '@memberPath', ->
|
60
|
+
beforeEach ->
|
61
|
+
@parent = FluffyParent.build 1
|
62
|
+
@grandParent = FluffyParent.build 666
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
expect(Animal.Cat.basePath parent: [grandParent, parent]).toEqual '/fluffy_parents/666/fluffy_parents/1/animal/cats'
|
64
|
+
it 'builds member path', ->
|
65
|
+
expect(Fluffy.memberPath 1).toEqual '/fluffies/1'
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
it 'builds member path with single parent', ->
|
68
|
+
expect(Fluffy.memberPath 1, parent: @parent).toEqual '/fluffy_parents/1/fluffies/1'
|
69
|
+
|
70
|
+
it 'builds member path with array parent', ->
|
71
|
+
expect(Fluffy.memberPath 1, parent: [@grandParent, @parent]).toEqual '/fluffy_parents/666/fluffy_parents/1/fluffies/1'
|
72
|
+
|
73
|
+
it 'builds member path with parent and from', ->
|
74
|
+
expect(Fluffy.memberPath 1, parent: @parent, from: 'test').toEqual '/fluffy_parents/1/fluffies/1/test'
|
75
|
+
|
76
|
+
it 'builds member path with parent, from and params', ->
|
77
|
+
expect(Fluffy.memberPath 1, parent: @parent, from: 'test', params: {foo: 'bar'}).toEqual '/fluffy_parents/1/fluffies/1/test'
|
70
78
|
|
71
|
-
expect(Fluffy.memberPath 1).toEqual '/fluffies/1'
|
72
|
-
expect(Fluffy.memberPath 1, parent: parent).toEqual '/fluffy_parents/1/fluffies/1'
|
73
|
-
expect(Fluffy.memberPath 1, parent: [grandParent, parent]).toEqual '/fluffy_parents/666/fluffy_parents/1/fluffies/1'
|
74
|
-
expect(Fluffy.memberPath 1, parent: parent, from: 'test').toEqual '/fluffy_parents/1/fluffies/1/test'
|
75
|
-
expect(Fluffy.memberPath 1, parent: parent, from: 'test', params: {foo: 'bar'}).toEqual '/fluffy_parents/1/fluffies/1/test'
|
76
79
|
|
77
80
|
it "builds collection path", ->
|
78
81
|
parent = FluffyParent.build 1
|
@@ -84,71 +87,81 @@ describe "Joosy.Resources.REST", ->
|
|
84
87
|
expect(Fluffy.collectionPath parent: parent, from: 'test').toEqual '/fluffy_parents/1/fluffies/test'
|
85
88
|
expect(Fluffy.collectionPath parent: parent, from: 'test', params: {foo: 'bar'}).toEqual '/fluffy_parents/1/fluffies/test'
|
86
89
|
|
87
|
-
describe
|
90
|
+
describe '@find(:id)', ->
|
88
91
|
rawData = '{"fluffy": {"id": 1, "name": "test1"}}'
|
89
92
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
93
|
+
beforeEach ->
|
94
|
+
@callback = sinon.spy (target, data) ->
|
95
|
+
expect(target instanceof Fluffy).toEqual true
|
96
|
+
expect(target.id()).toEqual 1
|
97
|
+
expect(target 'name').toEqual 'test1'
|
98
|
+
expect(data).toEqual $.parseJSON(rawData)
|
99
|
+
|
100
|
+
it "gets item without params", ->
|
101
|
+
resource = Fluffy.find 1, @callback
|
98
102
|
checkAndRespond @server.requests[0], 'GET', /^\/fluffies\/1\?_=\d+/, rawData
|
99
|
-
expect(callback.callCount).toEqual 1
|
103
|
+
expect(@callback.callCount).toEqual 1
|
100
104
|
|
101
|
-
it "with from", ->
|
102
|
-
resource = Fluffy.find 1, {from: 'action'}, callback
|
105
|
+
it "gets item with from", ->
|
106
|
+
resource = Fluffy.find 1, {from: 'action'}, @callback
|
103
107
|
checkAndRespond @server.requests[0], 'GET', /^\/fluffies\/1\/action\?_=\d+/, rawData
|
104
|
-
expect(callback.callCount).toEqual
|
108
|
+
expect(@callback.callCount).toEqual 1
|
105
109
|
|
106
|
-
it "with from and parent", ->
|
107
|
-
resource = Fluffy.find 1, {parent: FluffyParent.build(1), from: 'action'}, callback
|
110
|
+
it "gets item with from and parent", ->
|
111
|
+
resource = Fluffy.find 1, {parent: FluffyParent.build(1), from: 'action'}, @callback
|
108
112
|
checkAndRespond @server.requests[0], 'GET', /^\/fluffy_parents\/1\/fluffies\/1\/action\?_=\d+/, rawData
|
109
|
-
expect(callback.callCount).toEqual
|
113
|
+
expect(@callback.callCount).toEqual 1
|
110
114
|
|
111
|
-
it "with params", ->
|
112
|
-
resource = Fluffy.find 1, params: {foo: 'bar'}, callback
|
115
|
+
it "gets item with params", ->
|
116
|
+
resource = Fluffy.find 1, params: {foo: 'bar'}, @callback
|
113
117
|
checkAndRespond @server.requests[0], 'GET', /^\/fluffies\/1\?foo=bar&_=\d+/, rawData
|
114
|
-
expect(callback.callCount).toEqual
|
118
|
+
expect(@callback.callCount).toEqual 1
|
115
119
|
|
116
|
-
it "with
|
117
|
-
resource = Fluffy.find 1,
|
118
|
-
|
119
|
-
|
120
|
-
expect(resource 'name').toEqual 'test1'
|
120
|
+
it "gets item with url", ->
|
121
|
+
resource = Fluffy.find 1, url: '/some/custom/url', @callback
|
122
|
+
checkAndRespond @server.requests[0], 'GET', /^\/some\/custom\/url\?_=\d+/, rawData
|
123
|
+
expect(@callback.callCount).toEqual 1
|
121
124
|
|
125
|
+
it "gets item with direct assignation", ->
|
126
|
+
resource = Fluffy.find 1, (cbResource) ->
|
127
|
+
expect(resource).toBe cbResource
|
122
128
|
checkAndRespond @server.requests[0], 'GET', /^\/fluffies\/1\?_=\d+/, rawData
|
123
129
|
|
124
|
-
describe
|
130
|
+
describe '@find(\'all\')', ->
|
125
131
|
rawData = '{"page": 42, "fluffies": [{"id": 1, "name": "test1"}, {"id": 2, "name": "test2"}]}'
|
126
132
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
133
|
+
beforeEach ->
|
134
|
+
@callback = sinon.spy (target, data) ->
|
135
|
+
expect(target instanceof Joosy.Resources.RESTCollection).toEqual true
|
136
|
+
expect(target.size()).toEqual 2
|
137
|
+
expect(target.at(0) instanceof Fluffy).toEqual true
|
138
|
+
expect(data).toEqual $.parseJSON(rawData)
|
139
|
+
|
140
|
+
it "gets collection without params", ->
|
141
|
+
resource = Fluffy.find 'all', @callback
|
135
142
|
checkAndRespond @server.requests[0], 'GET', /^\/fluffies\?_=\d+/, rawData
|
136
|
-
expect(callback.callCount).toEqual 1
|
143
|
+
expect(@callback.callCount).toEqual 1
|
137
144
|
|
138
|
-
it "with from", ->
|
139
|
-
resource = Fluffy.find 'all', {from: 'action'}, callback
|
145
|
+
it "gets collection with from", ->
|
146
|
+
resource = Fluffy.find 'all', {from: 'action'}, @callback
|
140
147
|
checkAndRespond @server.requests[0], 'GET', /^\/fluffies\/action\?_=\d+/, rawData
|
141
|
-
expect(callback.callCount).toEqual
|
148
|
+
expect(@callback.callCount).toEqual 1
|
142
149
|
|
143
|
-
it "with from and parent", ->
|
144
|
-
resource = Fluffy.find 'all', {parent: FluffyParent.build(1), from: 'action'}, callback
|
150
|
+
it "gets collection with from and parent", ->
|
151
|
+
resource = Fluffy.find 'all', {parent: FluffyParent.build(1), from: 'action'}, @callback
|
145
152
|
checkAndRespond @server.requests[0], 'GET', /^\/fluffy_parents\/1\/fluffies\/action\?_=\d+/, rawData
|
146
|
-
expect(callback.callCount).toEqual
|
153
|
+
expect(@callback.callCount).toEqual 1
|
147
154
|
|
148
|
-
it "with params", ->
|
149
|
-
resource = Fluffy.find 'all', params: {foo: 'bar'}, callback
|
155
|
+
it "gets collection with params", ->
|
156
|
+
resource = Fluffy.find 'all', params: {foo: 'bar'}, @callback
|
150
157
|
checkAndRespond @server.requests[0], 'GET', /^\/fluffies\?foo=bar&_=\d+/, rawData
|
151
|
-
expect(callback.callCount).toEqual
|
158
|
+
expect(@callback.callCount).toEqual 1
|
159
|
+
|
160
|
+
it 'gets collection with url', ->
|
161
|
+
resource = Fluffy.find 'all', url: '/some/custom/url', @callback
|
162
|
+
checkAndRespond @server.requests[0], 'GET', /^\/some\/custom\/url\?_=\d+/, rawData
|
163
|
+
expect(@callback.callCount).toEqual 1
|
164
|
+
|
152
165
|
|
153
166
|
it "reloads resource", ->
|
154
167
|
rawData = '{"fluffy": {"id": 1, "name": "test1"}}'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joosy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0.alpha.
|
4
|
+
version: 1.2.0.alpha.56
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boris Staal
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-08-
|
13
|
+
date: 2013-08-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sprockets
|