joosy 1.2.0.alpha.38 → 1.2.0.alpha.41

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/Gruntfile.coffee +15 -7
  3. data/bower.json +4 -3
  4. data/lib/extensions/resources.js +11 -3
  5. data/lib/joosy.js +235 -300
  6. data/package.json +3 -3
  7. data/spec/helpers/ground.coffee +33 -0
  8. data/spec/helpers/matchers.coffee +65 -0
  9. data/spec/joosy/core/application_spec.coffee +8 -8
  10. data/spec/joosy/core/helpers/view_spec.coffee +9 -5
  11. data/spec/joosy/core/helpers/widgets_spec.coffee +43 -10
  12. data/spec/joosy/core/joosy_spec.coffee +42 -50
  13. data/spec/joosy/core/layout_spec.coffee +30 -34
  14. data/spec/joosy/core/modules/container_spec.coffee +79 -76
  15. data/spec/joosy/core/modules/events_spec.coffee +148 -81
  16. data/spec/joosy/core/modules/filters_spec.coffee +68 -49
  17. data/spec/joosy/core/modules/log_spec.coffee +13 -5
  18. data/spec/joosy/core/modules/module_spec.coffee +24 -14
  19. data/spec/joosy/core/modules/renderer_spec.coffee +95 -89
  20. data/spec/joosy/core/modules/time_manager_spec.coffee +11 -16
  21. data/spec/joosy/core/modules/widget_manager_spec.coffee +89 -71
  22. data/spec/joosy/core/page_spec.coffee +201 -137
  23. data/spec/joosy/core/templaters/jst_spec.coffee +62 -0
  24. data/spec/joosy/core/widget_spec.coffee +25 -29
  25. data/spec/joosy/extensions/form/form_spec.coffee +3 -1
  26. data/spec/joosy/extensions/resources/base_spec.coffee +3 -0
  27. data/spec/joosy/extensions/resources/collection_spec.coffee +3 -0
  28. data/spec/joosy/extensions/resources/rest_collection_spec.coffee +3 -0
  29. data/spec/joosy/extensions/resources/rest_spec.coffee +3 -0
  30. data/src/joosy/core/application.coffee +1 -7
  31. data/src/joosy/core/helpers/view.coffee +12 -0
  32. data/src/joosy/core/helpers/widgets.coffee +19 -9
  33. data/src/joosy/core/joosy.coffee +0 -23
  34. data/src/joosy/core/layout.coffee +7 -5
  35. data/src/joosy/core/module.coffee +24 -4
  36. data/src/joosy/core/modules/container.coffee +29 -28
  37. data/src/joosy/core/modules/events.coffee +85 -72
  38. data/src/joosy/core/modules/filters.coffee +3 -1
  39. data/src/joosy/core/modules/renderer.coffee +91 -74
  40. data/src/joosy/core/modules/widgets_manager.coffee +12 -9
  41. data/src/joosy/core/page.coffee +7 -14
  42. data/src/joosy/core/templaters/{rails_jst.coffee → jst.coffee} +21 -19
  43. data/src/joosy/core/widget.coffee +3 -3
  44. data/src/joosy/extensions/resources/base.coffee +8 -3
  45. data/src/joosy/extensions/resources/rest.coffee +8 -0
  46. data/src/joosy/extensions/resources/rest_collection.coffee +1 -0
  47. data/tasks/joosy.coffee +46 -17
  48. data/templates/application/base/pages/welcome/index.coffee +5 -5
  49. data/templates/application/base/templates/layouts/application.jst.hamlc +2 -2
  50. data/templates/application/base/templates/pages/welcome/index.jst.hamlc +2 -2
  51. data/templates/application/standalone/Gruntfile.coffee +3 -1
  52. metadata +6 -5
  53. data/spec/helpers/helper.coffee +0 -68
  54. data/spec/joosy/core/templaters/rails_jst_spec.coffee +0 -25
