volt 0.5.4 → 0.5.6
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/Readme.md +4 -0
- data/VERSION +1 -1
- data/app/volt/assets/css/notices.css.scss +1 -0
- data/app/volt/views/notices/index.html +1 -1
- data/lib/volt/models/model.rb +4 -55
- data/lib/volt/models/model_hash_behaviour.rb +66 -0
- data/lib/volt/models/url.rb +1 -0
- data/lib/volt/page/page.rb +3 -3
- data/lib/volt/page/targets/dom_section.rb +17 -13
- data/lib/volt/page/template_renderer.rb +4 -0
- data/lib/volt/reactive/reactive_array.rb +9 -1
- data/lib/volt/reactive/reactive_value.rb +0 -1
- data/lib/volt/router/routes.rb +1 -1
- data/spec/models/model_spec.rb +2 -2
- data/templates/newgem/app/newgem/controllers/index_controller.rb.tt +3 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b8a76f2d758ccc809b63fb8cb7433b1b6e11c54
|
4
|
+
data.tar.gz: 9ecc4f6a3333af52c492ac2079372beece3c773f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f82aa5ff02d08404d6c9ad387bbd60785190aa7aa5741f6e63ee5a5fd5e3b459def0928976db7b2a6ba24425b0b696848a06e0b788679efa5e9ff24123c61ce8
|
7
|
+
data.tar.gz: 82012fceb2f955f0a0627f16b1d96353fd2e55a7a8f2ccf577a63e407b476d85d42f0783994108cadb6d63bb45d2661d2736fe9ade7ad651e8415e798e46730e
|
data/Readme.md
CHANGED
@@ -668,3 +668,7 @@ Controllers provide a .channel method, that you can use to get the status of the
|
|
668
668
|
| retry_count | the number of reconnection attempts that have been made without a successful connection |
|
669
669
|
| reconnect_interval | the time until the next reconnection attempt (in seconds) |
|
670
670
|
|
671
|
+
|
672
|
+
## Accessing DOM section in a controller
|
673
|
+
|
674
|
+
TODO
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.6
|
data/lib/volt/models/model.rb
CHANGED
@@ -2,6 +2,7 @@ require 'volt/models/model_wrapper'
|
|
2
2
|
require 'volt/models/array_model'
|
3
3
|
require 'volt/models/model_helpers'
|
4
4
|
require 'volt/reactive/object_tracking'
|
5
|
+
require 'volt/models/model_hash_behaviour'
|
5
6
|
|
6
7
|
class NilMethodCall < NoMethodError
|
7
8
|
def true?
|
@@ -18,22 +19,11 @@ class Model
|
|
18
19
|
include ModelWrapper
|
19
20
|
include ObjectTracking
|
20
21
|
include ModelHelpers
|
22
|
+
include ModelHashBehaviour
|
21
23
|
|
22
24
|
attr_accessor :attributes
|
23
25
|
attr_reader :parent, :path, :persistor, :options
|
24
26
|
|
25
|
-
def nil?
|
26
|
-
attributes.nil?
|
27
|
-
end
|
28
|
-
|
29
|
-
def false?
|
30
|
-
attributes.false?
|
31
|
-
end
|
32
|
-
|
33
|
-
def true?
|
34
|
-
attributes.true?
|
35
|
-
end
|
36
|
-
|
37
27
|
def initialize(attributes={}, options={})
|
38
28
|
@options = options
|
39
29
|
@parent = options[:parent]
|
@@ -72,32 +62,6 @@ class Model
|
|
72
62
|
@persistor.event_removed(event, no_more_events) if @persistor
|
73
63
|
end
|
74
64
|
|
75
|
-
|
76
|
-
tag_method(:delete) do
|
77
|
-
destructive!
|
78
|
-
end
|
79
|
-
def delete(*args)
|
80
|
-
__clear_element(args[0])
|
81
|
-
attributes.delete(*args)
|
82
|
-
trigger_by_attribute!('changed', args[0])
|
83
|
-
|
84
|
-
@persistor.removed(args[0]) if @persistor
|
85
|
-
end
|
86
|
-
|
87
|
-
tag_method(:clear) do
|
88
|
-
destructive!
|
89
|
-
end
|
90
|
-
def clear
|
91
|
-
attributes.each_pair do |key,value|
|
92
|
-
__clear_element(key)
|
93
|
-
end
|
94
|
-
|
95
|
-
attributes.clear
|
96
|
-
trigger!('changed')
|
97
|
-
|
98
|
-
@persistor.removed(nil) if @persistor
|
99
|
-
end
|
100
|
-
|
101
65
|
tag_all_methods do
|
102
66
|
pass_reactive! do |method_name|
|
103
67
|
method_name[0] == '_' && method_name[-1] == '='
|
@@ -235,27 +199,12 @@ class Model
|
|
235
199
|
# Add the new item
|
236
200
|
result << value
|
237
201
|
|
238
|
-
return
|
202
|
+
return nil
|
239
203
|
end
|
240
204
|
|
241
205
|
def inspect
|
242
206
|
"<#{self.class.to_s} #{attributes.inspect}>"
|
243
|
-
end
|
244
|
-
|
245
|
-
def [](val)
|
246
|
-
raise "Models do not support hash style lookup. Hashes inserted into other models are converted to models, see https://github.com/voltrb/volt#automatic-model-conversion"
|
247
|
-
end
|
248
|
-
|
249
|
-
# Convert the model to a hash all of the way down.
|
250
|
-
def to_h
|
251
|
-
hash = {}
|
252
|
-
attributes.each_pair do |key, value|
|
253
|
-
hash[key] = deep_unwrap(value)
|
254
|
-
end
|
255
|
-
|
256
|
-
return hash
|
257
|
-
end
|
258
|
-
|
207
|
+
end
|
259
208
|
|
260
209
|
private
|
261
210
|
# Clear the previous value and assign a new one
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Contains all of the methods on a model that make it behave like a hash.
|
2
|
+
# Moving this into a module cleans up the main Model class for things that
|
3
|
+
# make it behave like a model.
|
4
|
+
module ModelHashBehaviour
|
5
|
+
def self.included(base)
|
6
|
+
# In modules, since we need to tag on the main class, we setup the
|
7
|
+
# tags with included.
|
8
|
+
base.tag_method(:delete) do
|
9
|
+
destructive!
|
10
|
+
end
|
11
|
+
|
12
|
+
base.tag_method(:clear) do
|
13
|
+
destructive!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def nil?
|
19
|
+
attributes.nil?
|
20
|
+
end
|
21
|
+
|
22
|
+
def false?
|
23
|
+
attributes.false?
|
24
|
+
end
|
25
|
+
|
26
|
+
def true?
|
27
|
+
attributes.true?
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete(*args)
|
31
|
+
__clear_element(args[0])
|
32
|
+
attributes.delete(*args)
|
33
|
+
trigger_by_attribute!('changed', args[0])
|
34
|
+
|
35
|
+
@persistor.removed(args[0]) if @persistor
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def clear
|
40
|
+
attributes.each_pair do |key,value|
|
41
|
+
__clear_element(key)
|
42
|
+
end
|
43
|
+
|
44
|
+
attributes.clear
|
45
|
+
trigger!('changed')
|
46
|
+
|
47
|
+
@persistor.removed(nil) if @persistor
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# Convert the model to a hash all of the way down.
|
52
|
+
def to_h
|
53
|
+
hash = {}
|
54
|
+
attributes.each_pair do |key, value|
|
55
|
+
hash[key] = deep_unwrap(value)
|
56
|
+
end
|
57
|
+
|
58
|
+
return hash
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def [](val)
|
63
|
+
raise "Models do not support hash style lookup. Hashes inserted into other models are converted to models, see https://github.com/voltrb/volt#automatic-model-conversion"
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/lib/volt/models/url.rb
CHANGED
data/lib/volt/page/page.rb
CHANGED
@@ -32,7 +32,7 @@ require 'volt/page/draw_cycle'
|
|
32
32
|
require 'volt/page/tasks'
|
33
33
|
|
34
34
|
class Page
|
35
|
-
attr_reader :url, :params, :page, :store, :flash, :templates, :routes, :draw_cycle
|
35
|
+
attr_reader :url, :params, :page, :store, :flash, :templates, :routes, :draw_cycle, :events
|
36
36
|
|
37
37
|
def initialize
|
38
38
|
|
@@ -80,10 +80,10 @@ class Page
|
|
80
80
|
return if url.blank?
|
81
81
|
|
82
82
|
# Normalize url
|
83
|
-
Benchmark.bm(1) do
|
83
|
+
# Benchmark.bm(1) do
|
84
84
|
host = `document.location.host`
|
85
85
|
@url.parse("http://#{host}" + url)
|
86
|
-
end
|
86
|
+
# end
|
87
87
|
|
88
88
|
# Clear the flash
|
89
89
|
flash.clear
|
@@ -64,6 +64,12 @@ class DomSection < BaseSection
|
|
64
64
|
}
|
65
65
|
end
|
66
66
|
|
67
|
+
# Returns the nearest DOM node that contains all of the section.
|
68
|
+
def container_node
|
69
|
+
range = self.range()
|
70
|
+
return `range.commonAncestorContainer`
|
71
|
+
end
|
72
|
+
|
67
73
|
# Takes in our html and bindings, and rezero's the comment names, and the
|
68
74
|
# bindings. Returns an updated bindings hash
|
69
75
|
def set_content_and_rezero_bindings(html, bindings)
|
@@ -133,21 +139,19 @@ class DomSection < BaseSection
|
|
133
139
|
return new_bindings
|
134
140
|
end
|
135
141
|
|
136
|
-
|
137
|
-
|
138
|
-
def range
|
139
|
-
return @range if @range
|
142
|
+
def range
|
143
|
+
return @range if @range
|
140
144
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
145
|
+
range = nil
|
146
|
+
%x{
|
147
|
+
range = document.createRange();
|
148
|
+
range.setStartAfter(this.start_node);
|
149
|
+
range.setEndBefore(this.end_node);
|
150
|
+
}
|
147
151
|
|
148
|
-
|
152
|
+
@range = range
|
149
153
|
|
150
|
-
|
151
|
-
|
154
|
+
return range
|
155
|
+
end
|
152
156
|
|
153
157
|
end
|
@@ -17,6 +17,14 @@ class ReactiveArray# < Array
|
|
17
17
|
@array.==(*args)
|
18
18
|
end
|
19
19
|
|
20
|
+
tag_method(:each) do
|
21
|
+
destructive!
|
22
|
+
end
|
23
|
+
# At the moment, each just passes through.
|
24
|
+
def each(&block)
|
25
|
+
@array.each(&block)
|
26
|
+
end
|
27
|
+
|
20
28
|
tag_method(:[]=) do
|
21
29
|
pass_reactive!
|
22
30
|
end
|
@@ -209,7 +217,7 @@ class ReactiveArray# < Array
|
|
209
217
|
|
210
218
|
result
|
211
219
|
end
|
212
|
-
end
|
220
|
+
end
|
213
221
|
|
214
222
|
def inspect
|
215
223
|
"#<#{self.class.to_s} #{@array.inspect}>"
|
@@ -92,7 +92,6 @@ class ReactiveValue < BasicObject
|
|
92
92
|
return current_obj.__send__(method_name, *pass_args, &block)
|
93
93
|
end
|
94
94
|
|
95
|
-
@block_reactives = []
|
96
95
|
result = @reactive_manager.with_and_options(args) do |val, in_args|
|
97
96
|
# Unwrap arguments if the method doesn't want reactive values
|
98
97
|
# TODO: Should cache the lookup on pass_reactive
|
data/lib/volt/router/routes.rb
CHANGED
data/spec/models/model_spec.rb
CHANGED
@@ -450,8 +450,8 @@ describe Model do
|
|
450
450
|
all_items = a._items.to_a.cur
|
451
451
|
|
452
452
|
a = [
|
453
|
-
{:_name=>"Test1", :_other=>{:_time=>"Now"}},
|
454
|
-
{:_name=>"Test2", :_other=>{:_time=>"Later"}}
|
453
|
+
{:_name => "Test1", :_other => {:_time => "Now"}},
|
454
|
+
{:_name => "Test2", :_other => {:_time => "Later"}}
|
455
455
|
]
|
456
456
|
expect(all_items).to eq(a)
|
457
457
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: volt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Stout
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -354,6 +354,7 @@ files:
|
|
354
354
|
- lib/volt/models.rb
|
355
355
|
- lib/volt/models/array_model.rb
|
356
356
|
- lib/volt/models/model.rb
|
357
|
+
- lib/volt/models/model_hash_behaviour.rb
|
357
358
|
- lib/volt/models/model_helpers.rb
|
358
359
|
- lib/volt/models/model_wrapper.rb
|
359
360
|
- lib/volt/models/persistors/array_store.rb
|