volt 0.8.15 → 0.8.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +11 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +1 -1
- data/Guardfile +2 -3
- data/Rakefile +1 -4
- data/VERSION +1 -1
- data/app/volt/controllers/notices_controller.rb +1 -1
- data/app/volt/tasks/live_query/data_store.rb +7 -7
- data/app/volt/tasks/live_query/live_query.rb +7 -9
- data/app/volt/tasks/live_query/live_query_pool.rb +13 -12
- data/app/volt/tasks/live_query/query_tracker.rb +4 -5
- data/app/volt/tasks/query_tasks.rb +9 -11
- data/app/volt/tasks/store_tasks.rb +4 -4
- data/app/volt/tasks/user_tasks.rb +1 -1
- data/bin/volt +2 -2
- data/lib/volt.rb +3 -7
- data/lib/volt/assets/test.rb +1 -2
- data/lib/volt/benchmark/benchmark.rb +3 -3
- data/lib/volt/boot.rb +1 -1
- data/lib/volt/cli.rb +18 -18
- data/lib/volt/cli/asset_compile.rb +8 -10
- data/lib/volt/cli/generate.rb +9 -11
- data/lib/volt/cli/new_gem.rb +51 -51
- data/lib/volt/config.rb +2 -3
- data/lib/volt/console.rb +1 -1
- data/lib/volt/controllers/model_controller.rb +6 -6
- data/lib/volt/data_stores/data_store.rb +1 -1
- data/lib/volt/data_stores/mongo_driver.rb +1 -1
- data/lib/volt/extra_core/array.rb +2 -2
- data/lib/volt/extra_core/blank.rb +1 -2
- data/lib/volt/extra_core/extra_core.rb +1 -1
- data/lib/volt/extra_core/inflector/methods.rb +0 -1
- data/lib/volt/extra_core/logger.rb +13 -7
- data/lib/volt/extra_core/numeric.rb +1 -1
- data/lib/volt/extra_core/string.rb +7 -7
- data/lib/volt/extra_core/stringify_keys.rb +5 -5
- data/lib/volt/models.rb +2 -2
- data/lib/volt/models/array_model.rb +18 -19
- data/lib/volt/models/cursor.rb +0 -1
- data/lib/volt/models/model.rb +17 -35
- data/lib/volt/models/model_hash_behaviour.rb +0 -2
- data/lib/volt/models/model_state.rb +1 -1
- data/lib/volt/models/model_wrapper.rb +1 -1
- data/lib/volt/models/persistors/array_store.rb +26 -13
- data/lib/volt/models/persistors/base.rb +1 -1
- data/lib/volt/models/persistors/flash.rb +2 -2
- data/lib/volt/models/persistors/local_store.rb +2 -3
- data/lib/volt/models/persistors/model_store.rb +7 -6
- data/lib/volt/models/persistors/params.rb +2 -2
- data/lib/volt/models/persistors/query/query_listener.rb +2 -0
- data/lib/volt/models/persistors/query/query_listener_pool.rb +1 -1
- data/lib/volt/models/persistors/store.rb +1 -2
- data/lib/volt/models/persistors/store_state.rb +2 -3
- data/lib/volt/models/url.rb +17 -16
- data/lib/volt/models/validations.rb +11 -14
- data/lib/volt/models/validators/length_validator.rb +3 -3
- data/lib/volt/models/validators/presence_validator.rb +2 -2
- data/lib/volt/page/bindings/attribute_binding.rb +2 -3
- data/lib/volt/page/bindings/base_binding.rb +1 -1
- data/lib/volt/page/bindings/each_binding.rb +8 -9
- data/lib/volt/page/bindings/event_binding.rb +2 -3
- data/lib/volt/page/bindings/template_binding.rb +8 -7
- data/lib/volt/page/bindings/template_binding/grouped_controllers.rb +2 -1
- data/lib/volt/page/channel.rb +10 -10
- data/lib/volt/page/channel_stub.rb +1 -1
- data/lib/volt/page/document.rb +0 -1
- data/lib/volt/page/document_events.rb +4 -4
- data/lib/volt/page/page.rb +26 -19
- data/lib/volt/page/string_template_renderer.rb +2 -2
- data/lib/volt/page/sub_context.rb +10 -4
- data/lib/volt/page/targets/attribute_section.rb +1 -1
- data/lib/volt/page/targets/attribute_target.rb +1 -2
- data/lib/volt/page/targets/base_section.rb +4 -4
- data/lib/volt/page/targets/binding_document/base_node.rb +0 -1
- data/lib/volt/page/targets/binding_document/component_node.rb +4 -5
- data/lib/volt/page/targets/dom_section.rb +21 -22
- data/lib/volt/page/targets/dom_target.rb +1 -1
- data/lib/volt/page/targets/dom_template.rb +11 -12
- data/lib/volt/page/targets/helpers/comment_searchers.rb +7 -8
- data/lib/volt/page/tasks.rb +0 -1
- data/lib/volt/page/template_renderer.rb +1 -1
- data/lib/volt/page/url_tracker.rb +3 -3
- data/lib/volt/reactive/computation.rb +5 -11
- data/lib/volt/reactive/dependency.rb +1 -3
- data/lib/volt/reactive/eventable.rb +17 -4
- data/lib/volt/reactive/hash_dependency.rb +1 -0
- data/lib/volt/reactive/reactive_accessors.rb +0 -1
- data/lib/volt/reactive/reactive_array.rb +20 -25
- data/lib/volt/reactive/reactive_hash.rb +3 -3
- data/lib/volt/router/routes.rb +11 -13
- data/lib/volt/server.rb +17 -17
- data/lib/volt/server/component_handler.rb +2 -2
- data/lib/volt/server/component_templates.rb +8 -8
- data/lib/volt/server/html_parser/attribute_scope.rb +9 -10
- data/lib/volt/server/html_parser/if_view_scope.rb +2 -2
- data/lib/volt/server/html_parser/sandlebars_parser.rb +14 -14
- data/lib/volt/server/html_parser/textarea_scope.rb +1 -2
- data/lib/volt/server/html_parser/view_handler.rb +1 -1
- data/lib/volt/server/html_parser/view_parser.rb +1 -1
- data/lib/volt/server/html_parser/view_scope.rb +10 -10
- data/lib/volt/server/rack/asset_files.rb +15 -16
- data/lib/volt/server/rack/component_code.rb +2 -2
- data/lib/volt/server/rack/component_html_renderer.rb +0 -1
- data/lib/volt/server/rack/component_paths.rb +13 -10
- data/lib/volt/server/rack/index_files.rb +4 -4
- data/lib/volt/server/rack/opal_files.rb +4 -5
- data/lib/volt/server/rack/source_map_server.rb +3 -3
- data/lib/volt/server/socket_connection_handler.rb +3 -4
- data/lib/volt/server/socket_connection_handler_stub.rb +1 -1
- data/lib/volt/spec/setup.rb +3 -3
- data/lib/volt/store/mongo.rb +2 -2
- data/lib/volt/tasks/task_handler.rb +3 -3
- data/lib/volt/utils/generic_counting_pool.rb +2 -2
- data/lib/volt/utils/generic_pool.rb +7 -8
- data/lib/volt/utils/local_storage.rb +4 -4
- data/lib/volt/volt/environment.rb +1 -1
- data/spec/apps/file_loading/app/shared/config/dependencies.rb +1 -1
- data/spec/apps/kitchen_sink/Gemfile +0 -2
- data/spec/apps/kitchen_sink/app/main/config/routes.rb +5 -5
- data/spec/apps/kitchen_sink/app/main/controllers/main_controller.rb +7 -6
- data/spec/apps/kitchen_sink/app/main/controllers/todos_controller.rb +3 -4
- data/spec/controllers/reactive_accessors_spec.rb +4 -4
- data/spec/extra_core/inflector_spec.rb +1 -1
- data/spec/extra_core/string_transformation_test_cases.rb +23 -24
- data/spec/extra_core/string_transformations_spec.rb +11 -12
- data/spec/integration/bindings_spec.rb +15 -15
- data/spec/integration/list_spec.rb +12 -13
- data/spec/integration/templates_spec.rb +3 -3
- data/spec/models/model_spec.rb +74 -80
- data/spec/models/persistors/params_spec.rb +2 -2
- data/spec/models/persistors/store_spec.rb +4 -4
- data/spec/models/validations_spec.rb +14 -23
- data/spec/page/bindings/content_binding_spec.rb +7 -8
- data/spec/page/bindings/template_binding_spec.rb +22 -24
- data/spec/page/sub_context_spec.rb +2 -2
- data/spec/reactive/computation_spec.rb +3 -3
- data/spec/reactive/reactive_array_spec.rb +12 -12
- data/spec/router/routes_spec.rb +45 -48
- data/spec/server/html_parser/sandlebars_parser_spec.rb +42 -42
- data/spec/server/html_parser/view_parser_spec.rb +132 -153
- data/spec/server/rack/asset_files_spec.rb +9 -8
- data/spec/server/rack/component_paths_spec.rb +5 -5
- data/spec/server/rack/rack_requests_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -1
- data/spec/tasks/live_query_spec.rb +4 -5
- data/spec/tasks/query_tasks.rb +2 -4
- data/spec/tasks/query_tracker_spec.rb +29 -29
- data/spec/templates/targets/binding_document/component_node_spec.rb +1 -1
- data/spec/utils/generic_counting_pool_spec.rb +4 -4
- data/spec/utils/generic_pool_spec.rb +12 -12
- data/templates/component/config/routes.rb +2 -2
- data/templates/component/controllers/main_controller.rb +7 -6
- data/templates/newgem/app/newgem/config/dependencies.rb +1 -1
- data/templates/newgem/app/newgem/config/routes.rb +1 -1
- data/templates/project/app/main/config/routes.rb +2 -2
- data/templates/project/app/main/controllers/main_controller.rb +7 -6
- data/templates/project/spec/sample_spec.rb +2 -2
- data/volt.gemspec +32 -33
- metadata +3 -4
- data/lib/volt/extra_core/log.rb +0 -56
- data/lib/volt/extra_core/try.rb +0 -31
|
@@ -9,14 +9,14 @@ module Volt
|
|
|
9
9
|
|
|
10
10
|
def changed(attribute_name)
|
|
11
11
|
if RUBY_PLATFORM == 'opal'
|
|
12
|
-
|
|
12
|
+
`
|
|
13
13
|
if (window.setTimeout && this.$run_update.bind) {
|
|
14
14
|
if (window.paramsUpdateTimer) {
|
|
15
15
|
clearTimeout(window.paramsUpdateTimer);
|
|
16
16
|
}
|
|
17
17
|
window.paramsUpdateTimer = setTimeout(this.$run_update.bind(this), 0);
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
`
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -8,7 +8,7 @@ module Volt
|
|
|
8
8
|
# single query at once. Data updates will only be sent once as well.
|
|
9
9
|
class QueryListenerPool < GenericPool
|
|
10
10
|
def print
|
|
11
|
-
puts
|
|
11
|
+
puts '--- Running Queries ---'
|
|
12
12
|
|
|
13
13
|
@pool.each_pair do |table, query_hash|
|
|
14
14
|
query_hash.keys.each do |query|
|
|
@@ -4,10 +4,9 @@ require 'volt/models/persistors/model_identity_map'
|
|
|
4
4
|
module Volt
|
|
5
5
|
module Persistors
|
|
6
6
|
class Store < Base
|
|
7
|
-
|
|
8
7
|
@@identity_map = ModelIdentityMap.new
|
|
9
8
|
|
|
10
|
-
def initialize(model, tasks=nil)
|
|
9
|
+
def initialize(model, tasks = nil)
|
|
11
10
|
@tasks = tasks
|
|
12
11
|
@model = model
|
|
13
12
|
|
|
@@ -2,9 +2,8 @@ module Volt
|
|
|
2
2
|
module Persistors
|
|
3
3
|
# StoreState provides method for a store to track its loading state.
|
|
4
4
|
module StoreState
|
|
5
|
-
|
|
6
5
|
# Called when a collection loads
|
|
7
|
-
def loaded(initial_state=nil)
|
|
6
|
+
def loaded(initial_state = nil)
|
|
8
7
|
change_state_to(initial_state || :not_loaded)
|
|
9
8
|
end
|
|
10
9
|
|
|
@@ -15,7 +14,7 @@ module Volt
|
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
# Called from the QueryListener when the data is loaded
|
|
18
|
-
def change_state_to(new_state, skip_trigger=false)
|
|
17
|
+
def change_state_to(new_state, skip_trigger = false)
|
|
19
18
|
old_state = @state
|
|
20
19
|
@state = new_state
|
|
21
20
|
|
data/lib/volt/models/url.rb
CHANGED
|
@@ -54,7 +54,7 @@ module Volt
|
|
|
54
54
|
|
|
55
55
|
scroll
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
true
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
# Full url rebuilds the url from it's constituent parts
|
|
@@ -78,15 +78,15 @@ module Volt
|
|
|
78
78
|
|
|
79
79
|
if query_parts.size > 0
|
|
80
80
|
self.query = query_parts.join('&')
|
|
81
|
-
new_url += '?' +
|
|
81
|
+
new_url += '?' + query
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
# Add fragment
|
|
86
|
-
frag =
|
|
86
|
+
frag = fragment
|
|
87
87
|
new_url += '#' + frag if frag.present?
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
new_url
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
# Called when the state has changed and the url in the
|
|
@@ -94,24 +94,24 @@ module Volt
|
|
|
94
94
|
# Called when an attribute changes to update the url
|
|
95
95
|
def update!
|
|
96
96
|
if Volt.client?
|
|
97
|
-
new_url = full_url
|
|
97
|
+
new_url = full_url
|
|
98
98
|
|
|
99
99
|
# Push the new url if pushState is supported
|
|
100
100
|
# TODO: add fragment fallback
|
|
101
|
-
|
|
101
|
+
`
|
|
102
102
|
if (document.location.href != new_url && history && history.pushState) {
|
|
103
103
|
history.pushState(null, null, new_url);
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
`
|
|
106
106
|
end
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
def scroll
|
|
110
110
|
if Volt.client?
|
|
111
|
-
frag =
|
|
111
|
+
frag = fragment
|
|
112
112
|
if frag
|
|
113
113
|
# Scroll to anchor via http://www.w3.org/html/wg/drafts/html/master/browsers.html#scroll-to-fragid
|
|
114
|
-
|
|
114
|
+
`
|
|
115
115
|
var anchor = $('#' + frag);
|
|
116
116
|
if (anchor.length == 0) {
|
|
117
117
|
anchor = $('*[name="' + frag + '"]:first');
|
|
@@ -120,7 +120,7 @@ module Volt
|
|
|
120
120
|
console.log('scroll to: ', anchor.offset().top);
|
|
121
121
|
$(document.body).scrollTop(anchor.offset().top);
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
`
|
|
124
124
|
else
|
|
125
125
|
# Scroll to the top by default
|
|
126
126
|
`$(document.body).scrollTop(0);`
|
|
@@ -129,6 +129,7 @@ module Volt
|
|
|
129
129
|
end
|
|
130
130
|
|
|
131
131
|
private
|
|
132
|
+
|
|
132
133
|
# Assigning the params is tricky since we don't want to trigger changed on
|
|
133
134
|
# any values that have not changed. So we first loop through all current
|
|
134
135
|
# url params, removing any not present in the params, while also removing
|
|
@@ -142,7 +143,7 @@ module Volt
|
|
|
142
143
|
new_params = @router.url_to_params(path)
|
|
143
144
|
|
|
144
145
|
if new_params == false
|
|
145
|
-
|
|
146
|
+
fail "no routes match path: #{path}"
|
|
146
147
|
end
|
|
147
148
|
|
|
148
149
|
query_hash.merge!(new_params)
|
|
@@ -193,7 +194,7 @@ module Volt
|
|
|
193
194
|
|
|
194
195
|
def query_hash
|
|
195
196
|
query_hash = {}
|
|
196
|
-
qury =
|
|
197
|
+
qury = query
|
|
197
198
|
if qury
|
|
198
199
|
qury.split('&').reject { |v| v == '' }.each do |part|
|
|
199
200
|
parts = part.split('=').reject { |v| v == '' }
|
|
@@ -206,7 +207,7 @@ module Volt
|
|
|
206
207
|
|
|
207
208
|
hash_part = query_hash
|
|
208
209
|
sections.each_with_index do |section, index|
|
|
209
|
-
if index == sections.size-1
|
|
210
|
+
if index == sections.size - 1
|
|
210
211
|
# Last part, assign the value
|
|
211
212
|
hash_part[section] = parts[1]
|
|
212
213
|
else
|
|
@@ -216,7 +217,7 @@ module Volt
|
|
|
216
217
|
end
|
|
217
218
|
end
|
|
218
219
|
|
|
219
|
-
|
|
220
|
+
query_hash
|
|
220
221
|
end
|
|
221
222
|
|
|
222
223
|
# Splits a key from a ?key=value&... parameter into its nested
|
|
@@ -240,7 +241,7 @@ module Volt
|
|
|
240
241
|
end.join('')
|
|
241
242
|
end
|
|
242
243
|
|
|
243
|
-
def nested_params_hash(params, path=[])
|
|
244
|
+
def nested_params_hash(params, path = [])
|
|
244
245
|
results = {}
|
|
245
246
|
|
|
246
247
|
params.each_pair do |key, value|
|
|
@@ -254,7 +255,7 @@ module Volt
|
|
|
254
255
|
end
|
|
255
256
|
end
|
|
256
257
|
|
|
257
|
-
|
|
258
|
+
results
|
|
258
259
|
end
|
|
259
260
|
end
|
|
260
261
|
end
|
|
@@ -11,9 +11,7 @@ module Volt
|
|
|
11
11
|
@validations[field_name] = options
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
@validations
|
|
16
|
-
end
|
|
14
|
+
attr_reader :validations
|
|
17
15
|
end
|
|
18
16
|
|
|
19
17
|
def self.included(base)
|
|
@@ -22,7 +20,7 @@ module Volt
|
|
|
22
20
|
|
|
23
21
|
# Once a field is ready, we can use include_in_errors! to start
|
|
24
22
|
# showing its errors.
|
|
25
|
-
def mark_field!(field_name, trigger_changed=true)
|
|
23
|
+
def mark_field!(field_name, trigger_changed = true)
|
|
26
24
|
marked_fields[field_name] = true
|
|
27
25
|
end
|
|
28
26
|
|
|
@@ -36,14 +34,14 @@ module Volt
|
|
|
36
34
|
|
|
37
35
|
# TODO: Errors is being called for any validation change. We should have errors return a
|
|
38
36
|
# hash like object that only calls the validation for each one.
|
|
39
|
-
def errors(marked_only=false)
|
|
37
|
+
def errors(marked_only = false)
|
|
40
38
|
errors = {}
|
|
41
39
|
|
|
42
40
|
validations = self.class.validations
|
|
43
41
|
|
|
44
42
|
if validations
|
|
45
43
|
# Merge into errors, combining any error arrays
|
|
46
|
-
merge =
|
|
44
|
+
merge = proc do |new_errors|
|
|
47
45
|
errors.merge!(new_errors) do |key, new_val, old_val|
|
|
48
46
|
new_val + old_val
|
|
49
47
|
end
|
|
@@ -64,27 +62,26 @@ module Volt
|
|
|
64
62
|
if klass
|
|
65
63
|
validate_with(merge, klass, field_name, args)
|
|
66
64
|
else
|
|
67
|
-
|
|
65
|
+
fail "validation type #{validation} is not specified."
|
|
68
66
|
end
|
|
69
67
|
end
|
|
70
68
|
end
|
|
71
69
|
end
|
|
72
70
|
|
|
73
|
-
|
|
71
|
+
errors
|
|
74
72
|
end
|
|
75
73
|
|
|
76
74
|
private
|
|
75
|
+
|
|
77
76
|
# calls the validate method on the class, passing the right arguments.
|
|
78
77
|
def validate_with(merge, klass, field_name, args)
|
|
79
|
-
|
|
78
|
+
merge.call(klass.validate(self, field_name, args))
|
|
80
79
|
end
|
|
81
80
|
|
|
82
81
|
def validation_class(validation, args)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
puts "Unable to find #{validation} validator"
|
|
87
|
-
end
|
|
82
|
+
Volt.const_get(:"#{validation.camelize}Validator")
|
|
83
|
+
rescue NameError => e
|
|
84
|
+
puts "Unable to find #{validation} validator"
|
|
88
85
|
end
|
|
89
86
|
end
|
|
90
87
|
end
|
|
@@ -11,11 +11,11 @@ module Volt
|
|
|
11
11
|
elsif args.is_a?(Hash)
|
|
12
12
|
min = args[:length] || args[:minimum]
|
|
13
13
|
max = args[:maximum]
|
|
14
|
-
|
|
14
|
+
fail 'length or minimum must be specified' unless min.is_a?(Fixnum)
|
|
15
15
|
|
|
16
16
|
message = args[:message]
|
|
17
17
|
else
|
|
18
|
-
|
|
18
|
+
fail 'The arguments to length must be a number or a hash'
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
if !value || value.size < min
|
|
@@ -24,7 +24,7 @@ module Volt
|
|
|
24
24
|
errors[field_name] = [message || "must be less than #{args} characters"]
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
errors
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
end
|
|
@@ -7,13 +7,13 @@ module Volt
|
|
|
7
7
|
if args.is_a?(Hash) && args[:message]
|
|
8
8
|
message = args[:message]
|
|
9
9
|
else
|
|
10
|
-
message =
|
|
10
|
+
message = 'must be specified'
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
errors[field_name] = [message]
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
errors
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
end
|
|
@@ -14,7 +14,6 @@ module Volt
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def setup
|
|
17
|
-
|
|
18
17
|
# Listen for changes
|
|
19
18
|
@computation = -> do
|
|
20
19
|
begin
|
|
@@ -39,7 +38,7 @@ module Volt
|
|
|
39
38
|
end
|
|
40
39
|
end
|
|
41
40
|
|
|
42
|
-
def changed(event=nil)
|
|
41
|
+
def changed(event = nil)
|
|
43
42
|
case @attribute_name
|
|
44
43
|
when 'value'
|
|
45
44
|
current_value = element.value
|
|
@@ -134,7 +133,7 @@ module Volt
|
|
|
134
133
|
end
|
|
135
134
|
|
|
136
135
|
def remove_anchors
|
|
137
|
-
|
|
136
|
+
fail 'attribute bindings do not have anchors, can not remove them'
|
|
138
137
|
end
|
|
139
138
|
end
|
|
140
139
|
end
|
|
@@ -45,10 +45,10 @@ module Volt
|
|
|
45
45
|
values_size = values.size
|
|
46
46
|
|
|
47
47
|
# Start over, re-create all nodes
|
|
48
|
-
(templates_size-1).downto(0) do |index|
|
|
48
|
+
(templates_size - 1).downto(0) do |index|
|
|
49
49
|
item_removed(index)
|
|
50
50
|
end
|
|
51
|
-
0.upto(values_size-1) do |index|
|
|
51
|
+
0.upto(values_size - 1) do |index|
|
|
52
52
|
item_added(index)
|
|
53
53
|
end
|
|
54
54
|
end
|
|
@@ -80,19 +80,19 @@ module Volt
|
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
# TODORW: :parent => @value may change
|
|
83
|
-
item_context = SubContext.new({:
|
|
84
|
-
item_context.locals[@item_name.to_sym] =
|
|
83
|
+
item_context = SubContext.new({ _index_value: position, parent: @value }, @context)
|
|
84
|
+
item_context.locals[@item_name.to_sym] = proc { @value[item_context.locals[:_index_value]] }
|
|
85
85
|
|
|
86
86
|
position_dependency = Dependency.new
|
|
87
87
|
item_context.locals[:index_dependency] = position_dependency
|
|
88
88
|
|
|
89
89
|
# Get and set index
|
|
90
|
-
item_context.locals[:index=] =
|
|
90
|
+
item_context.locals[:index=] = proc do |val|
|
|
91
91
|
position_dependency.changed!
|
|
92
92
|
item_context.locals[:_index_value] = val
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
item_context.locals[:index] =
|
|
95
|
+
item_context.locals[:index] = proc do
|
|
96
96
|
position_dependency.depend
|
|
97
97
|
item_context.locals[:_index_value]
|
|
98
98
|
end
|
|
@@ -108,7 +108,7 @@ module Volt
|
|
|
108
108
|
def update_indexes_after(start_index)
|
|
109
109
|
size = @templates.size
|
|
110
110
|
if size > 0
|
|
111
|
-
start_index.upto(size-1) do |index|
|
|
111
|
+
start_index.upto(size - 1) do |index|
|
|
112
112
|
@templates[index].context.locals[:index=].call(index)
|
|
113
113
|
end
|
|
114
114
|
end
|
|
@@ -118,10 +118,9 @@ module Volt
|
|
|
118
118
|
return [] if values.is_a?(Model) || values.is_a?(Exception)
|
|
119
119
|
values = values.attributes if values.respond_to?(:attributes)
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
values
|
|
122
122
|
end
|
|
123
123
|
|
|
124
|
-
|
|
125
124
|
# When this each_binding is removed, cleanup.
|
|
126
125
|
def remove
|
|
127
126
|
@computation.stop
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'volt/page/bindings/base_binding'
|
|
2
2
|
|
|
3
3
|
module Volt
|
|
4
|
-
# TODO: We need to figure out how we want to wrap JS events
|
|
4
|
+
# TODO: We need to figure out how we want to wrap JS events
|
|
5
5
|
class JSEvent
|
|
6
6
|
attr_reader :js_event
|
|
7
7
|
|
|
@@ -26,7 +26,6 @@ module Volt
|
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
|
|
30
29
|
class EventBinding < BaseBinding
|
|
31
30
|
attr_accessor :context, :binding_name
|
|
32
31
|
|
|
@@ -34,7 +33,7 @@ module Volt
|
|
|
34
33
|
super(page, target, context, binding_name)
|
|
35
34
|
@event_name = event_name
|
|
36
35
|
|
|
37
|
-
handler =
|
|
36
|
+
handler = proc do |js_event|
|
|
38
37
|
event = JSEvent.new(js_event)
|
|
39
38
|
event.prevent_default! if event_name == 'submit'
|
|
40
39
|
|
|
@@ -55,11 +55,11 @@ module Volt
|
|
|
55
55
|
# 2. controller - main
|
|
56
56
|
# 3. view - main
|
|
57
57
|
# 4. section - body
|
|
58
|
-
def path_for_template(lookup_path, force_section=nil)
|
|
58
|
+
def path_for_template(lookup_path, force_section = nil)
|
|
59
59
|
parts = lookup_path.split('/')
|
|
60
60
|
parts_size = parts.size
|
|
61
61
|
|
|
62
|
-
default_parts =
|
|
62
|
+
default_parts = %w(main main index body)
|
|
63
63
|
|
|
64
64
|
# When forcing a sub template, we can default the sub template section
|
|
65
65
|
default_parts[-1] = force_section if force_section
|
|
@@ -96,10 +96,10 @@ module Volt
|
|
|
96
96
|
end
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
[nil, nil]
|
|
100
100
|
end
|
|
101
101
|
|
|
102
|
-
def update(path, section_or_arguments=nil, options={})
|
|
102
|
+
def update(path, section_or_arguments = nil, options = {})
|
|
103
103
|
Computation.run_without_tracking do
|
|
104
104
|
# Remove existing template and call _removed
|
|
105
105
|
controller_send(:"#{@action}_removed") if @action && @controller
|
|
@@ -144,7 +144,7 @@ module Volt
|
|
|
144
144
|
# In the browser, we want to keep a grouped controller around during a single run
|
|
145
145
|
# of the event loop. To make that happen, we clear it on the next tick.
|
|
146
146
|
`setImmediate(function() {`
|
|
147
|
-
|
|
147
|
+
clear_grouped_controller
|
|
148
148
|
`});`
|
|
149
149
|
else
|
|
150
150
|
# For the backend, clear it immediately
|
|
@@ -161,7 +161,7 @@ module Volt
|
|
|
161
161
|
|
|
162
162
|
# The context for templates can be either a controller, or the original context.
|
|
163
163
|
def render_template(full_path, controller_path)
|
|
164
|
-
args = @arguments ? [SubContext.new(@arguments)] : []
|
|
164
|
+
args = @arguments ? [SubContext.new(@arguments, nil, true)] : []
|
|
165
165
|
|
|
166
166
|
@controller = nil
|
|
167
167
|
|
|
@@ -228,6 +228,7 @@ module Volt
|
|
|
228
228
|
end
|
|
229
229
|
|
|
230
230
|
private
|
|
231
|
+
|
|
231
232
|
# Sends the action to the controller if it exists
|
|
232
233
|
def controller_send(action_name)
|
|
233
234
|
if @controller.respond_to?(action_name)
|
|
@@ -260,7 +261,7 @@ module Volt
|
|
|
260
261
|
end
|
|
261
262
|
end
|
|
262
263
|
|
|
263
|
-
|
|
264
|
+
[obj, action]
|
|
264
265
|
end
|
|
265
266
|
end
|
|
266
267
|
end
|