@@ -45,12 +45,11 @@ Joosy.Modules.WidgetsManager =
45
45
  # Intialize all widgets for current object
46
46
  #
47
47
  __setupWidgets: ->
48
- widgets = @__widgets
49
- registered = Object.extended()
48
+ return unless @__widgets
50
49
 
51
- return unless widgets
50
+ registered = Object.extended()
52
51
 
53
- Object.each widgets, (selector, widget) =>
52
+ Object.each @__widgets, (selector, widget) =>
54
53
  if selector == '$container'
55
54
  activeSelector = @container
56
55
  else
@@ -65,14 +64,18 @@ Joosy.Modules.WidgetsManager =
65
64
  else
66
65
  instance = widget.call this, index
67
66
 
68
- registered[selector][Joosy.Module.__className instance] ||= 0
69
- registered[selector][Joosy.Module.__className instance] += 1
67
+ if Joosy.Application.config.debug
68
+ registered[selector][Joosy.Module.__className instance] ||= 0
69
+ registered[selector][Joosy.Module.__className instance] += 1
70
70
 
71
71
  @registerWidget $(elem), instance
72
72
 
73
- registered.each (selector, value) =>
74
- value.each (widget, count) =>
75
- Joosy.Modules.Log.debugAs @, "Widget #{widget} registered at '#{selector}'. Elements: #{count}"
73
+ @__widgets = {}
74
+
75
+ if Joosy.Application.config.debug
76
+ registered.each (selector, value) =>
77
+ value.each (widget, count) =>
78
+ Joosy.Modules.Log.debugAs @, "Widget #{widget} registered at '#{selector}'. Elements: #{count}"
76
79
 
77
80
  #
78
81
  # Unregister all widgets for current object
@@ -215,7 +215,7 @@ class Joosy.Page extends Joosy.Module
215
215
  unless @halted = !@__runBeforeLoads(@params, @previous)
216
216
  Joosy.Application.loading = true
217
217
 
218
- if !@previous?.layout?.uuid? || @previous?.__layoutClass != @__layoutClass
218
+ if !@previous?.layout?.uid? || @previous?.__layoutClass != @__layoutClass
219
219
  @__bootstrapLayout()
220
220
  else
221
221
  @__bootstrap()
@@ -324,20 +324,18 @@ class Joosy.Page extends Joosy.Module
324
324
  @previous?.__afterPaint?(callbacksParams)
325
325
  @__callSyncedThrough this, '__paint', callbacksParams, =>
326
326
  # Page HTML
327
- @swapContainer @layout.content(), @__renderer(@data || {})
327
+ @swapContainer @layout.content(), @__renderDefault(@data || {})
328
328
  @container = @layout.content()
329
329
 
330
330
  # Loading
331
331
  @__load()
332
332
 
333
- @layout.content()
334
-
335
333
  @__callSyncedThrough @previous, '__erase', callbacksParams, =>
336
334
  @previous?.__unload()
337
- @__callSyncedThrough this, '__beforePaint', callbacksParams, =>
335
+ @__callSyncedThrough @, '__beforePaint', callbacksParams, =>
338
336
  @trigger 'stageClear'
339
337
 
340
- @__callSyncedThrough this, '__fetch', [], =>
338
+ @__callSyncedThrough @, '__fetch', [], =>
341
339
  Joosy.Modules.Log.debugAs @, "Fetch complete"
342
340
  @trigger 'dataReceived'
343
341
 
@@ -363,21 +361,16 @@ class Joosy.Page extends Joosy.Module
363
361
  @wait "stageClear dataReceived", =>
364
362
  @__callSyncedThrough @layout, '__paint', callbacksParams, =>
365
363
  # Layout HTML
366
- data = Joosy.Module.merge {}, @layout.data || {}
367
- data = Joosy.Module.merge data, yield: => @layout.yield()
368
-
369
- @swapContainer Joosy.Application.content(), @layout.__renderer data
364
+ @swapContainer Joosy.Application.content(), @layout.__renderDefault(@layout.data || {})
370
365
 
