volt 0.4.12 → 0.4.14

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: 08c77c87d772570f8364780a35f43715d6d508da
4
- data.tar.gz: c44668cc7839b2d56194f4eaf555224fa5d945d4
3
+ metadata.gz: 905771711030eddcecc7a47be637a9a32d935718
4
+ data.tar.gz: cb0e6dcf3ba7a19bcc1544069d209a3f8508a023
5
5
  SHA512:
6
- metadata.gz: 9bf1d352e1daccbbc308246157d17c5893d4b77ae50d02d2859ba4d51e745d38ab008dade5ee15a7f78db752c20a0e7eb53b1c2038895adcd87f157bff4b6b03
7
- data.tar.gz: 1096504bef8576a640d64228acc99de1ff4956f437b5650ba274be8a22565212d454c02c9e8a45d68537175a623aa07a3af80a7468051c8827c47b3e3203600b
6
+ metadata.gz: 8ffded87588ef61e162316878a4ef29d26c0d61d1d85f480cc48ab169c16e5ee938cf8f80ffd8cdb1171679376cb2f423d5389eacd47919660e5e4bfb8879669
7
+ data.tar.gz: 99d9f82057294e409f44bc061a848caf780ecaf3967e4b211265837d11c1cc4bdc66afbc5505c4a74c054af7b2805756cde8f6a56040fd2d7a265dfead1454f7
data/Readme.md CHANGED
@@ -346,6 +346,59 @@ Models trigger events when their data is updated. Currently models emit three e
346
346
  # => item removed
347
347
 
348
348
 
349
+ ## Automatic Model Conversion
350
+
351
+ ### Hash -> Model
352
+
353
+ For convience, when placing a hash inside of another model, it is automatically converted into a model. Models are similar to hashes, but provide support for things like persistance and triggering reactive events.
354
+
355
+ user = Model.new
356
+ user._name = 'Ryan'
357
+ user._profiles = {
358
+ twitter: 'http://www.twitter.com/ryanstout',
359
+ dribbble: 'http://dribbble.com/ryanstout'
360
+ }
361
+
362
+ user._name
363
+ # => "Ryan"
364
+ user._profiles._twitter
365
+ # => "http://www.twitter.com/ryanstout"
366
+ user._profiles.class
367
+ # => Model
368
+
369
+
370
+ Models are accessed differently from hashes. Instead of using model[:symbol] to access, you call a method model.method_name. This provides a dynamic unified store where setters and getters can be added without changing any access code.
371
+
372
+ ### Array -> ArrayModel
373
+
374
+ Arrays inside of models are automatically converted to an instance of ArrayModel. ArrayModels behave the same as a normal Array except that they can handle things like being bound to backend data and triggering reactive events.
375
+
376
+ model = Model.new
377
+ model._items << {_name: 'item 1'}
378
+ model._items.class
379
+ # => ArrayModel
380
+
381
+ model._items[0].class
382
+ # => Model
383
+ model._items[0]
384
+
385
+
386
+
387
+ To convert a Model or an ArrayModel back to a normal hash, call .to_h or .to_a respectively. To convert them to a JavaScript Object (for passing to some JavaScript code), call .to_n (to native).
388
+
389
+ user = Model.new
390
+ user._name = 'Ryan'
391
+ user._profiles = {
392
+ twitter: 'http://www.twitter.com/ryanstout',
393
+ dribbble: 'http://dribbble.com/ryanstout'
394
+ }
395
+
396
+ user._profiles.to_h
397
+ # => {twitter: 'http://www.twitter.com/ryanstout', dribbble: 'http://dribbble.com/ryanstout'}
398
+
399
+ items = ArrayModel.new([1,2,3,4])
400
+ items
401
+
349
402
  # Controllers
350
403
 
351
404
  A controller can be any class in Volt, however it is common to have that class inherit from ModelController. A model controller lets you specify a model that the controller works off of. This is a common pattern in Volt. To assign the current model, simply set @model to one of the provided models in the initializer.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.12
1
+ 0.4.14
@@ -224,6 +224,10 @@ class Model
224
224
  "<#{self.class.to_s}:#{object_id} #{attributes.inspect}>"
225
225
  end
226
226
 
227
+ def [](val)
228
+ 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"
229
+ end
230
+
227
231
 
228
232
  private
229
233
  # Clear the previous value and assign a new one
@@ -22,8 +22,9 @@ class ContentBinding < BaseBinding
22
22
  # Exception values display the exception as a string
23
23
  value = value.to_s
24
24
 
25
- # Update the text in this section
26
- section.text = value
25
+ # Update the html in this section
26
+ # TODO: Move the formatter into another class.
27
+ section.html = value.gsub("\n", "<br />\n")
27
28
  end
28
29
 
29
30
  def remove
@@ -14,6 +14,10 @@ class AttributeSection
14
14
  set_content_and_rezero_bindings(text, {})
15
15
  end
16
16
 
17
+ def html=(value)
18
+ set_content_and_rezero_bindings(value, {})
19
+ end
20
+
17
21
  # Takes in our html and bindings, and rezero's the comment names, and the
18
22
  # bindings. Returns an updated bindings hash
19
23
  def set_content_and_rezero_bindings(html, bindings)
@@ -21,6 +21,10 @@ class DomSection < BaseSection
21
21
  this.$range().insertNode(document.createTextNode(#{value}));
22
22
  }
23
23
  end
24
+
25
+ def html=(value)
26
+ set_content_and_rezero_bindings(value, {})
27
+ end
24
28
 
25
29
  def remove
26
30
  range = self.range()
@@ -69,9 +73,11 @@ class DomSection < BaseSection
69
73
  %x{
70
74
  temp_div = document.createElement('div');
71
75
  var doc = jQuery.parseHTML(html);
72
-
73
- for (var i=0;i < doc.length;i++) {
74
- temp_div.appendChild(doc[i]);
76
+
77
+ if (doc) {
78
+ for (var i=0;i < doc.length;i++) {
79
+ temp_div.appendChild(doc[i]);
80
+ }
75
81
  }
76
82
  }
77
83
 
@@ -3,5 +3,7 @@ class IndexController < ModelController
3
3
 
4
4
  def initialize
5
5
  super
6
+
7
+ # Add controller setup code here
6
8
  end
7
9
  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.4.12
4
+ version: 0.4.14
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-28 00:00:00.000000000 Z
11
+ date: 2014-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor