joosy 1.1.2 → 1.2.0.alpha.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -7
  3. data/Gemfile +1 -11
  4. data/Gruntfile.coffee +138 -0
  5. data/README.md +65 -24
  6. data/bin/joosy +21 -0
  7. data/bower.json +23 -0
  8. data/joosy.gemspec +6 -12
  9. data/lib/joosy.js +3754 -0
  10. data/lib/joosy.rb +8 -9
  11. data/package.json +37 -0
  12. data/spec/{javascripts/helpers/spec_helper.js.coffee → helpers/helper.coffee} +0 -0
  13. data/spec/{javascripts/joosy/core/application_spec.js.coffee → joosy/core/application_spec.coffee} +0 -0
  14. data/spec/{javascripts/joosy/core/form_spec.js.coffee → joosy/core/form_spec.coffee} +30 -30
  15. data/spec/{javascripts/joosy/core/helpers/forms_spec.js.coffee → joosy/core/helpers/forms_spec.coffee} +0 -0
  16. data/spec/{javascripts/joosy/core/helpers/view_spec.js.coffee → joosy/core/helpers/view_spec.coffee} +0 -0
  17. data/spec/{javascripts/joosy/core/helpers/widgets_spec.js.coffee → joosy/core/helpers/widgets_spec.coffee} +0 -0
  18. data/spec/{javascripts/joosy/core/joosy_spec.js.coffee → joosy/core/joosy_spec.coffee} +0 -0
  19. data/spec/{javascripts/joosy/core/layout_spec.js.coffee → joosy/core/layout_spec.coffee} +0 -0
  20. data/spec/{javascripts/joosy/core/modules/container_spec.js.coffee → joosy/core/modules/container_spec.coffee} +1 -1
  21. data/spec/{javascripts/joosy/core/modules/events_spec.js.coffee → joosy/core/modules/events_spec.coffee} +0 -0
  22. data/spec/{javascripts/joosy/core/modules/filters_spec.js.coffee → joosy/core/modules/filters_spec.coffee} +0 -0
  23. data/spec/{javascripts/joosy/core/modules/log_spec.js.coffee → joosy/core/modules/log_spec.coffee} +0 -0
  24. data/spec/{javascripts/joosy/core/modules/module_spec.js.coffee → joosy/core/modules/module_spec.coffee} +0 -0
  25. data/spec/{javascripts/joosy/core/modules/renderer_spec.js.coffee → joosy/core/modules/renderer_spec.coffee} +35 -0
  26. data/spec/{javascripts/joosy/core/modules/time_manager_spec.js.coffee → joosy/core/modules/time_manager_spec.coffee} +0 -0
  27. data/spec/{javascripts/joosy/core/modules/widget_manager_spec.js.coffee → joosy/core/modules/widget_manager_spec.coffee} +0 -0
  28. data/spec/{javascripts/joosy/core/page_spec.js.coffee → joosy/core/page_spec.coffee} +0 -0
  29. data/spec/{javascripts/joosy/core/resource/collection_spec.js.coffee → joosy/core/resource/collection_spec.coffee} +0 -0
  30. data/spec/{javascripts/joosy/core/resource/generic_spec.js.coffee → joosy/core/resource/generic_spec.coffee} +0 -0
  31. data/spec/{javascripts/joosy/core/resource/rest_collection_spec.js.coffee → joosy/core/resource/rest_collection_spec.coffee} +0 -0
  32. data/spec/{javascripts/joosy/core/resource/rest_spec.js.coffee → joosy/core/resource/rest_spec.coffee} +0 -8
  33. data/spec/{javascripts/joosy/core/router_spec.js.coffee → joosy/core/router_spec.coffee} +19 -22
  34. data/spec/{javascripts/joosy/core/templaters/rails_jst_spec.js.coffee → joosy/core/templaters/rails_jst_spec.coffee} +0 -0
  35. data/spec/{javascripts/joosy/core/widget_spec.js.coffee → joosy/core/widget_spec.coffee} +0 -0
  36. data/spec/{javascripts/joosy/preloaders/caching_spec.js.coffee → joosy/preloaders/caching_spec.coffee} +2 -2
  37. data/spec/{javascripts/joosy/preloaders/inline_spec.js.coffee → joosy/preloaders/inline_spec.coffee} +1 -1
  38. data/spec/support/test.js +1 -0
  39. data/{app/assets/javascripts/joosy/core/application.js.coffee → src/joosy/core/application.coffee} +0 -0
  40. data/{app/assets/javascripts/joosy/core/form.js.coffee → src/joosy/core/form.coffee} +5 -5
  41. data/{app/assets/javascripts/joosy/core/helpers/form.js.coffee → src/joosy/core/helpers/form.coffee} +0 -0
  42. data/{app/assets/javascripts/joosy/core/helpers/view.js.coffee → src/joosy/core/helpers/view.coffee} +0 -0
  43. data/{app/assets/javascripts/joosy/core/helpers/widgets.js.coffee → src/joosy/core/helpers/widgets.coffee} +0 -0
  44. data/{app/assets/javascripts/joosy/core/joosy.js.coffee → src/joosy/core/joosy.coffee} +1 -1
  45. data/{app/assets/javascripts/joosy/core/layout.js.coffee → src/joosy/core/layout.coffee} +0 -0
  46. data/{app/assets/javascripts/joosy/core/modules/container.js.coffee → src/joosy/core/modules/container.coffee} +1 -1
  47. data/{app/assets/javascripts/joosy/core/modules/events.js.coffee → src/joosy/core/modules/events.coffee} +4 -6
  48. data/{app/assets/javascripts/joosy/core/modules/filters.js.coffee → src/joosy/core/modules/filters.coffee} +0 -0
  49. data/{app/assets/javascripts/joosy/core/modules/log.js.coffee → src/joosy/core/modules/log.coffee} +0 -0
  50. data/{app/assets/javascripts/joosy/core/modules/module.js.coffee → src/joosy/core/modules/module.coffee} +0 -0
  51. data/{app/assets/javascripts/joosy/core/modules/renderer.js.coffee → src/joosy/core/modules/renderer.coffee} +1 -1
  52. data/{app/assets/javascripts/joosy/core/modules/time_manager.js.coffee → src/joosy/core/modules/time_manager.coffee} +0 -0
  53. data/{app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee → src/joosy/core/modules/widgets_manager.coffee} +0 -0
  54. data/{app/assets/javascripts/joosy/core/page.js.coffee → src/joosy/core/page.coffee} +0 -1
  55. data/{app/assets/javascripts/joosy/core/preloader.js.coffee → src/joosy/core/preloader.coffee} +0 -0
  56. data/{app/assets/javascripts/joosy/core/resource/collection.js.coffee → src/joosy/core/resource/collection.coffee} +0 -0
  57. data/{app/assets/javascripts/joosy/core/resource/generic.js.coffee → src/joosy/core/resource/generic.coffee} +5 -5
  58. data/{app/assets/javascripts/joosy/core/resource/rest.js.coffee → src/joosy/core/resource/rest.coffee} +5 -5
  59. data/{app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee → src/joosy/core/resource/rest_collection.coffee} +0 -0
  60. data/src/joosy/core/resource/watcher.coffee +50 -0
  61. data/{app/assets/javascripts/joosy/core/router.js.coffee → src/joosy/core/router.coffee} +28 -30
  62. data/{app/assets/javascripts/joosy/core/templaters/rails_jst.js.coffee → src/joosy/core/templaters/rails_jst.coffee} +12 -2
  63. data/{app/assets/javascripts/joosy/core/widget.js.coffee → src/joosy/core/widget.coffee} +0 -0
  64. data/src/joosy/generators/command.coffee +49 -0
  65. data/src/joosy/generators/generator.coffee +93 -0
  66. data/src/joosy/generators/layout.coffee +20 -0
  67. data/src/joosy/generators/page.coffee +20 -0
  68. data/src/joosy/generators/project/base.coffee +28 -0
  69. data/src/joosy/generators/project/standalone.coffee +25 -0
  70. data/src/joosy/generators/project.coffee +16 -0
  71. data/src/joosy/generators/widget.coffee +20 -0
  72. data/{app/assets/javascripts/joosy/preloaders/caching.js.coffee → src/joosy/preloaders/caching.coffee} +0 -0
  73. data/{app/assets/javascripts/joosy/preloaders/inline.js.coffee → src/joosy/preloaders/inline.coffee} +0 -0
  74. data/src/joosy.coffee +2 -0
  75. data/src/vendor/metamorph.coffee +410 -0
  76. data/tasks/joosy.coffee +63 -0
  77. data/templates/application/base/application.coffee +11 -0
  78. data/{lib/rails/generators/joosy/templates/app/helpers/application.js.coffee → templates/application/base/helpers/application.coffee} +0 -0
  79. data/{lib/rails/generators/joosy/templates/app/layouts/application.js.coffee → templates/application/base/layouts/application.coffee} +0 -0
  80. data/{lib/rails/generators/joosy/templates/app/pages/application.js.coffee → templates/application/base/pages/application.coffee} +0 -0
  81. data/{lib/rails/generators/joosy/templates/app/pages/welcome/index.js.coffee → templates/application/base/pages/welcome/index.coffee} +3 -3
  82. data/templates/application/base/routes.coffee +3 -0
  83. data/{lib/rails/generators/joosy/templates/app → templates/application/base}/templates/layouts/application.jst.hamlc +0 -0
  84. data/{lib/rails/generators/joosy/templates/app → templates/application/base}/templates/pages/welcome/index.jst.hamlc +1 -2
  85. data/templates/application/standalone/.gitignore +5 -0
  86. data/templates/application/standalone/Gruntfile.coffee +40 -0
  87. data/templates/application/standalone/Procfile +1 -0
  88. data/templates/application/standalone/bower.json +7 -0
  89. data/templates/application/standalone/package.json +24 -0
  90. data/templates/application/standalone/source/index.haml +7 -0
  91. data/templates/application/standalone/stylesheets/application.styl +2 -0
  92. data/templates/layout/basic.coffee +2 -0
  93. data/templates/layout/namespaced.coffee +4 -0
  94. data/templates/page/basic.coffee +3 -0
  95. data/templates/page/namespaced.coffee +5 -0
  96. data/templates/widget/basic.coffee +2 -0
  97. data/templates/widget/namespaced.coffee +4 -0
  98. metadata +98 -179
  99. data/.codoopts +0 -5
  100. data/Gemfile.lock +0 -157
  101. data/Guardfile +0 -32
  102. data/LICENSE +0 -22
  103. data/MIT-LICENSE +0 -21
  104. data/Rakefile +0 -14
  105. data/app/assets/javascripts/joosy.js.coffee +0 -5
  106. data/app/helpers/joosy/sprockets_helper.rb +0 -41
  107. data/app/views/layouts/json_wrapper.json.erb +0 -1
  108. data/lib/joosy/rails/engine.rb +0 -24
  109. data/lib/joosy/version.rb +0 -3
  110. data/lib/rails/generators/joosy/application_generator.rb +0 -43
  111. data/lib/rails/generators/joosy/joosy_base.rb +0 -30
  112. data/lib/rails/generators/joosy/layout_generator.rb +0 -30
  113. data/lib/rails/generators/joosy/page_generator.rb +0 -42
  114. data/lib/rails/generators/joosy/preloader_generator.rb +0 -30
  115. data/lib/rails/generators/joosy/resource_generator.rb +0 -40
  116. data/lib/rails/generators/joosy/templates/app/layouts/template.js.coffee +0 -2
  117. data/lib/rails/generators/joosy/templates/app/pages/template.js.coffee +0 -5
  118. data/lib/rails/generators/joosy/templates/app/resources/template.js.coffee +0 -2
  119. data/lib/rails/generators/joosy/templates/app/resources/template_with_namespace.js.coffee +0 -4
  120. data/lib/rails/generators/joosy/templates/app/routes.js.coffee +0 -8
  121. data/lib/rails/generators/joosy/templates/app/widgets/template.js.coffee +0 -2
  122. data/lib/rails/generators/joosy/templates/app.js.coffee +0 -11
  123. data/lib/rails/generators/joosy/templates/app_controller.rb +0 -9
  124. data/lib/rails/generators/joosy/templates/app_preloader.js.coffee.erb +0 -13
  125. data/lib/rails/generators/joosy/templates/app_railties.js.coffee.erb +0 -11
  126. data/lib/rails/generators/joosy/templates/preload.html.erb +0 -26
  127. data/lib/rails/generators/joosy/templates/preload.html.haml +0 -19
  128. data/lib/rails/generators/joosy/templates/preload.html.slim +0 -19
  129. data/lib/rails/generators/joosy/widget_generator.rb +0 -30
  130. data/lib/rails/resources_with_joosy.rb +0 -11
  131. data/spec/javascripts/support/assets/coolface.jpg +0 -0
  132. data/spec/javascripts/support/assets/okay.jpg +0 -0
  133. data/spec/javascripts/support/assets/test.js +0 -1
  134. data/spec/javascripts/support/jasmine.yml +0 -74
  135. data/spec/javascripts/support/jasmine_config.rb +0 -23
  136. data/spec/javascripts/support/jasmine_runner.rb +0 -32
  137. data/spec/javascripts/support/sinon-1.3.1.js +0 -3469
  138. data/spec/javascripts/support/sinon-ie-1.3.1.js.skip +0 -82
  139. data/vendor/assets/javascripts/jquery.form.js +0 -1190
  140. data/vendor/assets/javascripts/jquery.hashchange.js +0 -390
  141. data/vendor/assets/javascripts/metamorph.js +0 -409
  142. data/vendor/assets/javascripts/sugar.js +0 -8637