371
366
  # Page HTML
372
- @swapContainer @layout.content(), @__renderer(@data || {})
367
+ @swapContainer @layout.content(), @__renderDefault(@data || {})
373
368
  @container = @layout.content()
374
369
 
375
370
  # Loading
376
371
  @layout.__load Joosy.Application.content()
377
372
  @__load()
378
373
 
379
- Joosy.Application.content()
380
-
381
374
  @__callSyncedThrough @previous?.layout, '__erase', callbacksParams, =>
382
375
  @previous?.layout?.__unload?()
383
376
  @previous?.__unload()
@@ -385,6 +378,6 @@ class Joosy.Page extends Joosy.Module
385
378
  @trigger 'stageClear'
386
379
 
387
380
  @__callSyncedThrough @layout, '__fetch', [], =>
388
- @__callSyncedThrough this, '__fetch', [], =>
381
+ @__callSyncedThrough @, '__fetch', [], =>
389
382
  Joosy.Modules.Log.debugAs @, "Fetch complete"
390
383
  @trigger 'dataReceived'
@@ -1,10 +1,12 @@
1
1
  #= require joosy/core/joosy
2
2
 
3
3
  #
4
- # Rails JST template precompilation binding
4
+ # JST template precompilation binding
5
5
  #
6
- class Joosy.Templaters.RailsJST
7
- constructor: (@applicationName) ->
6
+ class Joosy.Templaters.JST
7
+ constructor: (applicationName) ->
8
+ if Object.isString(applicationName) && applicationName.length > 0
9
+ @applicationName = applicationName
8
10
 
9
11
  #
10
12
  # Gets template lambda by its full name
@@ -13,22 +15,22 @@ class Joosy.Templaters.RailsJST
13
15
  #
14
16
  buildView: (name) ->
15
17
  template = false
16
- haystack = [
17
- "#{@applicationName}/templates/#{name}-#{I18n?.locale}",
18
- "#{@applicationName}/templates/#{name}",
19
- "templates/#{name}-#{I18n?.locale}",
20
- "templates/#{name}"
21
- ]
22
-
23
- haystack.each (path) ->
24
- if JST[path]
25
- location = path
26
- template = JST[path]
27
-
28
- unless template
29
- throw new Error "Template '#{name}' not found. Checked at: #{location}"
30
-
31
- template
18
+
19
+ if @applicationName
20
+ haystack = [
21
+ "#{@applicationName}/templates/#{name}-#{I18n?.locale}",
22
+ "#{@applicationName}/templates/#{name}"
23
+ ]
24
+ else
25
+ haystack = [
26
+ "templates/#{name}-#{I18n?.locale}",
27
+ "templates/#{name}"
28
+ ]
29
+
30
+ for path in haystack
31
+ return window.JST[path] if window.JST[path]
32
+
33
+ throw new Error "Template '#{name}' not found. Checked at: '#{haystack.join(', ')}'"
32
34
 
33
35
  #
34
36
  # Gets full name of template by several params
@@ -33,7 +33,7 @@ class Joosy.Widget extends Joosy.Module
33
33
  #
34
34
  # By default widget will not render on load
35
35
  #
36
- __renderer: false
36
+ __renderDefault: false
37
37
 
38
38
  #
39
39
  # Initial data that will be passed to view on load
@@ -66,8 +66,8 @@ class Joosy.Widget extends Joosy.Module
66
66
  #
67
67
  __load: (@parent, @container, render=true) ->
68
68
  @__runBeforeLoads()
69
- if render && @__renderer
70
- @swapContainer @container, @__renderer(@data || {})
69
+ if render && @__renderDefault
70
+ @swapContainer @container, @__renderDefault(@data || {})
71
71
  @__assignElements()
72
72
  @__delegateEvents()
73
73
  @__setupWidgets()
