volt 0.8.14 → 0.8.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/Readme.md +8 -2
  4. data/VERSION +1 -1
  5. data/app/volt/controllers/notices_controller.rb +1 -1
  6. data/app/volt/models/user.rb +2 -2
  7. data/app/volt/tasks/live_query/live_query_pool.rb +1 -1
  8. data/app/volt/tasks/query_tasks.rb +1 -1
  9. data/app/volt/tasks/store_tasks.rb +1 -1
  10. data/app/volt/tasks/user_tasks.rb +2 -2
  11. data/lib/volt/boot.rb +2 -2
  12. data/lib/volt/cli/asset_compile.rb +31 -27
  13. data/lib/volt/cli.rb +64 -65
  14. data/lib/volt/config.rb +25 -23
  15. data/lib/volt/console.rb +17 -16
  16. data/lib/volt/controllers/model_controller.rb +82 -80
  17. data/lib/volt/data_stores/data_store.rb +2 -2
  18. data/lib/volt/data_stores/mongo_driver.rb +2 -2
  19. data/lib/volt/extra_core/inflections.rb +2 -2
  20. data/lib/volt/extra_core/inflector/inflections.rb +185 -183
  21. data/lib/volt/extra_core/inflector/methods.rb +50 -48
  22. data/lib/volt/extra_core/string.rb +2 -2
  23. data/lib/volt/models/array_model.rb +93 -92
  24. data/lib/volt/models/cursor.rb +3 -2
  25. data/lib/volt/models/model.rb +248 -251
  26. data/lib/volt/models/model_hash_behaviour.rb +44 -44
  27. data/lib/volt/models/model_helpers.rb +38 -36
  28. data/lib/volt/models/model_state.rb +16 -17
  29. data/lib/volt/models/model_wrapper.rb +25 -24
  30. data/lib/volt/models/persistors/array_store.rb +145 -143
  31. data/lib/volt/models/persistors/base.rb +18 -16
  32. data/lib/volt/models/persistors/flash.rb +24 -22
  33. data/lib/volt/models/persistors/local_store.rb +46 -44
  34. data/lib/volt/models/persistors/model_identity_map.rb +10 -8
  35. data/lib/volt/models/persistors/model_store.rb +76 -76
  36. data/lib/volt/models/persistors/params.rb +19 -17
  37. data/lib/volt/models/persistors/query/query_listener.rb +65 -63
  38. data/lib/volt/models/persistors/query/query_listener_pool.rb +12 -10
  39. data/lib/volt/models/persistors/store.rb +28 -28
  40. data/lib/volt/models/persistors/store_factory.rb +12 -10
  41. data/lib/volt/models/persistors/store_state.rb +33 -31
  42. data/lib/volt/models/url.rb +96 -104
  43. data/lib/volt/models/validations.rb +56 -54
  44. data/lib/volt/models/validators/length_validator.rb +24 -22
  45. data/lib/volt/models/validators/presence_validator.rb +14 -12
  46. data/lib/volt/page/bindings/attribute_binding.rb +106 -106
  47. data/lib/volt/page/bindings/base_binding.rb +23 -21
  48. data/lib/volt/page/bindings/component_binding.rb +3 -1
  49. data/lib/volt/page/bindings/content_binding.rb +34 -34
  50. data/lib/volt/page/bindings/each_binding.rb +113 -113
  51. data/lib/volt/page/bindings/event_binding.rb +38 -34
  52. data/lib/volt/page/bindings/if_binding.rb +56 -54
  53. data/lib/volt/page/bindings/template_binding/grouped_controllers.rb +24 -22
  54. data/lib/volt/page/bindings/template_binding.rb +182 -185
  55. data/lib/volt/page/channel.rb +79 -77
  56. data/lib/volt/page/channel_stub.rb +29 -27
  57. data/lib/volt/page/document.rb +6 -5
  58. data/lib/volt/page/document_events.rb +54 -52
  59. data/lib/volt/page/page.rb +139 -138
  60. data/lib/volt/page/string_template_renderer.rb +36 -36
  61. data/lib/volt/page/sub_context.rb +26 -25
  62. data/lib/volt/page/targets/attribute_section.rb +27 -25
  63. data/lib/volt/page/targets/attribute_target.rb +7 -6
  64. data/lib/volt/page/targets/base_section.rb +27 -26
  65. data/lib/volt/page/targets/binding_document/base_node.rb +3 -1
  66. data/lib/volt/page/targets/binding_document/component_node.rb +85 -82
  67. data/lib/volt/page/targets/binding_document/html_node.rb +11 -9
  68. data/lib/volt/page/targets/dom_section.rb +78 -77
  69. data/lib/volt/page/targets/dom_target.rb +8 -6
  70. data/lib/volt/page/targets/dom_template.rb +90 -88
  71. data/lib/volt/page/targets/helpers/comment_searchers.rb +51 -49
  72. data/lib/volt/page/tasks.rb +59 -57
  73. data/lib/volt/page/template_renderer.rb +17 -14
  74. data/lib/volt/page/url_tracker.rb +26 -24
  75. data/lib/volt/reactive/computation.rb +87 -88
  76. data/lib/volt/reactive/dependency.rb +30 -28
  77. data/lib/volt/reactive/eventable.rb +64 -62
  78. data/lib/volt/reactive/hash_dependency.rb +25 -23
  79. data/lib/volt/reactive/reactive_accessors.rb +34 -32
  80. data/lib/volt/reactive/reactive_array.rb +162 -162
  81. data/lib/volt/reactive/reactive_hash.rb +37 -35
  82. data/lib/volt/router/routes.rb +99 -101
  83. data/lib/volt/server/component_handler.rb +20 -21
  84. data/lib/volt/server/component_templates.rb +72 -70
  85. data/lib/volt/server/html_parser/attribute_scope.rb +109 -99
  86. data/lib/volt/server/html_parser/each_scope.rb +17 -16
  87. data/lib/volt/server/html_parser/if_view_scope.rb +51 -49
  88. data/lib/volt/server/html_parser/sandlebars_parser.rb +184 -177
  89. data/lib/volt/server/html_parser/textarea_scope.rb +24 -22
  90. data/lib/volt/server/html_parser/view_handler.rb +66 -65
  91. data/lib/volt/server/html_parser/view_parser.rb +23 -21
  92. data/lib/volt/server/html_parser/view_scope.rb +142 -141
  93. data/lib/volt/server/rack/asset_files.rb +81 -79
  94. data/lib/volt/server/rack/component_code.rb +17 -15
  95. data/lib/volt/server/rack/component_html_renderer.rb +14 -12
  96. data/lib/volt/server/rack/component_paths.rb +72 -71
  97. data/lib/volt/server/rack/index_files.rb +36 -39
  98. data/lib/volt/server/rack/opal_files.rb +43 -41
  99. data/lib/volt/server/rack/source_map_server.rb +23 -21
  100. data/lib/volt/server/socket_connection_handler.rb +46 -45
  101. data/lib/volt/server/socket_connection_handler_stub.rb +21 -19
  102. data/lib/volt/server.rb +60 -58
  103. data/lib/volt/spec/setup.rb +3 -3
  104. data/lib/volt/tasks/dispatcher.rb +24 -23
  105. data/lib/volt/tasks/task_handler.rb +35 -33
  106. data/lib/volt/utils/ejson.rb +8 -6
  107. data/lib/volt/utils/generic_counting_pool.rb +33 -31
  108. data/lib/volt/utils/generic_pool.rb +73 -70
  109. data/lib/volt/utils/local_storage.rb +42 -38
  110. data/lib/volt/volt/environment.rb +1 -1
  111. data/lib/volt.rb +44 -42
  112. data/spec/apps/kitchen_sink/app/main/assets/css/todos.css +28 -0
  113. data/spec/apps/kitchen_sink/app/main/config/routes.rb +1 -0
  114. data/spec/apps/kitchen_sink/app/main/controllers/main_controller.rb +2 -2
  115. data/spec/apps/kitchen_sink/app/main/controllers/todos_controller.rb +17 -0
  116. data/spec/apps/kitchen_sink/app/main/views/main/main.html +1 -0
  117. data/spec/apps/kitchen_sink/app/main/views/todos/index.html +24 -0
  118. data/spec/apps/kitchen_sink/config.ru +1 -1
  119. data/spec/controllers/reactive_accessors_spec.rb +5 -5
  120. data/spec/extra_core/inflector_spec.rb +2 -2
  121. data/spec/integration/list_spec.rb +68 -0
  122. data/spec/models/model_spec.rb +57 -57
  123. data/spec/models/persistors/params_spec.rb +6 -6
  124. data/spec/models/persistors/store_spec.rb +7 -7
  125. data/spec/models/validations_spec.rb +3 -3
  126. data/spec/page/bindings/content_binding_spec.rb +7 -7
  127. data/spec/page/bindings/template_binding_spec.rb +4 -5
  128. data/spec/page/sub_context_spec.rb +2 -2
  129. data/spec/reactive/computation_spec.rb +10 -10
  130. data/spec/reactive/dependency_spec.rb +2 -2
  131. data/spec/reactive/eventable_spec.rb +4 -4
  132. data/spec/reactive/reactive_array_spec.rb +13 -13
  133. data/spec/router/routes_spec.rb +5 -5
  134. data/spec/server/html_parser/sandlebars_parser_spec.rb +9 -9
  135. data/spec/server/html_parser/view_parser_spec.rb +27 -27
  136. data/spec/server/rack/asset_files_spec.rb +5 -5
  137. data/spec/server/rack/component_paths_spec.rb +2 -2
  138. data/spec/tasks/live_query_spec.rb +2 -2
  139. data/spec/tasks/query_tasks.rb +1 -1
  140. data/spec/tasks/query_tracker_spec.rb +1 -1
  141. data/spec/templates/targets/binding_document/component_node_spec.rb +2 -2
  142. data/spec/utils/generic_counting_pool_spec.rb +2 -2
  143. data/spec/utils/generic_pool_spec.rb +2 -2
  144. data/templates/component/controllers/main_controller.rb +1 -1
  145. data/templates/model/model.rb.tt +2 -2
  146. data/templates/newgem/app/newgem/controllers/main_controller.rb.tt +2 -2
  147. data/templates/project/app/main/controllers/main_controller.rb +1 -1
  148. data/templates/project/config.ru +1 -1
  149. metadata +10 -3
  150. data/app/volt/assets/js/vertxbus.js +0 -216