data/lib/joosy.rb CHANGED
@@ -1,17 +1,16 @@
1
1
  require 'haml_coffee_assets'
2
- require 'joosy/version'
3
-
4
- if defined?(Rails)
5
- require 'joosy/rails/engine'
6
- require 'rails/resources_with_joosy'
7
- end
2
+ require 'json'
8
3
 
9
4
  module Joosy
5
+ PACKAGE = File.expand_path("../../package.json", __FILE__)
6
+
7
+ # Converting semver to the notation compatible with rubygems
8
+ VERSION = JSON.parse(File.read(PACKAGE))['version'].gsub '-', '.'
9
+
10
10
  def self.assets_paths
11
11
  [
12
- File.expand_path('../../app/assets/javascripts', __FILE__),
13
- File.expand_path('../../vendor/assets/javascripts', __FILE__),
14
- File.dirname(HamlCoffeeAssets.helpers_path)
12
+ File.expand_path('../../src', __FILE__),
13
+ File.dirname(HamlCoffeeAssets.helpers_path)
15
14
  ]
16
15
  end
17
16
  end
data/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "joosy",
3
+ "description": "Joosy Framework",
4
+ "keywords": [
5
+ "joosy"
6
+ ],
7
+ "version": "1.2.0-alpha.4",
8
+ "author": "Boris Staal <boris@staal.io>",
9
+ "bin": {
10
+ "joosy": "bin/joosy"
11
+ },
12
+ "engines": {
13
+ "node": ">=0.4.0"
14
+ },
15
+ "dependencies": {
16
+ "sugar": "~1.3.8",
17
+ "coffee-script": "~1.6.3",
18
+ "command-router": "0.0.5",
19
+ "resolve": "~0.4.0",
20
+ "ejs": "~0.8.4",
21
+ "prompt": "~0.2.9",
22
+ "commander": "~1.2.0",
23
+ "colors": "~0.6.0-1",
24
+ "grunt": "~0.4.1"
25
+ },
26
+ "devDependencies": {
27
+ "bower": "~0.9.2",
28
+ "mincer": "~0.4.6",
29
+ "grunt-mincer": "~0.3.1",
30
+ "grunt-contrib-jasmine": "git://github.com/inossidabile/grunt-contrib-jasmine.git#deep-outfile",
31
+ "grunt-contrib-watch": "~0.4.4",
32
+ "grunt-contrib-coffee": "~0.7.0",
33
+ "grunt-contrib-connect": "~0.3.0",
34
+ "grunt-coffeelint": "0.0.6",
35
+ "grunt-release": "~0.3.5"
36
+ }
37
+ }
@@ -54,7 +54,7 @@ describe "Joosy.Form", ->
54
54
  formWithProperties = new Joosy.Form @nudeForm, invalidationClass: 'fluffy'
