joosy 1.2.0.alpha.14 → 1.2.0.alpha.15

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/Gruntfile.coffee +42 -18
  4. data/README.md +16 -12
  5. data/bower.json +1 -1
  6. data/lib/extensions/form.js +592 -0
  7. data/lib/extensions/preloaders.js +193 -0
  8. data/lib/extensions/resources.js +667 -0
  9. data/lib/joosy.js +1141 -2680
  10. data/lib/joosy.rb +0 -5
  11. data/package.json +1 -1
  12. data/spec/helpers/helper.coffee +1 -1
  13. data/spec/joosy/core/joosy_spec.coffee +1 -28
  14. data/spec/joosy/core/modules/renderer_spec.coffee +0 -95
  15. data/spec/joosy/{core → extensions/form}/form_spec.coffee +2 -2
  16. data/spec/joosy/{core → extensions/form}/helpers/forms_spec.coffee +1 -1
  17. data/spec/joosy/{preloaders → extensions/preloaders}/caching_spec.coffee +0 -0
  18. data/spec/joosy/{preloaders → extensions/preloaders}/inline_spec.coffee +0 -0
  19. data/spec/joosy/{core/resource/generic_spec.coffee → extensions/resources/base_spec.coffee} +19 -20
  20. data/spec/joosy/{core/resource → extensions/resources}/collection_spec.coffee +4 -4
  21. data/spec/joosy/{core/resource → extensions/resources}/rest_collection_spec.coffee +4 -4
  22. data/spec/joosy/{core/resource → extensions/resources}/rest_spec.coffee +6 -7
  23. data/src/joosy.coffee +1 -2
  24. data/src/joosy/core/helpers/view.coffee +0 -8
  25. data/src/joosy/core/joosy.coffee +5 -44
  26. data/src/joosy/core/modules/renderer.coffee +10 -29
  27. data/src/joosy/core/{resource → resources}/watcher.coffee +2 -1
  28. data/src/joosy/{core → extensions/form}/form.coffee +3 -9
  29. data/src/joosy/{core → extensions/form}/helpers/form.coffee +2 -2
  30. data/src/joosy/extensions/form/index.coffee +1 -0
  31. data/src/joosy/{preloaders → extensions/preloaders}/caching.coffee +0 -0
  32. data/src/joosy/extensions/preloaders/index.coffee +1 -0
  33. data/src/joosy/{preloaders → extensions/preloaders}/inline.coffee +0 -0
  34. data/src/joosy/{core/resource/generic.coffee → extensions/resources/base.coffee} +21 -21
  35. data/src/joosy/{core/resource → extensions/resources}/collection.coffee +11 -11
  36. data/src/joosy/extensions/resources/index.coffee +1 -0
  37. data/src/joosy/{core/resource → extensions/resources}/rest.coffee +15 -12
  38. data/src/joosy/{core/resource → extensions/resources}/rest_collection.coffee +4 -2
  39. data/src/joosy/generators/base.coffee +1 -1
  40. metadata +25 -20
  41. data/src/joosy/core/preloader.coffee +0 -13
@@ -89,9 +89,6 @@ Joosy.Modules.Renderer =
89
89
  # be passed as a context, not as a argument
90
90
  assignContext = false
91
91
 
92
- isResource = Joosy.Module.hasAncestor locals.constructor, Joosy.Resource.Generic
93
- isCollection = Joosy.Module.hasAncestor locals.constructor, Joosy.Resource.Collection
94
-
95
92
  if Object.isString template
96
93
  if @__renderSection?
97
94
  template = Joosy.Application.templater.resolveTemplate @__renderSection(), template, this
@@ -102,8 +99,8 @@ Joosy.Modules.Renderer =
102
99
  else if !Object.isFunction template
103
100
  throw new Error "#{Joosy.Module.__className @}> template (maybe @view) does not look like a string or lambda"
104
101
 
105
- if !Object.isObject(locals) && Object.extended().constructor != locals.constructor && !isResource && !isCollection
106
- throw new Error "#{Joosy.Module.__className @}> locals (maybe @data?) not in: dumb hash, Resource, Collection"
102
+ if !Object.isObject(locals) && Object.extended().constructor != locals.constructor
103
+ throw new Error "#{Joosy.Module.__className @}> locals (maybe @data?) is not a hash"
107
104
 