@@ -1,232 +1,234 @@
1
1
  require 'volt/reactive/eventable'
2
2
 
3
- class ReactiveArray# < Array
4
- include Eventable
5
-
6
- def initialize(array=[])
7
- @array = array
8
- @array_deps = []
9
- @size_dep = Dependency.new
10
- @old_size = 0
11
- end
3
+ module Volt
4
+ class ReactiveArray
5
+ include Eventable
6
+
7
+ def initialize(array=[])
8
+ @array = array
9
+ @array_deps = []
10
+ @size_dep = Dependency.new
11
+ @old_size = 0
12
+ end
12
13
 
13
- # Forward any missing methods to the array
14
- def method_missing(method_name, *args, &block)
15
- @array.send(method_name, *args, &block)
16
- end
14
+ # Forward any missing methods to the array
15
+ def method_missing(method_name, *args, &block)
16
+ @array.send(method_name, *args, &block)
17
+ end
17
18
 
18
- def ==(*args)
19
- @array.==(*args)
20
- end
19
+ def ==(*args)
20
+ @array.==(*args)
21
+ end
21
22
 
22
- # At the moment, each just passes through.
23
- def each(&block)
24
- @array.each(&block)
25
- end
23
+ # At the moment, each just passes through.
24
+ def each(&block)
25
+ @array.each(&block)
26
+ end
26
27
 