55
55
  expect(formWithProperties.container).toEqual @nudeForm
56
56
  expect(formWithProperties.invalidationClass).toEqual 'fluffy'
57
- expect(formWithProperties.fields.length).toEqual 5
57
+ expect(formWithProperties.$fields.length).toEqual 5
58
58
 
59
59
  expect(@spy.callCount).toEqual 1
60
60
 
@@ -63,7 +63,7 @@ describe "Joosy.Form", ->
63
63
  expect(formWithCallback.container).toEqual @putForm
64
64
  expect(formWithCallback.invalidationClass).toEqual 'field_with_errors'
65
65
  expect(formWithCallback.success).toBe callback
66
- expect(formWithCallback.fields.length).toEqual 1
66
+ expect(formWithCallback.$fields.length).toEqual 1
67
67
 
68
68
  expect(@spy.callCount).toEqual 1
69
69
 
@@ -97,40 +97,40 @@ describe "Joosy.Form", ->
97
97
 
98
98
  it "should fill form, set proper action and method and store resource", ->
99
99
  @nudeForm.fill @resource
100
- expect(@nudeForm.fields[0].value).toEqual 'foo'
101
- expect(@nudeForm.fields[1].value).toEqual 'bar'
102
- expect(@nudeForm.fields[2].checked).toEqual true
103
- expect(@nudeForm.fields[2].value).toEqual '1'
104
- expect(@nudeForm.fields[3].value).toEqual 'qwe'
105
- expect(@nudeForm.fields[3].checked).toEqual false
106
- expect(@nudeForm.fields[4].value).toEqual 'zxc'
107
- expect(@nudeForm.fields[4].checked).toEqual true
100
+ expect(@nudeForm.$fields[0].value).toEqual 'foo'
101
+ expect(@nudeForm.$fields[1].value).toEqual 'bar'
102
+ expect(@nudeForm.$fields[2].checked).toEqual true
103
+ expect(@nudeForm.$fields[2].value).toEqual '1'
104
+ expect(@nudeForm.$fields[3].value).toEqual 'qwe'
105
+ expect(@nudeForm.$fields[3].checked).toEqual false
106
+ expect(@nudeForm.$fields[4].value).toEqual 'zxc'
107
+ expect(@nudeForm.$fields[4].checked).toEqual true
108
108
  expect(@nudeForm.container.attr('method').toLowerCase()).toEqual 'post'