@@ -213,9 +213,11 @@ class Joosy.Resources.Base extends Joosy.Module
213
213
  # @return [mixed]
214
214
  #
215
215
  __get: (path) ->
216
- target = @__callTarget path
216
+ target = @__callTarget path, true
217
217
 
218
- if target[0] instanceof Joosy.Resources.Base
218
+ if !target
219
+ return undefined
220
+ else if target[0] instanceof Joosy.Resources.Base
219
221
  return target[0](target[1])
220
222
  else
221
223
  return target[0][target[1]]
@@ -241,15 +243,18 @@ class Joosy.Resources.Base extends Joosy.Module
241
243
  # Locates the actual instance of attribute path `foo.bar` from get/set
242
244
  #
243
245
  # @param [String] path Path to the attribute (`foo.bar`)
246
+ # @param [Boolean] safe Indicates whether nested hashes should not be automatically created when they don't exist
244
247
  # @return [Array] Instance of object containing last step of path and keyword for required field
245
248
  #
246
- __callTarget: (path) ->
249
+ __callTarget: (path, safe=false) ->
247
250
  if path.has(/\./) && !@data[path]?
248
251
  path = path.split '.'
249
252
  keyword = path.pop()
250
253
  target = @data
251
254
 
252
255
  for part in path
256
+ return false if safe && !target[part]?
257
+
253
258
  target[part] ||= {}
254
259
  if target instanceof Joosy.Resources.Base
255
260
  target = target(part)
@@ -111,6 +111,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
111
111
  #
112
112
  # @param [Hash] options Options to proxy to collectionPath
113
113
  # @param [Function] callback Resulting callback
114
+ # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
114
115
  #
115
116
  @get: (options, callback) ->
116
117
  if Object.isFunction(options)
@@ -124,6 +125,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
124
125
  #
125
126
  # @param [Hash] options Options to proxy to collectionPath
126
127
  # @param [Function] callback Resulting callback
128
+ # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
127
129
  #
128
130
  @post: (options, callback) ->
129
131
  if Object.isFunction(options)
@@ -137,6 +139,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
137
139
  #
138
140
  # @param [Hash] options Options to proxy to collectionPath
139
141
  # @param [Function] callback Resulting callback
142
+ # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
140
143
  #
141
144
  @put: (options, callback) ->
142
145
  if Object.isFunction(options)
@@ -150,6 +153,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
150
153
  #
151
154
  # @param [Hash] options Options to proxy to collectionPath
152
155
  # @param [Function] callback Resulting callback
156
+ # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
153
157
  #
154
158
  @delete: (options, callback) ->
155
159
  if Object.isFunction(options)
@@ -163,6 +167,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
163
167
  #
164
168
  # @param [Hash] options Options to proxy to memberPath
165
169
  # @param [Function] callback Resulting callback
170
+ # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
166
171
  #
167
172
  get: (options, callback) ->
168
173
  if Object.isFunction(options)
@@ -176,6 +181,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
176
181
  #
177
182
  # @param [Hash] options Options to proxy to memberPath
178
183
  # @param [Function] callback Resulting callback
184
+ # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
179
185
  #
180
186
  post: (options, callback) ->
181
187
  if Object.isFunction(options)
@@ -189,6 +195,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
189
195
  #
190
196
  # @param [Hash] options Options to proxy to memberPath
191
197
  # @param [Function] callback Resulting callback
198
+ # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
192
199
  #
193
200
  put: (options, callback) ->
194
201
  if Object.isFunction(options)
@@ -266,6 +273,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
266
273
  #
267
274
  # @param [Hash] options See {Joosy.Resources.REST.find} for possible options
268
275
  # @param [Function] callback Resulting callback
276
+ # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
269
277
  #
270
278
  reload: (options={}, callback=false) ->
271
279
  if Object.isFunction(options)
@@ -15,6 +15,7 @@ class Joosy.Resources.RESTCollection extends Joosy.Resources.Collection
15
15
  #
