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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7344ad56ece898e553c1189b17452ffb374deae8
4
- data.tar.gz: e560a2a52146f435adf8a0a35802ceb15ee64a96
3
+ metadata.gz: affd48e6d6da883e726fc51daf2e9582d2b6718a
4
+ data.tar.gz: e4371716afbd5a772e0a7226486c6511dd59add5
5
5
  SHA512:
6
- metadata.gz: 38ea04be50cb93c26c33a597b7edbaa0f42798ab4ed599849cfeb2dce17a96dd4e21dc1589a3f5b7b450a816a2bd48eabddd3e8526060b9d39abc402737055c5
7
- data.tar.gz: b1f0306e5b360e16c81fb0141fd0ad2d7d292569cc932ea4d4a41d1fe14bcf82b3fbe26b37b997d631a88d0164ac4e1364957380bc0f73ba4c52620354de8a3a
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.first
53
- back = SampleList.new(%w(three two one)).render.first
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'opal-virtual-dom'
3
- s.version = '0.0.3'
3
+ s.version = '0.0.4'
4
4
  s.authors = [ 'Michał Kalbarczyk' ]
5
5
  s.email = 'fazibear@gmail.com'
6
6
  s.homepage = 'http://github.com/fazibear/opal-virtual-dom'
@@ -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
- p param pre progress
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-virtual-dom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Kalbarczyk