109
109
  expect(@nudeForm.container.attr 'action').toEqual '/tests/1'
110
110
  expect(@nudeForm.__resource).toEqual @resource
111
111
 
112
112
  it "should fill form with camelized properties", ->
113
113
  @putForm.fill @resource
114
- expect(@putForm.fields[0].value).toEqual 'baz'
114
+ expect(@putForm.$fields[0].value).toEqual 'baz'
115
115
  expect(@putForm.container.attr('method').toLowerCase()).toEqual 'post'
116
116
  expect(@putForm.container.attr 'action').toEqual '/tests/1'
117
117
 
118
118
  it "should fill form with any properties", ->
119
119
  @exactForm.fill @resource
120
- expect(@exactForm.fields[0].value).toEqual 'works'
120
+ expect(@exactForm.$fields[0].value).toEqual 'works'
121
121
 
122
122
  it "should fill form with decorator", ->
123
123
  @moreForm.fill @resource,
124
124
  decorator: (e) ->
125
125
  e.ololo = e.camelBaz
126
126
  e
127
- expect(@moreForm.fields[0].value).toEqual 'baz'
127
+ expect(@moreForm.$fields[0].value).toEqual 'baz'
128
128
 
129
129
  it "should fill form with extended action", ->
130
130
  @nudeForm.fill @resource,
131
131
  action: @resource.memberPath(from: 'calculate')
