volt 0.4.12 → 0.4.14
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 +53 -0
- data/VERSION +1 -1
- data/lib/volt/models/model.rb +4 -0
- data/lib/volt/page/bindings/content_binding.rb +3 -2
- data/lib/volt/page/targets/attribute_section.rb +4 -0
- data/lib/volt/page/targets/dom_section.rb +9 -3
- data/templates/project/app/home/controllers/index_controller.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 905771711030eddcecc7a47be637a9a32d935718
|
4
|
+
data.tar.gz: cb0e6dcf3ba7a19bcc1544069d209a3f8508a023
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
1
|
+
0.4.14
|
data/lib/volt/models/model.rb
CHANGED
@@ -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
|
26
|
-
|
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
|
-
|
74
|
-
|
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
|
|
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.
|
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-
|
11
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|