108
105
  renderers =
109
106
  render: (template, locals={}) =>
@@ -116,11 +113,7 @@ Joosy.Modules.Renderer =
116
113
  context = =>
117
114
  data = {}
118
115
 
119
- if isResource
120
- Joosy.Module.merge data, stack.locals.data
121
- else
122
- Joosy.Module.merge data, stack.locals
123
-
116
+ Joosy.Module.merge data, stack.locals
124
117
  Joosy.Module.merge data, @__instantiateHelpers(), false
125
118
  Joosy.Module.merge data, renderers
126
119
  data
@@ -150,25 +143,13 @@ Joosy.Modules.Renderer =
150
143
 
151
144
  morph.__bindings = []
152
145
 
153
- if isCollection
154
- for resource in locals.data
155
- binding = [resource, update]
156
- resource.bind 'changed', update
157
- stack.metamorphBindings.push binding
158
- morph.__bindings.push binding
159
- if isResource || isCollection
160
- binding = [locals, update]
161
- locals.bind 'changed', update
162
- stack.metamorphBindings.push binding
163
- morph.__bindings.push binding
164
- else
165
- for key, object of locals
166
- if locals.hasOwnProperty key
167
- if object?.bind? && object?.unbind?
168
- binding = [object, update]
169
- object.bind 'changed', update
170
- stack.metamorphBindings.push binding
171
- morph.__bindings.push binding
146
+ for key, object of locals
147
+ if locals.hasOwnProperty key
148
+ if object?.bind? && object?.unbind?
149
+ binding = [object, update]
150
+ object.bind 'changed', update
151
+ stack.metamorphBindings.push binding
152
+ morph.__bindings.push binding
172
153
 
173
154
  morph.outerHTML()
174
155
  else
@@ -1,4 +1,5 @@
1
- class Joosy.Resource.Watcher extends Joosy.Module
1
+ #### !!!UNSPECED ####
2
+ class Joosy.Resources.Watcher extends Joosy.Module
2
3
  @include Joosy.Modules.Events
3
4
 
4
5
  @cache: (cacheKey) -> @::__cacheKey = cacheKey
@@ -1,9 +1,3 @@
1
- #= require joosy/core/joosy
2
- #= require joosy/core/modules/module
3
- #= require joosy/core/modules/log
4
- #= require joosy/core/modules/events
5
- #= require joosy/core/modules/container
6
-
7
1
  #
8
2
  # AJAXifies form including file uploads and stuff. Built on top of jQuery.Form.
9
3
  #
@@ -94,7 +88,7 @@ class Joosy.Form extends Joosy.Module
94
88
  # by returning false from your own error callback. Both of callbacks will run if
95
89
  # you return true.
96
90
  #
97
- # @option options [Joosy.Resource.Generic] resource The resource to fill the form with
91
+ # @option options [Joosy.Resources.Base] resource The resource to fill the form with
98
92
  # @option options [String] resourceName The string to use as a resource name prefix for fields to match invalidation
99
93
  # @option options [String] action Action URL for the form
100
94
  # @option options [String] method HTTP method, for example PUT, that will passed in _method param
@@ -196,10 +190,10 @@ class Joosy.Form extends Joosy.Module
196
190
  input.filter("[value='#{val}']").attr 'checked', 'checked'
197
191
  else
198
192
  input.val val
199
- if val instanceof Joosy.Resource.RESTCollection
193
+ if val instanceof Joosy.Resources.RESTCollection
200
194
  for entity, i in val.data
201
195
  filler entity.data, @concatFieldName(scope, "[#{property}_attributes][#{i}]")
202
- else if val instanceof Joosy.Resource.REST
196
+ else if val instanceof Joosy.Resources.REST
203
197
  filler val.data, @concatFieldName(scope, "[#{property}_attributes][0]")
204
198
  else if Object.isObject(val) || Object.isArray(val)
205
199
  filler val, key
@@ -1,4 +1,4 @@
1
- #= require joosy/core/joosy
1
+ #= require ../form
2
2
 