132
- expect(@nudeForm.fields[0].value).toEqual 'foo'
133
- expect(@nudeForm.fields[1].value).toEqual 'bar'
132
+ expect(@nudeForm.$fields[0].value).toEqual 'foo'
133
+ expect(@nudeForm.$fields[1].value).toEqual 'bar'
134
134
  expect(@nudeForm.container.attr 'action').toEqual '/tests/1/calculate'
135
135
 
136
136
  resource = @Test.build 'someId'
@@ -156,14 +156,14 @@ describe "Joosy.Form", ->
156
156
 
157
157
  it "should fill nested attributes and resources", ->
158
158
  @nestedForm.fill @resource
159
- expect(@nestedForm.fields[0].value).toEqual 'test'
160
- expect(@nestedForm.fields[1].value).toEqual 'one'
161
- expect(@nestedForm.fields[2].value).toEqual 'two'
162
- expect(@nestedForm.fields[3].value).toEqual 'sin'
159
+ expect(@nestedForm.$fields[0].value).toEqual 'test'
160
+ expect(@nestedForm.$fields[1].value).toEqual 'one'
161
+ expect(@nestedForm.$fields[2].value).toEqual 'two'
162
+ expect(@nestedForm.$fields[3].value).toEqual 'sin'
163
163
 
164
164
  it 'should fill array-like attributes', ->
165
165
  @arrayForm.fill @resource
166
- expect(@arrayForm.fields[0].value).toEqual 'here'
166
+ expect(@arrayForm.$fields[0].value).toEqual 'here'
167
167
 
168
168
  it "should break cross-references", ->
169
169
  @resource('single')('trololo', @resource)
@@ -230,20 +230,20 @@ describe "Joosy.Form", ->
230
230
 
231
231
  it "should trigger 'success'", ->
232
232
  expect(@target.method).toEqual 'POST'
233
- expect(@target.url).toMatch /.*?\/tests\/1/
233
+ expect(@target.url.endsWith '/tests/1').toEqual true
234
234
  @target.respond 200, 'Content-Type': 'application/json', '{"form": "works"}'
235
235
  expect(@spy.callCount).toEqual 1
236
236
  expect(@spy.args[0][0]).toEqual {form: 'works'}
237
237
 
238
238
  it "should fill class for invalidated fields by default", ->
239
239
  @target.respond 422, 'Content-Type': 'application/json', '{"foo": "error!"}'
240
- expect($(@nudeForm.fields[0]).attr 'class').toEqual 'field_with_errors'
240
+ expect($(@nudeForm.$fields[0]).attr 'class').toEqual 'field_with_errors'
241
241
 
242
242
  it "should trigger 'error' and complete default action if it returned true", ->
243
243
  @nudeForm.error = sinon.spy ->
244
244
  true
245
245
  @target.respond 422, 'Content-Type': 'application/json', '{"foo": "error!"}'
246
- expect($(@nudeForm.fields[0]).attr 'class').toEqual 'field_with_errors'
246
+ expect($(@nudeForm.$fields[0]).attr 'class').toEqual 'field_with_errors'
247
247
  expect(@nudeForm.error.callCount).toEqual 1
248
248
  expect(@nudeForm.error.args[0][0]).toEqual
249
249
  "foo": "error!"
@@ -252,31 +252,31 @@ describe "Joosy.Form", ->
252
252
  @nudeForm.error = sinon.spy ->
253
253
  false
254
254
  @target.respond 422, 'Content-Type': 'application/json', '{"foo": "error!"}'
255
- expect($(@nudeForm.fields[0]).attr 'class').toNotEqual 'field_with_errors'
255
+ expect($(@nudeForm.$fields[0]).attr 'class').toNotEqual 'field_with_errors'
256
256
  expect(@nudeForm.error.callCount).toEqual 1
257
257
 
258
258
  it "should clear fields before another submit", ->
259
259
  @target.respond 422, 'Content-Type': 'application/json', '{"foo": "error!"}'
260
- expect($(@nudeForm.fields[0]).attr 'class').toEqual 'field_with_errors'
260
+ expect($(@nudeForm.$fields[0]).attr 'class').toEqual 'field_with_errors'
261
261
  @nudeForm.container.submit()
262
- expect($(@nudeForm.fields[0]).attr 'class').toNotEqual 'field_with_errors'
262
+ expect($(@nudeForm.$fields[0]).attr 'class').toNotEqual 'field_with_errors'
263
263
 
264
264
  it "should trigger 'before' and do default action if it returns true", ->
265
265
  @target.respond 422, 'Content-Type': 'application/json', '{"foo": "error!"}'
266
- expect($(@nudeForm.fields[0]).attr 'class').toEqual 'field_with_errors'
266
+ expect($(@nudeForm.$fields[0]).attr 'class').toEqual 'field_with_errors'
267
267
  @nudeForm.before = sinon.spy ->
268
268
  true
269
269
  @nudeForm.container.submit()
270
- expect($(@nudeForm.fields[0]).attr 'class').toNotEqual 'field_with_errors'
270
+ expect($(@nudeForm.$fields[0]).attr 'class').toNotEqual 'field_with_errors'
271
271
  expect(@nudeForm.before.callCount).toEqual 1
272
272
 
273
273
  it "should trigger 'before' and skip default action if it returns false", ->