27
- def count(&block)
28
- if block
29
- count = 0
30
- size.times do |index|
31
- if block.call(self[index]).true?
32
- count += 1
28
+ def count(&block)
29
+ if block
30
+ count = 0
31
+ size.times do |index|
32
+ if block.call(self[index]).true?
33
+ count += 1
34
+ end
33
35
  end
34
- end
35
-
36
- return count
37
- else
38
- return size
39
- end
40
- end
41
36
 
42
- def select
43
- result = []
44
- size.times do |index|
45
- val = self[index]
46
- if yield(val).true?
47
- result << val
37
+ return count
38
+ else
39
+ return size
48
40
  end
49
41
  end
50
42
 
51
- return result
52
- end
53
-
54
- def any?
55
- if block_given?
43
+ def select
44
+ result = []
56
45
  size.times do |index|
57
46
  val = self[index]
58
-
59
47
  if yield(val).true?
60
- return true
48
+ result << val
61
49
  end
62
50
  end
63
51
 
64
- return false
65
- else
66
- return @array.any?
52
+ return result
67
53
  end
68
- end
69
54
 
70
- def all?
71
- if block_given?
72
- size.times do |index|
73
- val = self[index]
55
+ def any?
56
+ if block_given?
57
+ size.times do |index|
58
+ val = self[index]
74
59
 
