volt 0.5.4 → 0.5.6

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: 2390fa6b2d27296a6a761e1bbf575bd07cebc42d
4
- data.tar.gz: a9520a04804d30eca3619a436918e81987eb7b41
3
+ metadata.gz: 7b8a76f2d758ccc809b63fb8cb7433b1b6e11c54
4
+ data.tar.gz: 9ecc4f6a3333af52c492ac2079372beece3c773f
5
5
  SHA512:
6
- metadata.gz: 66c6eea2b57285e84f61480db89912df81dbcc82f204e36df68e1bd512a0d716249ee89bda9fab91900909d76e6d48daa4e218c47c77b93b43b3b987b47d6a6a
7
- data.tar.gz: c59669709786b49c15976d09f9895d1d8952c08bfd6d7b3604fd6f364493ecea0ea5aa0bcf7ee270470c6424584785c122f050d2dd7e373f3c733b6a6396dfc1
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.4
1
+ 0.5.6
@@ -5,4 +5,5 @@
5
5
  margin-left: -300px;
6
6
  left: 50%;
7
7
  z-index: 1000;
8
+ cursor: pointer;
8
9
  }
@@ -9,7 +9,7 @@
9
9
  </div>
10
10
  {/}
11
11
  {#if !flash.empty?}
12
- <div class="notices alert alert-info">
12
+ <div class="notices alert alert-info" e-click="flash.clear">
13
13
  {#each flash._notices as notice}
14
14
  <p>{notice}</p>
15
15
  {/}
@@ -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 result
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
@@ -17,6 +17,7 @@ class URL
17
17
  destructive!
18
18
  end
19
19
  def parse(url)
20
+ puts "PARSE: #{url}"
20
21
  matcher = url.match(/^(https?)[:]\/\/([^\/]+)(.*)$/)
21
22
  @scheme = matcher[1]
22
23
  @host, @port = matcher[2].split(':')
@@ -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
- private
137
-
138
- def range
139
- return @range if @range
142
+ def range
143
+ return @range if @range
140
144
 
141
- range = nil
142
- %x{
143
- range = document.createRange();
144
- range.setStartAfter(this.start_node);
145
- range.setEndBefore(this.end_node);
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
- @range = range
152
+ @range = range
149
153
 
150
- return range
151
- end
154
+ return range
155
+ end
152
156
 
153
157
  end
@@ -26,6 +26,10 @@ class TemplateRenderer < BaseBinding
26
26
  end
27
27
  end
28
28
 
29
+ if @context.respond_to?(:section=)
30
+ @context.section = self.section
31
+ end
32
+
29
33
  if @context.respond_to?(:dom_ready)
30
34
  @context.dom_ready
31
35
  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
@@ -89,7 +89,7 @@ class Routes
89
89
  # TODO: Slow, need dfa
90
90
  def params_for_path(path)
91
91
  routes.each do |route|
92
- puts "ROUTE: #{route.inspect} -- #{path.inspect}"
92
+ # TODO: Finish nested routes
93
93
  if false && route[0].class == Proc
94
94
  # puts route[0].call(params).inspect
95
95
 
@@ -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
@@ -1,5 +1,7 @@
1
1
  module <%=config[:name].gsub(/^volt[-]/, '').gsub('-', '_').split("_").map {|s| s.capitalize }.join("") %>
2
- class IndexController
2
+ class IndexController < ModelController
3
+ model :page
4
+
3
5
  attr_accessor :data
4
6
 
5
7
  def initialize(data)
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
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-01 00:00:00.000000000 Z
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