274
274
  @target.respond 422, 'Content-Type': 'application/json', '{"foo": "error!"}'
275
- expect($(@nudeForm.fields[0]).attr 'class').toEqual 'field_with_errors'
275
+ expect($(@nudeForm.$fields[0]).attr 'class').toEqual 'field_with_errors'
276
276
  @nudeForm.before = sinon.spy ->
277
277
  false
278
278
  @nudeForm.container.submit()
279
- expect($(@nudeForm.fields[0]).attr 'class').toEqual 'field_with_errors'
279
+ expect($(@nudeForm.$fields[0]).attr 'class').toEqual 'field_with_errors'
280
280
  expect(@nudeForm.before.callCount).toEqual 1
281
281
 
282
282
  describe "Error response handling", ->
@@ -15,7 +15,7 @@ describe "Joosy.Modules.Container", ->
15
15
  it "should have property named per declared element in container", ->
16
16
  @ground.prepend('<div class="footer" />') # out of container
17
17
  @box.refreshElements()
18
- target = @box.footer.get 0
18
+ target = @box.$footer.get 0
19
19
  expect(target).toBeTruthy()
20
20
  expect(target).toBe $('.footer', @box.container).get 0
21
21
  expect(target).toBe @box.$('.footer').get 0
@@ -112,6 +112,41 @@ describe "Joosy.Modules.Renderer", ->
112
112
  runs ->
113
113
  expect(elem.text()).toBe "suck"
114
114
 
115
+ xit "renders collections and track its new items", ->
116
+ class Foo extends Joosy.Resource.Generic
117
+ @entity 'foo'
118
+
119
+ data = new Joosy.Resource.Collection(Foo)
120
+ data.load [
121
+ {key: 1},
122
+ {key: 2}
123
+ ]
124
+
125
+ @TestContainer.view (locals) ->
126
+ template = -> @data.map((item) -> item('key')).join('')
127
+ @renderDynamic(template, locals)
128
+
129
+ elem = $("<div></div>")
130
+ @ground.append elem
131
+ elem.html @dummyContainer.__renderer(data)
132
+
133
+ waits 0
134
+
135
+ runs ->
136
+ expect(elem.text()).toBe "12"
137
+ data.add Foo.build(key: 3)
138
+
139
+ waits 0
140
+
141
+ runs ->
142
+ expect(elem.text()).toBe "123"
143
+ data.at(2)('key', 6)
144
+
145
+ waits 0
146
+
147
+ runs ->
148
+ expect(elem.text()).toBe "126"
149
+
115
150
  it "debounces morpher updates", ->
116
151
  @TestContainer.view (locals) ->
117
152
  template = -> @object.value
@@ -14,10 +14,6 @@ describe "Joosy.Resource.REST", ->
14
14
  class @Cat extends Joosy.Resource.REST
15
15
  @entity 'cat'
16
16
 
17
- class @Dog extends Joosy.Resource.REST
18
- @entity 'dog'
19
- @source '/cuties'
20
-
21
17
  beforeEach ->
22
18
  @server = sinon.fakeServer.create()
23
19
 
@@ -37,10 +33,6 @@ describe "Joosy.Resource.REST", ->
37
33
  expect(Animal.Cat.basePath parent: parent).toEqual '/fluffy_parents/1/animal/cats'
38
34
  expect(Animal.Cat.basePath parent: [grandParent, parent]).toEqual '/fluffy_parents/666/fluffy_parents/1/animal/cats'
39
35
 
40
- expect(Animal.Dog.basePath()).toEqual '/cuties'
41
- expect(Animal.Dog.basePath parent: parent).toEqual '/fluffy_parents/1/cuties'
42
- expect(Animal.Dog.basePath parent: [grandParent, parent]).toEqual '/fluffy_parents/666/fluffy_parents/1/cuties'
43
-
44
36
  it "builds member path", ->
45
37
  parent = FluffyParent.build 1
46
38
  grandParent = FluffyParent.build 666
@@ -141,7 +141,7 @@ describe "Joosy.Router", ->
141
141
 
142
142
  Joosy.Application.setCurrentPage.restore()
143
143
  Joosy.Router.restrict false
144
-
144
+
145
145
  it "should DRAW simple routes, only using match and root", ->
146
146
  Joosy.Router.map
147
147
  '/': spies.root
@@ -150,14 +150,14 @@ describe "Joosy.Router", ->
150
150
  raw_routes_for_map = Joosy.Router.rawRoutes
151
151
 
152
152
  Joosy.Router.reset()
153
-
153
+
154
154
  Joosy.Router.draw ->
155
155
  @root to: spies.root
156
156
  @match '/page', to: TestPage
157
157
  @notFound to: spies.wildcard
158
-
158
+
159
159
  expect(Joosy.Router.rawRoutes).toEqual(raw_routes_for_map)
160
-
160
+
161
161
  it "should DRAW namespaced routes", ->
162
162
  Joosy.Router.map
163
163
  '/': spies.root
@@ -169,7 +169,7 @@ describe "Joosy.Router", ->
169
169
  rawRoutesForMap = Joosy.Router.rawRoutes
170
170
 