75
- if !yield(val).true?
76
- return false
60
+ if yield(val).true?
61
+ return true
62
+ end
77
63
  end
78
- end
79
64
 
80
- return true
81
- else
82
- return @array.all?
65
+ return false
66
+ else
67
+ return @array.any?
68
+ end
83
69
  end
84
- end
85
-
86
- # TODO: Handle a range
87
- def [](index)
88
- # Handle a negative index
89
- index = size + index if index < 0
90
-
91
- # Get or create the dependency
92
- dep = (@array_deps[index] ||= Dependency.new)
93
70
 
94
- # Track the dependency
95
- dep.depend
71
+ def all?
72
+ if block_given?
73
+ size.times do |index|
74
+ val = self[index]
96
75
 
97
- # Return the index
98
- return @array[index]
99
- end
76
+ if !yield(val).true?
77
+ return false
78
+ end
79
+ end
100
80
 
101
- def []=(index, value)
81
+ return true
82
+ else
83
+ return @array.all?
84
+ end
85
+ end
102
86
 
103
- # Assign the new value
104
- @array[index] = value
87
+ # TODO: Handle a range
88
+ def [](index)
89
+ # Handle a negative index
90
+ index = size + index if index < 0
105
91
 
106
- trigger_for_index!(index)
92
+ # Get or create the dependency
93
+ dep = (@array_deps[index] ||= Dependency.new)
107
94
 
108
- trigger_size_change!
109
- end
95
+ # Track the dependency
96
+ dep.depend
110
97
 
111
- def size
112
- @size_dep.depend
98
+ # Return the index
99
+ return @array[index]
100
+ end
113
101
 
114
- return @array.size
115
- end
116
- alias :length :size
102
+ def []=(index, value)
117
103
 
118
- def delete_at(index)
119
- # Handle a negative index
120
- index = size + index if index < 0
104
+ # Assign the new value
105
+ @array[index] = value
121
106
 
122
- model = @array.delete_at(index)
107
+ trigger_for_index!(index)
123
108
 
124
- # Remove the dependency for that cell, and #remove it
125
- index_deps = @array_deps.delete_at(index)
126
- index_deps.remove if index_deps
109
+ trigger_size_change!
110
+ end
127
111
 
128
- trigger_removed!(index)
112
+ def size
113
+ @size_dep.depend
129
114
 
130
- # Trigger a changed event for each element in the zone where the
131
- # delete would change
132
- index.upto(self.size+1) do |position|
133
- trigger_for_index!(position)
115
+ return @array.size
134
116
  end
135
117
 
136
- trigger_size_change!
118
+ alias :length :size
137
119
 
