volt 0.4.18 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.md +19 -4
- data/VERSION +1 -1
- data/app/volt/views/notices/index.html +1 -1
- data/lib/volt/models/model.rb +2 -0
- data/lib/volt/models/url.rb +8 -3
- data/lib/volt/page/channel.rb +21 -6
- data/lib/volt/page/page.rb +3 -2
- data/lib/volt/router/routes.rb +26 -6
- data/spec/models/model_spec.rb +3 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92e92321c95b13a37fe37cbb8f7a639a338a264c
|
4
|
+
data.tar.gz: af72a815e19b40a9d6fb57977afea8f8186ec7e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ae673bd0e6340fa5eed1529c18c45839b1f22008c31ad039ecf0aa38768495ee7e19888509207c94ab3b70494b0b5b03abaaae6a03c20ed2d9aa9fe42146604
|
7
|
+
data.tar.gz: d2529b34a6540cdeeffc846ea757ac8e77b6a0d90c52523cc0d4fe662f8c264ead47db1abefe130148d22f0b01ae0718b664a602e1f7d5dfcadd100b7a417f32
|
data/Readme.md
CHANGED
@@ -605,17 +605,15 @@ Routes take two arguments, a path, and a params hash. When a new url is loaded
|
|
605
605
|
|
606
606
|
When the params are changed, the url will be set to the path for the route that's params hash matches.
|
607
607
|
|
608
|
-
**Note: at the moment nested params do not work, but they are a planned feature**
|
609
|
-
|
610
608
|
Route path's can also contain variables similar to bindings.
|
611
609
|
|
612
610
|
```ruby
|
613
611
|
get "/todos/{_index}", _view: 'todos'
|
614
612
|
```
|
615
613
|
|
616
|
-
In the case above, if any url matches /todos/*, (where * is anything but a slash), it will be the active route. params._view would be set to 'todos', and params._index would be set to the value in the path.
|
614
|
+
In the case above, if any url matches /todos/*, (where * is anything but a slash), it will be the active route. ```params._view``` would be set to 'todos', and ```params._index``` would be set to the value in the path.
|
617
615
|
|
618
|
-
If params._view is 'todos' and params._index is not nil, the route would be matched.
|
616
|
+
If ```params._view``` is 'todos' and ```params._index``` is not nil, the route would be matched.
|
619
617
|
|
620
618
|
Routes are matched top to bottom in a routes file.
|
621
619
|
|
@@ -627,3 +625,20 @@ An in browser irb is in the works. We also have source maps support, but they a
|
|
627
625
|
|
628
626
|
They are disabled by default because they slow down page rendering because so many files are rendered. We're working with the opal and sprockets teams to make it so everything is still served in one big source maps file (which would show the files as they originated on disk)
|
629
627
|
|
628
|
+
|
629
|
+
## Channel
|
630
|
+
|
631
|
+
Controllers provide a .channel method, that you can use to get the status of the connection to the backend. Channel is provided in a ReactiveValue, and when the status changes, the changed events are triggered. It provides the following:
|
632
|
+
|
633
|
+
| method | description |
|
634
|
+
|-------------|-----------------------------------------------------------|
|
635
|
+
| connected? | true if it is connected to the backend |
|
636
|
+
| status | possible values: :opening, :open, :closed, :reconnecting |
|
637
|
+
| error | the error message for the last failed connection |
|
638
|
+
| retry_count | the number of reconnection attempts that have been made without a successful connection |
|
639
|
+
| reconnect_interval | the time until the next reconnection attempt (in seconds) |
|
640
|
+
|
641
|
+
|
642
|
+
## Notices
|
643
|
+
|
644
|
+
Volt ships with a component that provies notices for things like dropped backend connections, flash messages, etc...
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
@@ -2,7 +2,7 @@
|
|
2
2
|
{#if page._reloading}
|
3
3
|
<div class="notices alert alert-info">Reloading...</div>
|
4
4
|
{/}
|
5
|
-
{#if channel.
|
5
|
+
{#if channel.status == :closed}
|
6
6
|
<div class="notices alert alert-info">
|
7
7
|
Connection Lost... {channel.error}...
|
8
8
|
{#if channel.reconnect_interval} Reconnecting in {(channel.reconnect_interval / 1000.0).round} sec{/}
|
data/lib/volt/models/model.rb
CHANGED
data/lib/volt/models/url.rb
CHANGED
@@ -9,7 +9,6 @@ class URL
|
|
9
9
|
def initialize(router=nil)
|
10
10
|
@router = router
|
11
11
|
@params = Model.new({}, persistor: Persistors::Params)
|
12
|
-
#Params.new({}, 'params')
|
13
12
|
end
|
14
13
|
|
15
14
|
# Parse takes in a url and extracts each sections.
|
@@ -85,8 +84,13 @@ class URL
|
|
85
84
|
# Loop through the .params we already have assigned.
|
86
85
|
assign_from_old(@params, query_hash)
|
87
86
|
assign_new(@params, query_hash)
|
87
|
+
|
88
|
+
puts @params.inspect + '---'
|
88
89
|
end
|
89
90
|
|
91
|
+
# Loop through the old params, and overwrite any existing values,
|
92
|
+
# and delete the values that don't exist in the new params. Also
|
93
|
+
# remove any assigned to the new params (query_hash)
|
90
94
|
def assign_from_old(params, new_params)
|
91
95
|
queued_deletes = []
|
92
96
|
|
@@ -111,6 +115,7 @@ class URL
|
|
111
115
|
queued_deletes.each {|name| params.delete(name) }
|
112
116
|
end
|
113
117
|
|
118
|
+
# Assign any new params, which weren't in the old params.
|
114
119
|
def assign_new(params, new_params)
|
115
120
|
new_params.each_pair do |name, value|
|
116
121
|
if value.is_a?(Hash)
|
@@ -175,8 +180,8 @@ class URL
|
|
175
180
|
results = {}
|
176
181
|
|
177
182
|
params.each_pair do |key,value|
|
178
|
-
if value.
|
179
|
-
# TODO:
|
183
|
+
if value.respond_to?(:persistor) && value.persistor && value.persistor.is_a?(Persistors::Params)
|
184
|
+
# TODO: Should be a param
|
180
185
|
results.merge!(nested_params_hash(value, path + [key]))
|
181
186
|
else
|
182
187
|
results[query_key(path + [key])] = value
|
data/lib/volt/page/channel.rb
CHANGED
@@ -6,17 +6,27 @@ require 'json'
|
|
6
6
|
class Channel
|
7
7
|
include ReactiveTags
|
8
8
|
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :status, :error, :reconnect_interval
|
10
10
|
|
11
11
|
def initialize
|
12
12
|
@socket = nil
|
13
|
-
@
|
13
|
+
@status = :opening
|
14
|
+
@connected = false
|
14
15
|
@error = nil
|
16
|
+
@retry_count = 0
|
15
17
|
@queue = []
|
16
18
|
|
17
19
|
connect!
|
18
20
|
end
|
19
21
|
|
22
|
+
def connected?
|
23
|
+
@connected
|
24
|
+
end
|
25
|
+
|
26
|
+
def retry_count
|
27
|
+
@retry_count
|
28
|
+
end
|
29
|
+
|
20
30
|
def connect!
|
21
31
|
%x{
|
22
32
|
this.socket = new SockJS('/channel');
|
@@ -36,8 +46,10 @@ class Channel
|
|
36
46
|
end
|
37
47
|
|
38
48
|
def opened
|
39
|
-
@
|
49
|
+
@status = :open
|
50
|
+
@connected = true
|
40
51
|
@reconnect_interval = nil
|
52
|
+
@retry_count = 0
|
41
53
|
@queue.each do |message|
|
42
54
|
send_message(message)
|
43
55
|
end
|
@@ -47,7 +59,8 @@ class Channel
|
|
47
59
|
end
|
48
60
|
|
49
61
|
def closed(error)
|
50
|
-
@
|
62
|
+
@status = :closed
|
63
|
+
@connected = false
|
51
64
|
@error = `error.reason`
|
52
65
|
|
53
66
|
trigger!('closed')
|
@@ -57,8 +70,10 @@ class Channel
|
|
57
70
|
end
|
58
71
|
|
59
72
|
def reconnect!
|
73
|
+
@status = :reconnecting
|
60
74
|
@reconnect_interval ||= 0
|
61
75
|
@reconnect_interval += (2000 + rand(5000))
|
76
|
+
@retry_count += 1
|
62
77
|
|
63
78
|
# Trigger changed for reconnect interval
|
64
79
|
trigger!('changed')
|
@@ -82,7 +97,7 @@ class Channel
|
|
82
97
|
destructive!
|
83
98
|
end
|
84
99
|
def send_message(message)
|
85
|
-
if @
|
100
|
+
if @status != :open
|
86
101
|
@queue << message
|
87
102
|
else
|
88
103
|
# TODO: Temp: wrap message in an array, so we're sure its valid JSON
|
@@ -94,7 +109,7 @@ class Channel
|
|
94
109
|
end
|
95
110
|
|
96
111
|
def close!
|
97
|
-
@
|
112
|
+
@status = :closed
|
98
113
|
%x{
|
99
114
|
this.socket.close();
|
100
115
|
}
|
data/lib/volt/page/page.rb
CHANGED
@@ -130,6 +130,9 @@ class Page
|
|
130
130
|
# Setup to render template
|
131
131
|
Element.find('body').html = "<!-- $CONTENT --><!-- $/CONTENT -->"
|
132
132
|
|
133
|
+
# Do the initial url params parse
|
134
|
+
@url_tracker.url_updated(true)
|
135
|
+
|
133
136
|
main_controller = IndexController.new
|
134
137
|
|
135
138
|
# Setup main page template
|
@@ -142,8 +145,6 @@ class Page
|
|
142
145
|
`document.title = title;`
|
143
146
|
end
|
144
147
|
TemplateRenderer.new(title_target, main_controller, "main", "home/index/index/title")
|
145
|
-
|
146
|
-
@url_tracker.url_updated(true)
|
147
148
|
end
|
148
149
|
end
|
149
150
|
|
data/lib/volt/router/routes.rb
CHANGED
@@ -44,8 +44,9 @@ class Routes
|
|
44
44
|
|
45
45
|
add_path_matcher(sections) if Volt.server?
|
46
46
|
|
47
|
+
# Create a path that takes in the params and returns the main
|
48
|
+
# part of the url with the params filled in.
|
47
49
|
path = Proc.new do |params|
|
48
|
-
# Create a path using the params in the path
|
49
50
|
sections.map do |section|
|
50
51
|
if section[0] == '{' && section[-1] == '}'
|
51
52
|
params[section[1..-2]]
|
@@ -63,7 +64,7 @@ class Routes
|
|
63
64
|
match_path = ''
|
64
65
|
sections.each do |section|
|
65
66
|
if section[0] == '{' && section[-1] == '}'
|
66
|
-
match_path = match_path + "[
|
67
|
+
match_path = match_path + "[^\\/]+"
|
67
68
|
else
|
68
69
|
match_path = match_path + section
|
69
70
|
end
|
@@ -85,9 +86,15 @@ class Routes
|
|
85
86
|
end
|
86
87
|
|
87
88
|
# Takes in a path and returns the matching params.
|
89
|
+
# TODO: Slow, need dfa
|
88
90
|
def params_for_path(path)
|
89
91
|
routes.each do |route|
|
90
|
-
|
92
|
+
puts "ROUTE: #{route.inspect} -- #{path.inspect}"
|
93
|
+
if false && route[0].class == Proc
|
94
|
+
# puts route[0].call(params).inspect
|
95
|
+
|
96
|
+
return false
|
97
|
+
elsif route[0] == path
|
91
98
|
# Found the matching route
|
92
99
|
return route[1]
|
93
100
|
end
|
@@ -99,6 +106,7 @@ class Routes
|
|
99
106
|
private
|
100
107
|
def path_and_params(params, path, options)
|
101
108
|
params = params.attributes.dup
|
109
|
+
puts params.inspect if path.class == Proc
|
102
110
|
path = path.call(params) if path.class == Proc
|
103
111
|
|
104
112
|
options.keys.each do |key|
|
@@ -108,11 +116,23 @@ class Routes
|
|
108
116
|
return path, params
|
109
117
|
end
|
110
118
|
|
119
|
+
# Match one route against the current params.
|
111
120
|
def params_match_options?(params, options)
|
112
121
|
options.each_pair do |key, value|
|
113
|
-
#
|
114
|
-
#
|
115
|
-
|
122
|
+
# If the value is a hash, we have a nested route. Get the
|
123
|
+
# matching section in the parameter and loop down to check
|
124
|
+
# the values down.
|
125
|
+
if value.is_a?(Hash)
|
126
|
+
sub_params = params.send(key)
|
127
|
+
|
128
|
+
if sub_params
|
129
|
+
return params_match_options?(sub_params, value)
|
130
|
+
else
|
131
|
+
return false
|
132
|
+
end
|
133
|
+
elsif value != nil && value != params.send(key)
|
134
|
+
# A nil value means it can match anything, so we don't want to
|
135
|
+
# fail on nil.
|
116
136
|
return false
|
117
137
|
end
|
118
138
|
end
|
data/spec/models/model_spec.rb
CHANGED
@@ -449,10 +449,11 @@ describe Model do
|
|
449
449
|
|
450
450
|
all_items = a._items.to_a.cur
|
451
451
|
|
452
|
-
|
452
|
+
a = [
|
453
453
|
{:_name=>"Test1", :_other=>{:_time=>"Now"}},
|
454
454
|
{:_name=>"Test2", :_other=>{:_time=>"Later"}}
|
455
|
-
]
|
455
|
+
]
|
456
|
+
expect(all_items).to eq(a)
|
456
457
|
end
|
457
458
|
|
458
459
|
|