171
171
  Joosy.Router.reset()
172
-
172
+
173
173
  Joosy.Router.draw ->
174
174
  @root to: spies.root
175
175
  @match '/page', to: TestPage
@@ -177,25 +177,25 @@ describe "Joosy.Router", ->
177
177
  @match '/page/:id', to: spies.section
178
178
  @match '/page2/:more', to: TestPage
179
179
  @notFound to: spies.wildcard
180
-
180
+
181
181
  expect(Joosy.Router.rawRoutes).toEqual(rawRoutesForMap)
182
-
182
+
183
183
  it "should DRAW simple route reverses, only using match and root", ->
184
184
  Joosy.Router.draw ->
185
185
  @root to: spies.root
186
186
  @match '/page', to: TestPage, as: "page"
187
187
  @match '/page/:id', to: TestPage, as: "pageFor"
188
188
  @notFound to: spies.wildcard
189
-
189
+
190
190
  validate = ->
191
191
  expect(@rootUrl).not.toEqual undefined
192
192
  expect(@rootPath).not.toEqual undefined
193
-
193
+
194
194
  expect(@rootPath()).toEqual "#!/"
195
195
  expect(@pagePath()).toEqual "#!/page"
196
196
  expect(@pageForPath(id: 3)).toEqual "#!/page/3"
197
197
  validate.call(Joosy.Helpers.Application)
198
-
198
+
199
199
  it "should DRAW more complex reverses using namespaces", ->
200
200
  Joosy.Router.draw ->
201
201
  @namespace '/projects', as: "projects", ->
@@ -203,13 +203,11 @@ describe "Joosy.Router", ->
203
203
  @namespace "/:id", ->
204
204
  @match "/", to: TestPage, as: "show"
205
205
  @match "/edit", to: TestPage, as: "edit"
206
-
207
- @namespace '/subnamespace', as: 'subnamespace', ->
208
- @match '/', to: TestPage, as: 'index'
209
-
206
+ @match "/delete", to: TestPage, as: "delete"
207
+
210
208
  @namespace '/tickets', ->
211
209
  @match "/", to: TestPage, as: "tasksIndex"
212
-
210
+
213
211
  @namespace '/activities', ->
214
212
  @root to: TestPage, as: "activities"
215
213
 
@@ -217,21 +215,20 @@ describe "Joosy.Router", ->
217
215
  expect(@projectsIndexPath).not.toEqual undefined
218
216
  expect(@projectsIndexPath()).not.toEqual "#!/projects"
219
217
  expect(@projectsIndexPath()).toEqual "#!/projects/"
220
-
218
+
221
219
  expect(@projectsShowPath(id: 3)).toEqual "#!/projects/3/"
222
220
  expect(@projectsEditPath(id: 3)).toEqual "#!/projects/3/edit"
223
-
221
+ expect(@projectsDeletePath(id: 3)).toEqual "#!/projects/3/delete"
222
+
224
223
  expect(@tasksIndexPath()).toEqual "#!/tickets/"
225
224
  expect(@activitiesPath()).toEqual "#!/activities/"
226
-
227
- expect(@projectsSubnamespaceIndexPath()).toEqual '#!/projects/subnamespace/'
228
225
  validate.call(Joosy.Helpers.Application)
229
-
226
+
230
227
  it "should return reverse url with hostname and pathname", ->
231
228
  Joosy.Router.draw ->
232
229
  @match "/projects/", to: TestPage, as: "projectsIndex"
233
-
230
+
234
231
  validate = ->
235
232
  expect(@projectsIndexPath()).toEqual "#!/projects/"
236
- expect(@projectsIndexUrl()).toEqual "http://localhost:8888/#!/projects/"
233
+ expect(@projectsIndexUrl()).toEqual "#{location.protocol}//#{location.host}#{location.pathname}#!/projects/"
237
234
  validate.call(Joosy.Helpers.Application)
@@ -8,7 +8,7 @@ describe "CachingPreloader", ->
8
8
  server = sinon.fakeServer.create()
9
9
 
10
10
  load = ->
11
- CachingPreloader.load [['/spec/javascripts/support/assets/test.js']],
11
+ CachingPreloader.load [['/test.js']],
12
12
  complete: callback
13
13
 
14
14
  load()
@@ -16,7 +16,7 @@ describe "CachingPreloader", ->
16
16
  expect(server.requests.length).toEqual 1
17
17
  target = server.requests[0]
18
18
  expect(target.method).toEqual 'GET'
19
- expect(target.url).toMatch /^\/spec\/javascripts\/support\/assets\/test.js$/
19
+ expect(target.url).toMatch /^\/test.js$/
20
20
  target.respond 200, 'Content-Type': 'application/javascript',
21
21
  "window.variable_assigned_on_load = 'yapyap';"
22
22
 
@@ -5,7 +5,7 @@ describe "InlinePreloader", ->
5
5
  callback = sinon.spy()
6
6
 
7
7
  runs ->
8
- InlinePreloader.load [['/spec/javascripts/support/assets/test.js']],
8
+ InlinePreloader.load [['/spec/support/test.js']],
9
9
  complete: callback
10
10
 
11
11
  waits 100