16
16
  # @param [Hash] options See {Joosy.Resources.REST.find} for possible options
17
17
  # @param [Function] callback Resulting callback
18
+ # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
18
19
  #
19
20
  reload: (options={}, callback=false) ->
20
21
  if Object.isFunction(options)
data/tasks/joosy.coffee CHANGED
@@ -150,24 +150,51 @@ module.exports = (grunt) ->
150
150
 
151
151
  console.log "=> Serving static from /#{paths.public}"
152
152
 
153
- bower: -> require('bower')
153
+ bower:
154
+ install: (complete) ->
155
+ if grunt.file.exists('bower.json')
156
+ require('bower').commands.install()
157
+ .on('data', (msg) -> grunt.log.ok msg)
158
+ .on('error', (error) ->
159
+ if error.code == 'ECONFLICT'
160
+ grunt.joosy.bower.resolve complete, error
161
+ else
162
+ grunt.log.subhead "Bower has errored"
163
+ grunt.log.warn error
164
+ grunt.log.warn error.details if error.details?
165
+ )
166
+ .on('end', complete)
167
+ else
168
+ complete()
169
+
170
+ resolve: (complete, error) ->
171
+ grunt.log.subhead "Bower conflict for '#{error.name}'"
172
+
173
+ error.picks.each (p) ->
174
+ dependencies = p.dependants.map((x) -> x.endpoint.name).join(',')
175
+ grunt.log.warn "#{p.endpoint.target} (#{dependencies.yellow}: resolves to #{p.pkgMeta._release.yellow})"
176
+
177
+ resolutions = error.picks.map((x) -> x.pkgMeta._release).unique()
178
+
179
+ unless process.env['NODE_ENV'] == 'production'
180
+ grunt.log.subhead "Pick a resolution from the list:"
181
+ require('commander').choose resolutions, (i) ->
182
+ bowerConfig = JSON.parse grunt.file.read('./bower.json')
183
+ bowerConfig.resolutions ||= {}
184
+ bowerConfig.resolutions[error.name] = resolutions[i]
185
+
186
+ grunt.file.write './bower.json', JSON.stringify(bowerConfig, null, 2)
187
+
188
+ grunt.joosy.bower.install complete
189
+ else
190
+ grunt.log.subhead "Possible resolutions:"
191
+ resolutions.unique().each (r) -> grunt.log.warn r
192
+ grunt.fatal "Bower has errored"
193
+
154
194
 
155
195
  # Tasks
156
- grunt.registerTask 'joosy:postinstall', ->
157
- complete = @async()
158
- bowerized = ->
159
- if process.env['NODE_ENV'] == 'production'
160
- grunt.task.run 'compile'
161
-
162
- complete()
163
-
164
- if grunt.file.exists('bower.json')
165
- grunt.joosy.bower().commands.install()
166
- .on('data', (msg) -> grunt.log.ok msg)
167
- .on('error', (error) -> grunt.fail.fatal(error))
168
- .on('end', bowerized)
169
- else
170
- bowerized()
196
+ grunt.registerTask 'joosy:bower', ->
197
+ grunt.joosy.bower.install @async()
171
198
 
172
199
  grunt.registerTask 'joosy:server', ->
173
200
  @async()
@@ -186,6 +213,9 @@ module.exports = (grunt) ->
186
213
 
187
214
  grunt.registerTask 'joosy:compile', ['joosy:assets', 'joosy:haml']
188
215
 
216
+ grunt.registerTask 'joosy:compile:production', ->
217
+ grunt.task.run 'compile' if process.env['NODE_ENV'] == 'production'
218
+
189
219
  grunt.registerTask 'joosy:assets', (target) ->
190
220
  complete = @async()
191
221
  assets = grunt.joosy.helpers.normalizeFiles('joosy.assets', target)
@@ -219,7 +249,6 @@ module.exports = (grunt) ->
219
249
 
220
250
  grunt.log.ok "Compiled #{destination}"
