opal-virtual-dom 0.0.5 → 0.1.0

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: 7cc990c4c96f2e28448f288b3ea4052eb8cd2f19
4
- data.tar.gz: d8f664e45585821c6d59b68f9de7344505e5b415
3
+ metadata.gz: 8f0189e3d7be5aca3994abaae718dc232650dfa5
4
+ data.tar.gz: 0ea3804fb5020f857b5d0d51e59e570ffa8fd99b
5
5
  SHA512:
6
- metadata.gz: 02c7bbf79cef887b97c9a4dddf7c9d6ab6f7e4e6062b9fee26496e70d92e9895f0df9f11a1c9d4d3d3f3fece98e3d4bb3941b1aaa0e19d2890b7b2e474fa2e92
7
- data.tar.gz: 57bf94f20257d81900009c565a064a1d1ab08b1c06a481883d7e028b8debc450739e2e0e33166c14ab7631653d2f807668da4a82486b343fbcfbef0ab468c8eb
6
+ metadata.gz: 2d2e4b6e53f95b21bec2d55d302f6513e5e1b0055539f1283169632466616dc52bd947667dc16e13dc1d22754523e5892d3f846ebcd947b6b3ecd2769eed5b72
7
+ data.tar.gz: 2b96075d013c8b42dae30f2135a6a1e4c016822b39b07c7c676ab24f0c0973941e920a7da9fc1480657958279d3dbbea06ad08b48b8079f1e540b12a8472adb1
data/README.md CHANGED
@@ -31,17 +31,15 @@ require 'virtual_dom' # opal wrapper
31
31
  class SampleList
32
32
  include VirtualDOM
33
33
 
34
- attr_reader :elements
35
-
36
34
  def initialize(elements = [])
37
35
  @elements = elements
38
36
  end
39
37
 
40
38
  def render
41
- virtual_dom do
42
- ul class: 'simple-list' do
43
- elements.each do |string|
44
- li string
39
+ ul class: 'simple-list' do
40
+ @elements.each do |string|
41
+ li do
42
+ text string
45
43
  end
46
44
  end
47
45
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'opal-virtual-dom'
3
- s.version = '0.0.5'
3
+ s.version = '0.1.0'
4
4
  s.authors = [ 'Michał Kalbarczyk' ]
5
5
  s.email = 'fazibear@gmail.com'
6
6
  s.homepage = 'http://github.com/fazibear/opal-virtual-dom'
data/opal/virtual_dom.rb CHANGED
@@ -1,23 +1,9 @@
1
1
  require 'virtual_dom/virtual_node'
2
2
  require 'virtual_dom/virtual_text_node'
3
- require 'virtual_dom/node_factory'
3
+ require 'virtual_dom/wrapper'
4
+ require 'virtual_dom/dom'
4
5
 
5
6
  module VirtualDOM
6
- def virtual_dom(&block)
7
- NodeFactory.new(block, self).nodes.first
8
- end
9
-
10
- module_function
11
-
12
- def create(vnode)
13
- `virtualDom.create(#{vnode})`
14
- end
15
-
16
- def diff(old, new)
17
- `virtualDom.diff(#{old}, #{new})`
18
- end
19
-
20
- def patch(dom, diff)
21
- `virtualDom.patch(#{dom}, #{diff})`
22
- end
7
+ include VirtualDOM::DOM
8
+ extend VirtualDOM::Wrapper
23
9
  end
@@ -0,0 +1,53 @@
1
+ module VirtualDOM
2
+ module DOM
3
+ HTML_TAGS = %w(a abbr address area article aside audio b base bdi bdo big blockquote body br
4
+ button canvas caption cite code col colgroup data datalist dd del details dfn
5
+ dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5
6
+ h6 head header hr html i iframe img input ins kbd keygen label legend li link
7
+ main map mark menu menuitem meta meter nav noscript object ol optgroup option
8
+ output p param picture pre progress q rp rt ruby s samp script section select
9
+ small source span strong style sub summary sup table tbody td textarea tfoot th
10
+ thead time title tr track u ul var video wbr)
11
+
12
+ HTML_TAGS.each do |tag|
13
+ define_method tag do |params, &block|
14
+ @__virtual_nodes__ ||= []
15
+ if block
16
+ current = @__virtual_nodes__
17
+ @__virtual_nodes__ = []
18
+ result = block.call
19
+ vnode = VirtualNode.new(tag, process_params(params), @__virtual_nodes__.count == 0 ? result : @__virtual_nodes__).vnode
20
+ @__virtual_nodes__ = current
21
+ else
22
+ vnode = VirtualNode.new(tag, process_params(params), []).vnode
23
+ end
24
+ @__virtual_nodes__ << vnode
25
+ vnode
26
+ end
27
+ end
28
+
29
+ def text(string)
30
+ @__virtual_nodes__ << VirtualTextNode.new(string).vnode
31
+ end
32
+
33
+ def process_params(params)
34
+ if params && params.is_a?(Hash)
35
+ params.each do |k, v|
36
+ case k
37
+ when 'class'
38
+ params['className'] = params.delete('class')
39
+ when /^on/
40
+ params[k] = ->(e) { v.call(Native(e)) }
41
+ end
42
+ end
43
+ else
44
+ {}
45
+ end
46
+ end
47
+
48
+ # for backwards compatibility
49
+ def virtual_dom(&block)
50
+ block.call
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,15 @@
1
+ module VirtualDOM
2
+ module Wrapper
3
+ def create(vnode)
4
+ `virtualDom.create(#{vnode})`
5
+ end
6
+
7
+ def diff(old, new)
8
+ `virtualDom.diff(#{old}, #{new})`
9
+ end
10
+
11
+ def patch(dom, diff)
12
+ `virtualDom.patch(#{dom}, #{diff})`
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-virtual-dom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Kalbarczyk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-10 00:00:00.000000000 Z
11
+ date: 2015-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -51,9 +51,10 @@ files:
51
51
  - lib/opal-virtual-dom.rb
52
52
  - opal-virtual-dom.gemspec
53
53
  - opal/virtual_dom.rb
54
- - opal/virtual_dom/node_factory.rb
54
+ - opal/virtual_dom/dom.rb
55
55
  - opal/virtual_dom/virtual_node.rb
56
56
  - opal/virtual_dom/virtual_text_node.rb
57
+ - opal/virtual_dom/wrapper.rb
57
58
  homepage: http://github.com/fazibear/opal-virtual-dom
58
59
  licenses: []
59
60
  metadata: {}
@@ -1,72 +0,0 @@
1
- module VirtualDOM
2
- class NodeFactory
3
- HTML_TAGS = %w(
4
- a abbr address area article aside audio
5
- b base bdi bdo blockquote body br button
6
- canvas caption cite code col colgroup command
7
- data datalist dd del details dfn dialog div dl dt
8
- em embed
9
- fieldset figcaption figure footer form
10
- h1 h2 h3 h4 h5 h6 head header hgroup hr html
11
- i iframe img input ins
12
- kbd keygen
13
- label legend li link
14
- map mark menu meta meter
15
- nav noscript
16
- object ol optgroup option output
17
- p param pre progress
18
- q
19
- rp rt ruby
20
- s samp script section select small source span strong style sub summary sup
21
- table tbody td textarea tfoot th thead time title tr track
22
- u ul
23
- vav video
24
- wbr
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.each do |k, v|
60
- case k
61
- when 'class'
62
- params['className'] = params.delete('class')
63
- when /^on/
64
- params[k] = ->(e) { v.call(Native(e)) }
65
- end
66
- end
67
- else
68
- {}
69
- end
70
- end
71
- end
72
- end