3
3
  #
4
4
  # Form helper
@@ -6,7 +6,7 @@
6
6
  Joosy.helpers 'Application', ->
7
7
 
8
8
  description = (resource, method, extendIds, idSuffix) ->
9
- if Joosy.Module.hasAncestor resource.constructor, Joosy.Resource.Generic
9
+ if Joosy.Module.hasAncestor resource.constructor, Joosy.Resources.Base
10
10
  id = resource.id()
11
11
  resource = resource.__entityName
12
12
 
@@ -0,0 +1 @@
1
+ #= require_tree ./
@@ -0,0 +1 @@
1
+ #= require_tree ./
@@ -2,7 +2,7 @@
2
2
  # Basic data wrapper with triggering and entity name binding
3
3
  #
4
4
  # @example Basic usage
5
- # class R extends Joosy.Resource.Generic
5
+ # class R extends Joosy.Resources.Base
6
6
  # @entity 'r'
7
7
  #
8
8
  # @beforeLoad (data) ->
@@ -18,7 +18,7 @@
18
18
  # @include Joosy.Modules.Log
19
19
  # @include Joosy.Modules.Events
20
20
  #
21
- class Joosy.Resource.Generic extends Joosy.Module
21
+ class Joosy.Resources.Base extends Joosy.Module
22
22
  @include Joosy.Modules.Log
23
23
  @include Joosy.Modules.Events
24
24
 
@@ -34,7 +34,7 @@ class Joosy.Resource.Generic extends Joosy.Module
34
34
  # ensure correct garbage collection.
35
35
  #
36
36
  @resetIdentity: ->
37
- Joosy.Resource.Generic.identity = {}
37
+ Joosy.Resources.Base.identity = {}
38
38
 
39
39
  #
40
40
  # Allows to modify data before it gets stored.
@@ -71,7 +71,7 @@ class Joosy.Resource.Generic extends Joosy.Module
71
71
  #
72
72
  class Clone extends this
73
73
 
74
- if entity instanceof Joosy.Resource.Generic
74
+ if entity instanceof Joosy.Resources.Base
75
75
  Clone.__source = entity.memberPath()
76
76
  Clone.__source += '/' + @::__entityName.pluralize() if @::__entityName
77
77
  else
@@ -91,18 +91,18 @@ class Joosy.Resource.Generic extends Joosy.Module
91
91
  # Sets the collection to use
92
92
  #
93
93
  # @note By default will try to seek for `EntityNamesCollection`.
94
- # Will fallback to {Joosy.Resource.Collection}
94
+ # Will fallback to {Joosy.Resources.Collection}
95
95
  #
96
96
  # @param [Class] klass Class to assign as collection
97
97
  #
98
98
  @collection: (klass) -> @::__collection = -> klass
99
99
 
100
100
  #
101
- # Implements {Joosy.Resource.Generic.collection} default behavior.
101
+ # Implements {Joosy.Resources.Base.collection} default behavior.
102
102
  #
103
103
  __collection: ->
104
104
  named = @__entityName.camelize().pluralize() + 'Collection'
105
- if window[named] then window[named] else Joosy.Resource.Collection
105
+ if window[named] then window[named] else Joosy.Resources.Collection
106
106
 
107
107
  #
108
108
  # Dynamically creates collection of inline resources.
@@ -111,9 +111,9 @@ class Joosy.Resource.Generic extends Joosy.Module
111
111
  # to handle inline changes with triggers and all that resources stuff
112
112
  #
113
113
  # @example Basic usage
114
- # class Zombie extends Joosy.Resource.Generic
114
+ # class Zombie extends Joosy.Resources.Base
115
115
  # @entity 'zombie'
116
- # class Puppy extends Joosy.Resource.Generic
116
+ # class Puppy extends Joosy.Resources.Base
117
117
  # @entity 'puppy'
118
118
  # @map 'zombies'
119
119
  #
@@ -134,7 +134,7 @@ class Joosy.Resource.Generic extends Joosy.Module
134
134
  throw new Error "#{Joosy.Module.__className @}> class can not be detected for '#{name}' mapping"
135
135
 
136
136
  @beforeLoad (data) ->