221
251
 
222
-
223
252
  grunt.registerTask 'joosy:clean', ->
224
253
  trash = []
225
254
 
@@ -4,11 +4,6 @@ Joosy.namespace 'Welcome', ->
4
4
  @layout ApplicationLayout
5
5
  @view 'index'
6
6
 
7
- @afterLoad ->
8
- @startHeartbeat()
9
- @$content().css
10
- 'padding-top': "#{$(window).height() / 2 - 80}px"
11
-
12
7
  @mapElements
13
8
  content: '#content'
14
9
  joosy: '.joosy'
@@ -17,6 +12,11 @@ Joosy.namespace 'Welcome', ->
17
12
  'mouseover $joosy': -> clearInterval @heartbeat
18
13
  'mouseout $joosy': 'startHeartbeat'
19
14
 
15
+ @afterLoad ->
16
+ @startHeartbeat()
17
+ @$content().css
18
+ 'padding-top': "#{$(window).height() / 2 - 80}px"
19
+
20
20
  startHeartbeat: ->
21
21
  @heartbeat = @setInterval 1500, =>
22
22
  @$joosy().animate({opacity: 0.8}, 300).animate({opacity: 1}, 300)
@@ -1,2 +1,2 @@
1
- #page{:style => 'text-align: center'}
2
- .content{:id => @yield()}
1
+ #page{style: 'text-align: center'}
2
+ != @page 'div', class: 'content'
@@ -1,6 +1,6 @@
1
1
  #wrapper
2
2
  #content
3
3
  %h1 Welcome aboard
4
- .joosy{:style => 'background: #F71; border-radius: 10px; width: 250px; display: inline-block'}
5
- %div{:style => 'color: #FFF; padding: 10px;'}
4
+ .joosy{style: 'background: #F71; border-radius: 10px; width: 250px; display: inline-block'}
5
+ %div{style: 'color: #FFF; padding: 10px;'}
6
6
  It's Joosy time!
@@ -38,4 +38,6 @@ module.exports = (grunt) ->
38
38
  # Tasks
39
39
  #
40
40
  grunt.registerTask 'compile', ['joosy:compile', 'uglify', 'cssmin']
41
- grunt.registerTask 'server', ['joosy:server']
41
+ grunt.registerTask 'server', ['joosy:server']
42
+
43
+ grunt.registerTask 'joosy:postinstall', ['joosy:bower', 'joosy:compile:production']
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.38
4
+ version: 1.2.0.alpha.41
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-07-16 00:00:00.000000000 Z
13
+ date: 2013-07-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sprockets
@@ -60,7 +60,8 @@ files:
60
60
  - lib/joosy.js
61
61
  - lib/joosy.rb
62
62
  - package.json
63
- - spec/helpers/helper.coffee
63
+ - spec/helpers/ground.coffee
64
+ - spec/helpers/matchers.coffee
64
65
  - spec/joosy/core/application_spec.coffee
65
66
  - spec/joosy/core/helpers/view_spec.coffee
66
67
  - spec/joosy/core/helpers/widgets_spec.coffee
@@ -76,7 +77,7 @@ files:
76
77
  - spec/joosy/core/modules/widget_manager_spec.coffee
77
78
  - spec/joosy/core/page_spec.coffee
78
79
  - spec/joosy/core/router_spec.coffee
79
- - spec/joosy/core/templaters/rails_jst_spec.coffee
80
+ - spec/joosy/core/templaters/jst_spec.coffee
80
81
  - spec/joosy/core/widget_spec.coffee
81
82
  - spec/joosy/extensions/form/form_spec.coffee
82
83
  - spec/joosy/extensions/form/helpers/forms_spec.coffee
@@ -104,7 +105,7 @@ files:
104
105
  - src/joosy/core/page.coffee
105
106
  - src/joosy/core/resources/watcher.coffee
106
107
  - src/joosy/core/router.coffee