138
- @persistor.removed(model) if @persistor
120
+ def delete_at(index)
121
+ # Handle a negative index
122
+ index = size + index if index < 0
139
123
 
140
- return model
141
- end
124
+ model = @array.delete_at(index)
142
125
 
126
+ # Remove the dependency for that cell, and #remove it
127
+ index_deps = @array_deps.delete_at(index)
128
+ index_deps.remove if index_deps
143
129
 
144
- def delete(val)
145
- index = @array.index(val)
146
- if index
147
- self.delete_at(index)
148
- else
149
- # Sometimes the model isn't loaded at the right state yet, so we
150
- # just remove it from the persistor
151
- @persistor.removed(val) if @persistor
152
- end
153
- end
130
+ trigger_removed!(index)
154
131
 
155
- def clear
156
- old_size = @array.size
132
+ # Trigger a changed event for each element in the zone where the
133
+ # delete would change
134
+ index.upto(self.size+1) do |position|
135
+ trigger_for_index!(position)
136
+ end
137
+
138
+ trigger_size_change!
157
139
 
158
- deps = @array_deps
159
- @array_deps = []
140
+ @persistor.removed(model) if @persistor
160
141
 
161
- # Trigger remove for each cell
162
- old_size.times do |index|
163
- trigger_removed!(old_size - index - 1)
142
+ return model
164
143
  end
165
144
 
166
- # Trigger on each cell since we are clearing out the array
167
- if deps
168
- deps.each do |dep|
169
- dep.changed! if dep
145
+
146
+ def delete(val)
147
+ index = @array.index(val)
148
+ if index
149
+ self.delete_at(index)
150
+ else
151
+ # Sometimes the model isn't loaded at the right state yet, so we
152
+ # just remove it from the persistor
153
+ @persistor.removed(val) if @persistor
170
154
  end
171
155
  end
172
156
 
173
- # clear the array
174
- @array = []
175
- end
157
+ def clear
158
+ old_size = @array.size
176
159
 
177
- # alias :__old_append :<<
178
- def <<(value)
179
- result = (@array << value)
160
+ deps = @array_deps
161
+ @array_deps = []
180
162
 
181
- trigger_for_index!(self.size-1)
182
- trigger_added!(self.size-1)
183
- trigger_size_change!
163
+ # Trigger remove for each cell
164
+ old_size.times do |index|
165
+ trigger_removed!(old_size - index - 1)
166
+ end
184
167
 
185
- return result
186
- end
168
+ # Trigger on each cell since we are clearing out the array
169
+ if deps
170
+ deps.each do |dep|
171
+ dep.changed! if dep
172
+ end
173
+ end
187
174
 
175
+ # clear the array
176
+ @array = []
177
+ end
188
178
 
189
- def +(array)
190
- raise "not implemented yet"
191
- old_size = self.size
179
+ # alias :__old_append :<<
180
+ def <<(value)
181
+ result = (@array << value)
192
182
 
193
- # TODO: += is funky here, might need to make a .plus! method
194
- result = ReactiveArray.new(@array.dup + array)
183
+ trigger_for_index!(self.size-1)
184
+ trigger_added!(self.size-1)
185
+ trigger_size_change!
195
186
 
196
- old_size.upto(result.size-1) do |index|
197
- trigger_for_index!('changed', index)
198
- trigger_added!(old_size + index)
187
+ return result
199
188
  end
200
189
 
201
- trigger_size_change!
202
190
 
203
- return result
204
- end
191
+ def +(array)
192
+ raise "not implemented yet"
193
+ old_size = self.size
205
194
 
206
- def insert(index, *objects)
207
- result = @array.insert(index, *objects)
195
+ # TODO: += is funky here, might need to make a .plus! method
196
+ result = ReactiveArray.new(@array.dup + array)
208
197
 