137
- klass = klass() unless Joosy.Module.hasAncestor(klass, Joosy.Resource.Generic)
137
+ klass = klass() unless Joosy.Module.hasAncestor(klass, Joosy.Resources.Base)
138
138
 
139
139
  @__map(data, name, klass)
140
140
 
@@ -142,13 +142,13 @@ class Joosy.Resource.Generic extends Joosy.Module
142
142
  # Wraps instance of resource inside shim-function allowing to track
143
143
  # data changes. See class example
144
144
  #
145
- # @return [Joosy.Resource.Generic]
145
+ # @return [Joosy.Resources.Base]
146
146
  #
147
147
  @build: (data={}) ->
148
148
  klass = @::__entityName
149
149
 
150
- Joosy.Resource.Generic.identity ||= {}
151
- Joosy.Resource.Generic.identity[klass] ||= {}
150
+ Joosy.Resources.Base.identity ||= {}
151
+ Joosy.Resources.Base.identity[klass] ||= {}
152
152
 
153
153
  shim = ->
154
154
  shim.__call.apply shim, arguments
@@ -169,11 +169,11 @@ class Joosy.Resource.Generic extends Joosy.Module
169
169
  if Joosy.Application.identity
170
170
  id = data[shim.__primaryKey]
171
171
 
172
- if id? && Joosy.Resource.Generic.identity[klass][id]
173
- shim = Joosy.Resource.Generic.identity[klass][id]
172
+ if id? && Joosy.Resources.Base.identity[klass][id]
173
+ shim = Joosy.Resources.Base.identity[klass][id]
174
174
  shim.load data
175
175
  else
176
- Joosy.Resource.Generic.identity[klass][id] = shim
176
+ Joosy.Resources.Base.identity[klass][id] = shim
177
177
  @apply shim, [data]
178
178
  else
179
179
  @apply shim, [data]
@@ -200,7 +200,7 @@ class Joosy.Resource.Generic extends Joosy.Module
200
200
  #
201
201
  # @param [Object] data Data to store
202
202
  #
203
- # @return [Joosy.Resource.Generic] Returns self
203
+ # @return [Joosy.Resources.Base] Returns self
204
204
  #
205
205
  load: (data) ->
206
206
  @__fillData data
@@ -215,7 +215,7 @@ class Joosy.Resource.Generic extends Joosy.Module
215
215
  __get: (path) ->
216
216
  target = @__callTarget path
217
217
 
218
- if target[0] instanceof Joosy.Resource.Generic
218
+ if target[0] instanceof Joosy.Resources.Base
219
219
  return target[0](target[1])
220
220
  else
221
221
  return target[0][target[1]]
@@ -229,7 +229,7 @@ class Joosy.Resource.Generic extends Joosy.Module
229
229
  __set: (path, value) ->
230
230
  target = @__callTarget path
231
231
 
232
- if target[0] instanceof Joosy.Resource.Generic
232
+ if target[0] instanceof Joosy.Resources.Base
233
233
  target[0](target[1], value)
234
234
  else
235
235
  target[0][target[1]] = value
@@ -251,7 +251,7 @@ class Joosy.Resource.Generic extends Joosy.Module
251
251
 
252
252
  for part in path
253
253
  target[part] ||= {}
254
- if target instanceof Joosy.Resource.Generic
254
+ if target instanceof Joosy.Resources.Base
255
255
  target = target(part)
256
256
  else
257
257
  target = target[part]
@@ -261,7 +261,7 @@ class Joosy.Resource.Generic extends Joosy.Module
261
261
  [@data, path]
262
262
 
263
263
  #
264
- # Wrapper for {Joosy.Resource.Generic.build} magic
264
+ # Wrapper for {Joosy.Resources.Base.build} magic
265
265
  #
266
266
  __call: (path, value) ->
267
267
  if arguments.length > 1
@@ -3,14 +3,14 @@
3
3
  # Turns JSON array into array of Resources and manages them.
4
4
  #
5
5
  # @note You should not use Collection directly. It will be