107
- - src/joosy/core/templaters/rails_jst.coffee
108
+ - src/joosy/core/templaters/jst.coffee
108
109
  - src/joosy/core/widget.coffee
109
110
  - src/joosy/extensions/preloaders/caching.coffee
110
111
  - src/joosy/extensions/preloaders/index.coffee
@@ -1,68 +0,0 @@
1
- beforeEach ->
2
- Joosy.Resources.Base?.resetIdentity()
3
-
4
- window.JST = {}
5
- $('body').append('<div id="ground">')
6
-
7
- @ground = $('body #ground')
8
-
9
- @seedGround = ->
10
- @ground.html('
11
- <div id="application" class="application">
12
- <div id="header" class="header" />
13
- <div id="wrapper" class="wrapper">
14
- <div id="content" class="content">
15
- <div id="post1" class="post" />
16
- <div id="post2" class="post" />
17
- <div id="post3" class="post" />
18
- </div>
19
- <div id="sidebar" class="sidebar">
20
- <div id="widget1" class="widget" />
21
- <div id="widget2" class="widget" />
22
- </div>
23
- </div>
24
- <div id="footer" class="footer" />
25
- </div>
26
- ')
27
-
28
- @addMatchers
29
- toBeSequenced: () ->
30
- if !Object.isArray(@actual) || @actual.length == 0
31
- console.log 'toBeSequenced: not array or empty array given'
32
- return false
33
- i = 0
34
- for spy in @actual
35
- unless spy.callCount == 1
36
- console.log "toBeSequenced: spy ##{i} was called #{spy.callCount} times"
37
- return false
38
- i++
39
- if @actual.length > 1
40
- for spy in @actual.from(1)
41
- i = @actual.indexOf spy
42
- previous = @actual[i - 1]
43
- unless spy.calledAfter previous
44
- console.log "toBeSequenced: spy ##{i} wasn't called after spy ##{i - 1}"
45
- return false
46
- return true
47
-
48
- toBeTag: (tagName, content, attrs) ->
49
- @message = =>
50
- "Expected #{@actual} to be a tag #{tagName} with attributes #{JSON.stringify attrs} and content #{content}"
51
-
52
- tag = $ @actual
53
- flag = true
54
-
55
- flag = flag && tag.length == 1
56
- flag = flag && tag[0].nodeName == tagName.toUpperCase()
57
- if content != false
58
- flag = flag && tag.html() == content
59
-
60
- for name, val of attrs
61
- flag = flag && !!(if val.constructor == RegExp then tag.attr(name).match(val) else tag.attr(name) == val)
62
-
63
- flag = flag && tag[0].attributes.length == Object.keys(attrs).length
64
-
65
- flag
66
-
67
- afterEach ->
68
- @ground.remove() unless @polluteGround
@@ -1,25 +0,0 @@
1
- describe "Joosy.Templaters.RailsJST", ->
2
-
3
- beforeEach ->
4
- @templater = new Joosy.Templaters.RailsJST()
5
-
6
- class @Klass extends Joosy.Module
7
-
8
- Joosy.namespace 'British.Cities', ->
9
- class @Klass extends Joosy.Module
10
-
11
- it "should resolve templates correctly", ->
12
- expect(@templater.resolveTemplate(undefined, "/absolute", undefined)).
13
- toEqual "absolute"
14
-
15
- expect(@templater.resolveTemplate('widgets', 'fuga', {})).
16
- toEqual 'widgets/fuga'
17
-
18
- expect(@templater.resolveTemplate('widgets', 'fuga', new @Klass)).
19
- toEqual 'widgets/fuga'
20
-
21
- expect(@templater.resolveTemplate('widgets', 'fuga', new British.Cities.Klass)).
22
- toEqual 'widgets/british/cities/fuga'
23
-
24
- expect(@templater.resolveTemplate('widgets', 'hoge/fuga', new British.Cities.Klass)).
25
- toEqual 'widgets/british/cities/hoge/fuga'