209
- # All objects from index to the end have "changed"
210
- index.upto(result.size) do |index|
211
- trigger_for_index!(index)
212
- end
198
+ old_size.upto(result.size-1) do |index|
199
+ trigger_for_index!('changed', index)
200
+ trigger_added!(old_size + index)
201
+ end
202
+
203
+ trigger_size_change!
213
204
 
214
- objects.size.times do |count|
215
- trigger_added!(index+count)
205
+ return result
216
206
  end
217
207
 
218
- trigger_size_change!
208
+ def insert(index, *objects)
209
+ result = @array.insert(index, *objects)
219
210
 
220
- return result
221
- end
211
+ # All objects from index to the end have "changed"
212
+ index.upto(result.size) do |index|
213
+ trigger_for_index!(index)
214
+ end
222
215
 
216
+ objects.size.times do |count|
217
+ trigger_added!(index+count)
218
+ end
223
219
 
224
- def inspect
225
- "#<#{self.class.to_s}:#{object_id} #{@array.inspect}>"
226
- end
220
+ trigger_size_change!
221
+
222
+ return result
223
+ end
227
224
 
228
225
 
229
- private
226
+ def inspect
227
+ "#<#{self.class.to_s}:#{object_id} #{@array.inspect}>"
228
+ end
229
+
230
+
231
+ private
230
232
  # Check to see if the size has changed, trigger a change on size if it has
231
233
  def trigger_size_change!
232
234
  new_size = @array.size
@@ -251,7 +253,5 @@ class ReactiveArray# < Array
251
253
  def trigger_removed!(index)
252
254
  trigger!('removed', index)
253
255
  end
254
-
255
-
256
-
256
+ end
257
257
  end
@@ -1,49 +1,51 @@
1
1
  require 'volt/reactive/hash_dependency'
2
2
 
3
- class ReactiveHash
4
- def initialize(values={})
5
- @hash = values
6
- @deps = HashDependency.new
7
- @all_deps = Dependency.new
8
- end
3
+ module Volt
4
+ class ReactiveHash
5
+ def initialize(values={})
6
+ @hash = values
7
+ @deps = HashDependency.new
8
+ @all_deps = Dependency.new
9
+ end
9
10
 
10
- def ==(val)
11
- @all_deps.depend
12
- @hash == val
13
- end
11
+ def ==(val)
12
+ @all_deps.depend
13
+ @hash == val
14
+ end
14
15
 
15
- # TODO: We should finish off this class for reactivity
16
- def method_missing(method_name, *args, &block)
17
- @all_deps.depend
16
+ # TODO: We should finish off this class for reactivity
17
+ def method_missing(method_name, *args, &block)
18
+ @all_deps.depend
18
19
 
19
- return @hash.send(method_name, *args, &block)
20
- end
20
+ return @hash.send(method_name, *args, &block)
21
+ end
21
22
 
22
- def [](key)
23
- @deps.depend(key)
23
+ def [](key)
24
+ @deps.depend(key)
24
25
 
25
- return @hash[key]
26
- end
26
+ return @hash[key]
27
+ end
27
28
 
28
- def []=(key, value)
29
- @deps.changed!(key)
30
- @all_deps.changed!
29
+ def []=(key, value)
30
+ @deps.changed!(key)
31
+ @all_deps.changed!
31
32
 
32
- @hash[key] = value
33
- end
33
+ @hash[key] = value
34
+ end
34
35
 
35
- def delete(key)
36
- @deps.delete(key)
37
- @hash.delete(key)
38
- end
36
+ def delete(key)
37
+ @deps.delete(key)
38
+ @hash.delete(key)
39
+ end
39
40
 
40
- def clear
41
- @hash.each_pair do |key,_|
42
- delete(key)
41
+ def clear
42
+ @hash.each_pair do |key, _|
43
+ delete(key)
44
+ end
43
45
  end
44
- end
45
46
 
46
- def inspect
47
- "#<ReactiveHash #{@hash.inspect}>"
47
+ def inspect
48
+ "#<ReactiveHash #{@hash.inspect}>"
49
+ end
48
50
  end
49
- end
51
+ end