@@ -0,0 +1 @@
1
+ window.variable_assigned_on_load = 'yapyap';
@@ -157,7 +157,7 @@ class Joosy.Form extends Joosy.Module
157
157
  # Resets form submit behavior to default
158
158
  #
159
159
  unbind: ->
160
- @container.unbind('submit').find('input:submit,input:image,button:submit').unbind('click');
160
+ @container.unbind('submit').find('input:submit,input:image,button:submit').unbind('click')
161
161
 
162
162
  #
163
163
  # Links current form with given resource and sets values of form inputs from with it.
@@ -185,7 +185,7 @@ class Joosy.Form extends Joosy.Module
185
185
  data.__joosy_form_filler_lock = true
186
186
  Object.each data, (property, val) =>
187
187
  key = @concatFieldName scope, property
188
- input = @fields.filter("[name='#{key}']:not(:file),[name='#{key.underscore()}']:not(:file),[name='#{key.camelize(false)}']:not(:file)")
188
+ input = @$fields.filter("[name='#{key}']:not(:file),[name='#{key.underscore()}']:not(:file),[name='#{key.camelize(false)}']:not(:file)")
189
189
  if input.length > 0
190
190
  if input.is ':checkbox'
191
191
  if val
@@ -203,7 +203,7 @@ class Joosy.Form extends Joosy.Module
203
203
  filler val.data, @concatFieldName(scope, "[#{property}_attributes][0]")
204
204
  else if Object.isObject(val) || Object.isArray(val)
205
205
  filler val, key
206
- else
206
+ else
207
207
  delete data.__joosy_form_filler_lock
208
208
 
209
209
  filler data, resource.__entityName || options.resourceName
@@ -252,7 +252,7 @@ class Joosy.Form extends Joosy.Module
252
252
  #
253
253
  __before: (xhr, settings) ->
254
254
  if !@before? || @before(arguments...) is true
255
- @fields.removeClass @invalidationClass
255
+ @$fields.removeClass @invalidationClass
256
256
 
257
257
  #
258
258
  # Inner error callback.
@@ -298,7 +298,7 @@ class Joosy.Form extends Joosy.Module
298
298
  # @param [String] field Name of field to find
299
299
  #
300
300
  findField: (field) ->
301
- @fields.filter("[name='#{field}']")
301
+ @$fields.filter("[name='#{field}']")
302
302
 
303
303
  #
304
304
  # Simulates REST methods by adding hidden _method input with real method
@@ -35,7 +35,7 @@
35
35
  name = name.split '.'
36
36
  space = window
37
37
  for part in name
38
- space = space[part] ?= {}
38
+ space = space[part] ?= {} if part.length > 0
39
39
 
40
40
  if generator
41
41
  generator = generator.apply space
@@ -29,7 +29,7 @@ Joosy.Modules.Container =
29
29
  refreshElements: ->
30
30
  @__collectElements().each (key, value) =>
31
31
  # TODO: Check for possible collisions?
32
- @[key] = @$(value)
32
+ @['$'+key] = @$(value)
33
33
 
34
34
  if @hasOwnProperty "__onRefreshes"
35
35
  @__onRefreshes.each (callback) => callback.apply @
@@ -1,5 +1,3 @@
1
- #= require joosy/core/joosy
2
-
3
1
  #
4
2
  # Basic events implementation
5
3
  #
@@ -15,13 +13,13 @@ Joosy.Modules.Events =
15
13
  # @param [Hash] options Options
16
14
  #
17
15
  wait: (name, events, callback) ->
18
- @__oneShotEvents ||= {}
16
+ @__oneShotEvents ||= Object.extended()
19
17
 
20
18
  # unnamed binding
21
19
  if Object.isFunction(events)
22
20
  callback = events
23
21
  events = name
24
- name = Object.keys(@__oneShotEvents).length.toString()
22
+ name = @__oneShotEvents.keys().length.toString()
25
23
 
26
24
  events = @__splitEvents events
27
25
  @__validateEvents events
@@ -37,13 +35,13 @@ Joosy.Modules.Events =
37
35
  # @param [Hash] options Options
38
36
  #
39
37
  bind: (name, events, callback) ->
40
- @__boundEvents ||= {}
38
+ @__boundEvents ||= Object.extended()
41
39
 
42
40
  # unnamed binding
43
41
  if Object.isFunction(events)
44
42
  callback = events
45
43
  events = name
46
- name = Object.keys(@__boundEvents).length.toString()
44
+ name = @__boundEvents.keys().length.toString()
47
45
 
48
46
  events = @__splitEvents events
49
47
  @__validateEvents events
@@ -1,5 +1,5 @@
1
1
  #= require_tree ../templaters
2
- #= require metamorph
2
+ #= require vendor/metamorph
3
3
 
4
4
  #
5
5
  # Core DOM rendering mechanics
@@ -155,7 +155,6 @@ class Joosy.Page extends Joosy.Module
155
155
  #
156
156
  @fetchSynchronized: (callback) ->
157
157
  @::__fetch = (complete) ->
158
- @data = {}
159
158
  @synchronize (context) ->
160
159
  context.after -> complete()
161
160
  callback.call(this, context)