volt 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af78d5a1516b7a9eff62b7c5a78ce4cf79ff12aa
4
- data.tar.gz: 79f9315c28e7f8805145b0cabbbcf340d6a7d14c
3
+ metadata.gz: 2390fa6b2d27296a6a761e1bbf575bd07cebc42d
4
+ data.tar.gz: a9520a04804d30eca3619a436918e81987eb7b41
5
5
  SHA512:
6
- metadata.gz: 3783e9990493225b42f8806aa7987b423a6a65fc04d81e07171fdd4df0c9cf137c91b62ed2ad83088e5494bd7e3db65f8ac717efebe6edca067b19070221f9a3
7
- data.tar.gz: 3ac4b68cb199e7c532967037add881ef766774032763bd8889d19d67f181419800392ef1aeca094f7d2c07a75c82634b38faf70e07d9d097f1a5e5e650f0809c
6
+ metadata.gz: 66c6eea2b57285e84f61480db89912df81dbcc82f204e36df68e1bd512a0d716249ee89bda9fab91900909d76e6d48daa4e218c47c77b93b43b3b987b47d6a6a
7
+ data.tar.gz: c59669709786b49c15976d09f9895d1d8952c08bfd6d7b3604fd6f364493ecea0ea5aa0bcf7ee270470c6424584785c122f050d2dd7e373f3c733b6a6396dfc1
data/Readme.md CHANGED
@@ -69,14 +69,19 @@ You can access the volt console with:
69
69
  3. [Each Binding](#each-binding)
70
70
  4. [Attribute Bindings](#attribute-bindings)
71
71
  2. [Models](#models)
72
- 1. [Reactive Models](#reactive-models)
73
- 2. [Model Events](#model-events)
74
- 3. [Provided Collections](#provided-collections)
75
- 3. [Components](#components)
72
+ 1. [Provided Collections](#provided-collections)
73
+ 2. [Reactive Models](#reactive-models)
74
+ 3. [Model Events](#model-events)
75
+ 4. [Automatic Model Conversion](#automatic-model-conversion)
76
+ 3. [Controllers](#controllers)
77
+ 4. [Components](#components)
76
78
  1. [Assets](#assets)
77
79
  2. [Component Generator](#component-generator)
78
- 4. [Controls](#controls)
79
- 5. [Routes](#routes)
80
+ 3. [Provided Components](#provided-components)
81
+ 1. [Notices](#notices)
82
+ 2. [Flash](#flash)
83
+ 5. [Controls](#controls)
84
+ 6. [Routes](#routes)
80
85
  1. [Routes file](#routes-file)
81
86
 
82
87
 
@@ -525,6 +530,30 @@ Once the gem is ready, you can release it to ruby gems with:
525
530
 
526
531
  Remove the path: option in the gemfile if you wish to use the rubygems version.
527
532
 
533
+ ## Provided Components
534
+
535
+ Volt provides a few components to make web developers lives easier.
536
+
537
+ ### Notices
538
+
539
+ Volt automatically places ```<:volt:notices />``` into views. This shows notices for the following:
540
+
541
+ 1. flash messages
542
+ 2. connection status (when a disconnect happens, lets the user know why and when a reconnect will be attempted)
543
+ 3. page reloading notices (in development)
544
+
545
+ ### Flash
546
+
547
+ As part of the notices component explained above, you can append messages to any collection on the flash model.
548
+
549
+ Each collection represents a different type of "flash". Common examples are ```_notices, _warnings, and _errors``` Using different collections allows you to change how you want the flash displayed. For example, you might want ```_notices``` and ```_errors``` to show with different colors.
550
+
551
+ ```ruby
552
+ flash._notices << "message to flash"
553
+ ```
554
+
555
+ These messages will show for 5 seconds, then disappear (both from the screen and the collection).
556
+
528
557
  # Controls
529
558
 
530
559
  Everyone wishes that we could predict the scope and required features for each part of our application, but in the real world, things we don't expect to grow large often do and things we think will be large don't end up that way. Controls let you quickly setup reusable code/views. The location of the control's code can be moved as it grows without changing the way controls are invoked.
@@ -639,7 +668,3 @@ Controllers provide a .channel method, that you can use to get the status of the
639
668
  | retry_count | the number of reconnection attempts that have been made without a successful connection |
640
669
  | reconnect_interval | the time until the next reconnection attempt (in seconds) |
641
670
 
642
-
643
- ## Notices
644
-
645
- Volt ships with a component that provies notices for things like dropped backend connections, flash messages, etc...
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.3
1
+ 0.5.4
@@ -0,0 +1,4 @@
1
+ class Volt
2
+ class NoticesController < ModelController
3
+ end
4
+ end
@@ -2,7 +2,7 @@
2
2
  {#if page._reloading}
3
3
  <div class="notices alert alert-info">Reloading...</div>
4
4
  {/}
5
- {#if !channel.connected?}
5
+ {#if channel.status == :reconnecting}
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{/}
@@ -10,7 +10,9 @@
10
10
  {/}
11
11
  {#if !flash.empty?}
12
12
  <div class="notices alert alert-info">
13
- <p>{flash._notice}</p>
13
+ {#each flash._notices as notice}
14
+ <p>{notice}</p>
15
+ {/}
14
16
  </div>
15
17
  {/}
16
18
  </:body>
@@ -5,4 +5,5 @@ require 'volt/models/persistors/store_factory'
5
5
  require 'volt/models/persistors/array_store'
6
6
  require 'volt/models/persistors/model_store'
7
7
  require 'volt/models/persistors/params'
8
+ require 'volt/models/persistors/flash'
8
9
 
@@ -30,7 +30,7 @@ class ArrayModel < ReactiveArray
30
30
 
31
31
  super(*args)
32
32
 
33
- @persistor.added(args[0]) if @persistor
33
+ @persistor.added(args[0], @array.size-1) if @persistor
34
34
  end
35
35
 
36
36
  # Make sure it gets wrapped
@@ -239,7 +239,7 @@ class Model
239
239
  end
240
240
 
241
241
  def inspect
242
- "<#{self.class.to_s}:#{object_id} #{attributes.inspect}>"
242
+ "<#{self.class.to_s} #{attributes.inspect}>"
243
243
  end
244
244
 
245
245
  def [](val)
@@ -7,7 +7,7 @@ module Persistors
7
7
  def changed(attribute_name)
8
8
  end
9
9
 
10
- def added(model)
10
+ def added(model, index)
11
11
  end
12
12
 
13
13
  # For removed, the default action is to call changed for it
@@ -0,0 +1,32 @@
1
+ require 'volt/models/persistors/base'
2
+
3
+ module Persistors
4
+ class Flash < Base
5
+ def initialize(model)
6
+ @model = model
7
+ end
8
+
9
+ def added(model, index)
10
+ if Volt.client?
11
+ # Setup a new timer for clearing the flash.
12
+ %x{
13
+ setTimeout(function() {
14
+ self.$clear_model(model);
15
+ }, 5000);
16
+ }
17
+ end
18
+ end
19
+
20
+ def clear_model(model)
21
+ @model.delete(model)
22
+
23
+ # Clear out the parent collection (usually the main flash)
24
+ # Makes it so flash.empty? reflects if there is any outstanding
25
+ # flashes.
26
+ if @model.size == 0
27
+ collection_name = @model.path[-1]
28
+ @model.parent.delete(collection_name)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -42,7 +42,7 @@ class Page
42
42
 
43
43
  # Run the code to setup the page
44
44
  @page = ReactiveValue.new(Model.new)
45
- @flash = ReactiveValue.new(Model.new)
45
+ @flash = ReactiveValue.new(Model.new({}, persistor: Persistors::Flash))
46
46
  @store = ReactiveValue.new(Model.new({}, persistor: Persistors::StoreFactory.new(tasks)))
47
47
 
48
48
  @url = ReactiveValue.new(URL.new)
@@ -134,6 +134,8 @@ class Page
134
134
  # Setup to render template
135
135
  Element.find('body').html = "<!-- $CONTENT --><!-- $/CONTENT -->"
136
136
 
137
+ load_stored_page
138
+
137
139
  # Do the initial url params parse
138
140
  @url_tracker.url_updated(true)
139
141
 
@@ -150,6 +152,25 @@ class Page
150
152
  end
151
153
  TemplateRenderer.new(title_target, main_controller, "main", "home/index/index/title")
152
154
  end
155
+
156
+ # When the page is reloaded from the backend, we store the $page.page, so we
157
+ # can reload the page in the exact same state. Speeds up development.
158
+ def load_stored_page
159
+ if Volt.client?
160
+ if `sessionStorage`
161
+ page_obj_str = nil
162
+
163
+ `page_obj_str = sessionStorage.getItem('___page');`
164
+ `if (page_obj_str) {`
165
+ `sessionStorage.removeItem('___page');`
166
+
167
+ JSON.parse(page_obj_str).each_pair do |key, value|
168
+ self.page.send(:"#{key}=", value)
169
+ end
170
+ `}`
171
+ end
172
+ end
173
+ end
153
174
  end
154
175
 
155
176
  if Volt.client?
@@ -93,6 +93,15 @@ class Tasks
93
93
 
94
94
  def reload
95
95
  puts "RELOAD"
96
+ # Stash the current page value
97
+ value = JSON.dump($page.page.cur.to_h)
98
+
99
+ # If this browser supports session storage, store the page, so it will
100
+ # be in the same state when we reload.
101
+ if `sessionStorage`
102
+ `sessionStorage.setItem('___page', value);`
103
+ end
104
+
96
105
  $page.page._reloading = true
97
106
  `window.location.reload(false);`
98
107
  end
@@ -22,7 +22,7 @@ describe Persistors::Store do
22
22
 
23
23
  @model = ArrayModel.new([1,2,3], persistor: persistor)
24
24
 
25
- expect(persistor_instance).to receive(:added).with(4)
25
+ expect(persistor_instance).to receive(:added).with(4,3)
26
26
 
27
27
  @model << 4
28
28
  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.3
4
+ version: 0.5.4
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-01-31 00:00:00.000000000 Z
11
+ date: 2014-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -326,6 +326,7 @@ files:
326
326
  - app/volt/assets/js/jquery-2.0.3.js
327
327
  - app/volt/assets/js/sockjs-0.2.1.min.js
328
328
  - app/volt/config/dependencies.rb
329
+ - app/volt/controllers/notices_controller.rb
329
330
  - app/volt/tasks/channel_tasks.rb
330
331
  - app/volt/tasks/store_tasks.rb
331
332
  - app/volt/views/notices/index.html
@@ -357,6 +358,7 @@ files:
357
358
  - lib/volt/models/model_wrapper.rb
358
359
  - lib/volt/models/persistors/array_store.rb
359
360
  - lib/volt/models/persistors/base.rb
361
+ - lib/volt/models/persistors/flash.rb
360
362
  - lib/volt/models/persistors/model_store.rb
361
363
  - lib/volt/models/persistors/params.rb
362
364
  - lib/volt/models/persistors/store.rb