6
- # automatically created by things like {Joosy.Resource.Generic.map}
7
- # or {Joosy.Resource.REST.find}.
6
+ # automatically created by things like {Joosy.Resources.Base.map}
7
+ # or {Joosy.Resources.REST.find}.
8
8
  #
9
9
  # @example Basic sample
10
- # class R extends Joosy.Resource.Generic
10
+ # class R extends Joosy.Resources.Base
11
11
  # @entity 'r'
12
12
  #
13
- # collection = new Joosy.Resource.Collection(R)
13
+ # collection = new Joosy.Resources.Collection(R)
14
14
  #
15
15
  # collection.load [{foo: 'bar'}, {foo: 'baz'}]
16
16
  # collection.each (resource) ->
@@ -18,7 +18,7 @@
18
18
  #
19
19
  # @include Joosy.Modules.Events
20
20
  #
21
- class Joosy.Resource.Collection extends Joosy.Module
21
+ class Joosy.Resources.Collection extends Joosy.Module
22
22
  @include Joosy.Modules.Events
23
23
 
24
24
  #
@@ -63,7 +63,7 @@ class Joosy.Resource.Collection extends Joosy.Module
63
63
  # If hash was given will seek for moodel name camelized and pluralized.
64
64
  # @param [Boolean] notify Indicates whether to trigger 'changed' event
65
65
  #
66
- # @return [Joosy.Resource.Collection] Returns self.
66
+ # @return [Joosy.Resources.Collection] Returns self.
67
67
  #
68
68
  load: (entities, notify=true) ->
69
69
  if @__beforeLoad?
@@ -110,7 +110,7 @@ class Joosy.Resource.Collection extends Joosy.Module
110
110
  #
111
111
  # @param [Function] description Callback matcher
112
112
  #
113
- # @return [Joosy.Resource.Generic]
113
+ # @return [Joosy.Resources.Base]
114
114
  #
115
115
  find: (description) ->
116
116
  @data.find description
@@ -123,7 +123,7 @@ class Joosy.Resource.Collection extends Joosy.Module
123
123
  #
124
124
  # @param [Integer] id Id to find
125
125
  #
126
- # @return [Joosy.Resource.Generic]
126
+ # @return [Joosy.Resources.Base]
127
127
  #
128
128
  findById: (id) ->
129
129
  @data.find (x) -> x.id().toString() == id.toString()
@@ -133,7 +133,7 @@ class Joosy.Resource.Collection extends Joosy.Module
133
133
  #
134
134
  # @param [Integer] i Index
135
135
  #
136
- # @return [Joosy.Resource.Generic]
136
+ # @return [Joosy.Resources.Base]
137
137
  #
138
138
  at: (i) ->
139
139
  @data[i]
@@ -145,7 +145,7 @@ class Joosy.Resource.Collection extends Joosy.Module
145
145
  # @param [Resource] target Resource by itself
146
146
  # @param [Boolean] notify Indicates whether to trigger 'changed' event
147
147
  #
148
- # @return [Joosy.Resource.Generic] Removed element
148
+ # @return [Joosy.Resources.Base] Removed element
149
149
  #
150
150
  remove: (target, notify=true) ->
151
151
  if Object.isNumber target
@@ -165,7 +165,7 @@ class Joosy.Resource.Collection extends Joosy.Module
165
165
  # @param [Integer] index Index to add to. If omited will be pushed to the end
166
166
  # @param [Boolean] notify Indicates whether to trigger 'changed' event
167
167
  #
168
- # @return [Joosy.Resource.Generic] Added element
168
+ # @return [Joosy.Resources.Base] Added element
169
169
  #
170
170
  add: (element, index=false, notify=true) ->
171
171
  if typeof index is 'number'
@@ -0,0 +1 @@
1
+ #= require_tree ./
@@ -1,15 +1,18 @@
1
+ #= require ./base
2
+ #= require ./collection
3
+
1
4
  #
2
5
  # Resource with REST/JSON backend
3
6
  #
4
- class Joosy.Resource.REST extends Joosy.Resource.Generic
7
+ class Joosy.Resources.REST extends Joosy.Resources.Base
5
8
 
6
9
  #
7
10
  # Implements `@collection` default behavior.
