opal-virtual-dom 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/opal-virtual-dom.gemspec +1 -1
- data/opal/virtual_dom/node_factory.rb +40 -41
- 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: affd48e6d6da883e726fc51daf2e9582d2b6718a
|
4
|
+
data.tar.gz: e4371716afbd5a772e0a7226486c6511dd59add5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5201474d2788cabeeb6337c1f5b6e530e14a6b28d886cd5d1856e85d64819fff4a398523ed85eacd751215c68d9ad0e7201f705c5119dce48bd909544a4423a5
|
7
|
+
data.tar.gz: ad6753e518d81e9021af1a80918f2ec6cab287541fcef9628dd663c8333975737a86188b195174868e68f6a7ac5a1c14432885dae0dbb1808734de3e34f7ae78
|
data/README.md
CHANGED
@@ -49,8 +49,8 @@ class SampleList
|
|
49
49
|
end
|
50
50
|
|
51
51
|
$document.ready do
|
52
|
-
list = SampleList.new(%w(one two three)).render
|
53
|
-
back = SampleList.new(%w(three two one)).render
|
52
|
+
list = SampleList.new(%w(one two three)).render
|
53
|
+
back = SampleList.new(%w(three two one)).render
|
54
54
|
|
55
55
|
root_node = VirtualDOM.create(list)
|
56
56
|
$document.body.inner_dom = root_node
|
data/opal-virtual-dom.gemspec
CHANGED
@@ -1,45 +1,5 @@
|
|
1
1
|
module VirtualDOM
|
2
2
|
class NodeFactory
|
3
|
-
attr_reader :nodes
|
4
|
-
|
5
|
-
def initialize(dom, _self)
|
6
|
-
@nodes = []
|
7
|
-
@self = _self
|
8
|
-
instance_eval(&dom)
|
9
|
-
end
|
10
|
-
|
11
|
-
def method_missing(name, *args, &block)
|
12
|
-
if @self.send(:respond_to?, name)
|
13
|
-
@self.send(name, *args, &block)
|
14
|
-
elsif name == 'text'
|
15
|
-
@nodes << VirtualTextNode.new(args.first).vnode
|
16
|
-
elsif HTML_TAGS.include?(name)
|
17
|
-
@nodes << VirtualNode.new(name, params(args), childrens(args, block)).vnode
|
18
|
-
else
|
19
|
-
super
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def params(args)
|
24
|
-
if args.first.is_a?(Hash)
|
25
|
-
args = args.first
|
26
|
-
args['className'] = args.delete('class') if args.keys.include?('class')
|
27
|
-
args
|
28
|
-
else
|
29
|
-
{}
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def childrens(args, block)
|
34
|
-
if block
|
35
|
-
NodeFactory.new(block, @self).nodes
|
36
|
-
elsif args.last.is_a?(String)
|
37
|
-
[VirtualTextNode.new(args.last).vnode]
|
38
|
-
else
|
39
|
-
[]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
3
|
HTML_TAGS = %w(
|
44
4
|
a abbr address area article aside audio
|
45
5
|
b base bdi bdo blockquote body br button
|
@@ -54,7 +14,7 @@ module VirtualDOM
|
|
54
14
|
map mark menu meta meter
|
55
15
|
nav noscript
|
56
16
|
object ol optgroup option output
|
57
|
-
|
17
|
+
param pre progress
|
58
18
|
q
|
59
19
|
rp rt ruby
|
60
20
|
s samp script section select small source span strong style sub summary sup
|
@@ -63,5 +23,44 @@ module VirtualDOM
|
|
63
23
|
vav video
|
64
24
|
wbr
|
65
25
|
)
|
26
|
+
|
27
|
+
attr_reader :nodes
|
28
|
+
|
29
|
+
def initialize(dom, parent)
|
30
|
+
@nodes = []
|
31
|
+
@parent = parent
|
32
|
+
instance_eval(&dom)
|
33
|
+
end
|
34
|
+
|
35
|
+
HTML_TAGS.each do |tag|
|
36
|
+
define_method tag do |params, &block|
|
37
|
+
@nodes << VirtualNode.new(
|
38
|
+
tag,
|
39
|
+
process_params(params),
|
40
|
+
block ? NodeFactory.new(block, @parent).nodes : []
|
41
|
+
).vnode
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def text(string)
|
46
|
+
@nodes << VirtualTextNode.new(string).vnode
|
47
|
+
end
|
48
|
+
|
49
|
+
def method_missing(name, *args, &block)
|
50
|
+
if @parent.send(:respond_to?, name)
|
51
|
+
@parent.send(name, *args, &block)
|
52
|
+
else
|
53
|
+
super
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def process_params(params)
|
58
|
+
if params && params.is_a?(Hash)
|
59
|
+
params['className'] = params.delete('class') if params.keys.include?('class')
|
60
|
+
params
|
61
|
+
else
|
62
|
+
{}
|
63
|
+
end
|
64
|
+
end
|
66
65
|
end
|
67
66
|
end
|