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 +4 -4
- data/README.md +4 -6
- data/opal-virtual-dom.gemspec +1 -1
- data/opal/virtual_dom.rb +4 -18
- data/opal/virtual_dom/dom.rb +53 -0
- data/opal/virtual_dom/wrapper.rb +15 -0
- metadata +4 -3
- data/opal/virtual_dom/node_factory.rb +0 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f0189e3d7be5aca3994abaae718dc232650dfa5
|
4
|
+
data.tar.gz: 0ea3804fb5020f857b5d0d51e59e570ffa8fd99b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
data/opal-virtual-dom.gemspec
CHANGED
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/
|
3
|
+
require 'virtual_dom/wrapper'
|
4
|
+
require 'virtual_dom/dom'
|
4
5
|
|
5
6
|
module VirtualDOM
|
6
|
-
|
7
|
-
|
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
|
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
|
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-
|
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/
|
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
|