8
- # Changes the default fallback to Joosy.Resource.RESTCollection.
11
+ # Changes the default fallback to Joosy.Resources.RESTCollection.
9
12
  #
10
13
  __collection: ->
11
14
  named = @__entityName.camelize().pluralize() + 'Collection'
12
- if window[named] then window[named] else Joosy.Resource.RESTCollection
15
+ if window[named] then window[named] else Joosy.Resources.RESTCollection
13
16
 
14
17
  #
15
18
  # Builds parents part of member path based on parents array
@@ -21,7 +24,7 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
21
24
  #
22
25
  @__parentsPath: (parents) ->
23
26
  parents.reduce (path, parent) ->
24
- path += if Joosy.Module.hasAncestor parent.constructor, Joosy.Resource.REST
27
+ path += if Joosy.Module.hasAncestor parent.constructor, Joosy.Resources.REST
25
28
  parent.memberPath()
26
29
  else
27
30
  parent
@@ -30,7 +33,7 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
30
33
  #
31
34
  # Builds base path
32
35
  #
33
- # @param [Hash] options See {Joosy.Resource.REST.find} for possible options
36
+ # @param [Hash] options See {Joosy.Resources.REST.find} for possible options
34
37
  #
35
38
  # @example Basic usage
36
39
  # Resource.basePath() # /resources
@@ -51,7 +54,7 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
51
54
  #
52
55
  # Builds base path
53
56
  #
54
- # @see Joosy.Resource.REST.basePath
57
+ # @see Joosy.Resources.REST.basePath
55
58
  #
56
59
  basePath: (options={}) ->
57
60
  @constructor.basePath options
@@ -60,7 +63,7 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
60
63
  # Builds member path based on the given id.
61
64
  #
62
65
  # @param [String] id ID of entity to build member path for
63
- # @param [Hash] options See {Joosy.Resource.REST.find} for possible options
66
+ # @param [Hash] options See {Joosy.Resources.REST.find} for possible options
64
67
  #
65
68
  # @example Basic usage
66
69
  # Resource.memberPath(1, from: 'foo') # /resources/1/foo
@@ -73,7 +76,7 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
73
76
  #
74
77
  # Builds member path
75
78
  #
76
- # @param [Hash] options See {Joosy.Resource.REST.find} for possible options
79
+ # @param [Hash] options See {Joosy.Resources.REST.find} for possible options
77
80
  #
78
81
  # @example Basic usage
79
82
  # resource.memberPath(from: 'foo') # /resources/1/foo
@@ -84,7 +87,7 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
84
87
  #
85
88
  # Builds collection path
86
89
  #
87
- # @param [Hash] options See {Joosy.Resource.REST.find} for possible options
90
+ # @param [Hash] options See {Joosy.Resources.REST.find} for possible options
88
91
  #
89
92
  # @example Basic usage
90
93
  # Resource.collectionPath() # /resources/
@@ -97,7 +100,7 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
97
100
  #
98
101
  # Builds collection path
99
102
  #
100
- # @see Joosy.Resource.REST.collectionPath
103
+ # @see Joosy.Resources.REST.collectionPath
101
104
  #
102
105
  collectionPath: (options={}) ->
103
106
  @constructor.collectionPath options
@@ -217,7 +220,7 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
217
220
  # @param [Function] callback Resulting callback
218
221
  # (will receive retrieved Collection/Resource)
219
222
  #
220
- # @option options [Joosy.Resource.REST] parent Sets the given resource as a base path
223
+ # @option options [Joosy.Resources.REST] parent Sets the given resource as a base path
221
224
  # i.e. /parents/1/resources
222
225
  # @option options [String] parent Sets the given staring as a base path
223
226
  # i.e. /trololo/resources
@@ -261,7 +264,7 @@ class Joosy.Resource.REST extends Joosy.Resource.Generic
261
264
  #
262
265
  # Refetches the data from backend and triggers `changed`
263
266
  #
264
- # @param [Hash] options See {Joosy.Resource.REST.find} for possible options
267
+ # @param [Hash] options See {Joosy.Resources.REST.find} for possible options
265
268
  # @param [Function] callback Resulting callback
266
269
  #
267
270
  reload: (options={}, callback=false) ->