opal-virtual-dom 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/README.md +6 -5
- data/opal/virtual_dom/node_factory.rb +40 -9
- data/opal/virtual_dom.rb +1 -1
- data/opal-virtual-dom.gemspec +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f111cca8efc994a90bbfbd969ea76a15bd2b1a7
|
4
|
+
data.tar.gz: e88e013e2ae11c3b67b41f628bf7273e6e4d20ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44f2eda3f7a0e236c61218f0b1b4c6547271d118276548b1c3895feaa39f54c15a3e6fe15359d318a0144c4e577a09b8243c148b2edb7e25c82b1fd7fad600ef
|
7
|
+
data.tar.gz: 2def8797c05f166a3b88446899fa3e08d1a1aaf3c1e5b2060902f13e08f7cd51e34157c5ca9e99ff8cd76ea08432ec2c657469eca2ff488d7d48ee7b8c654cc2
|
data/.gitignore
ADDED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# Virtual Dom support for Opal
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/opal-virtual-dom.svg)](http://badge.fury.io/rb/opal-virtual-dom)
|
3
|
-
[![Code Climate](https://codeclimate.com/github/fazibear/opal-virtual-dom/badges/gpa.svg)](https://codeclimate.com/github/fazibear/opal-virtual-dom)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/fazibear/opal-virtual-dom/badges/gpa.svg)](https://codeclimate.com/github/fazibear/opal-virtual-dom)
|
4
4
|
|
5
5
|
## requiments
|
6
6
|
|
@@ -26,17 +26,18 @@ Browser side
|
|
26
26
|
require 'opal'
|
27
27
|
require 'virtual-dom' # javascript library
|
28
28
|
require 'browser' # not required
|
29
|
-
require 'virtual_dom' # opal wrapper
|
29
|
+
require 'virtual_dom' # opal wrapper
|
30
30
|
|
31
31
|
class SampleList
|
32
32
|
include VirtualDOM
|
33
33
|
|
34
|
+
attr_reader :elements
|
35
|
+
|
34
36
|
def initialize(elements = [])
|
35
37
|
@elements = elements
|
36
38
|
end
|
37
39
|
|
38
40
|
def render
|
39
|
-
elements = @elements
|
40
41
|
virtual_dom do
|
41
42
|
ul class: 'simple-list' do
|
42
43
|
elements.each do |string|
|
@@ -57,4 +58,4 @@ $document.ready do
|
|
57
58
|
diff = VirtualDOM.diff(list, back)
|
58
59
|
VirtualDOM.patch(root_node, diff)
|
59
60
|
end
|
60
|
-
```
|
61
|
+
```
|
@@ -1,18 +1,25 @@
|
|
1
|
-
|
1
|
+
module VirtualDOM
|
2
2
|
class NodeFactory
|
3
3
|
attr_reader :nodes
|
4
4
|
|
5
|
-
def initialize(dom)
|
5
|
+
def initialize(dom, _self)
|
6
6
|
@nodes = []
|
7
|
-
@
|
7
|
+
@self = _self
|
8
|
+
instance_eval(&dom)
|
8
9
|
end
|
9
10
|
|
10
11
|
def method_missing(name, *args, &block)
|
11
|
-
@
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
if @self.send(:respond_to?, name)
|
13
|
+
@self.send(name, *args, &block)
|
14
|
+
elsif HTML_TAGS.include?(name)
|
15
|
+
@nodes << if name == 'text'
|
16
|
+
VirtualTextNode.new(args.first).vnode
|
17
|
+
else
|
18
|
+
VirtualNode.new(name, params(args), childrens(args, block)).vnode
|
19
|
+
end
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
16
23
|
end
|
17
24
|
|
18
25
|
def params(args)
|
@@ -27,12 +34,36 @@ class VirtualDOM
|
|
27
34
|
|
28
35
|
def childrens(args, block)
|
29
36
|
if block
|
30
|
-
NodeFactory.new(block).nodes
|
37
|
+
NodeFactory.new(block, @self).nodes
|
31
38
|
elsif args.last.is_a?(String)
|
32
39
|
[VirtualTextNode.new(args.last).vnode]
|
33
40
|
else
|
34
41
|
[]
|
35
42
|
end
|
36
43
|
end
|
44
|
+
|
45
|
+
HTML_TAGS = %w(
|
46
|
+
a abbr address area article aside audio
|
47
|
+
b base bdi bdo blockquote body br button
|
48
|
+
canvas caption cite code col colgroup command
|
49
|
+
data datalist dd del details dfn dialog div dl dt
|
50
|
+
em embed
|
51
|
+
fieldset figcaption figure footer form
|
52
|
+
h1 h2 h3 h4 h5 h6 head header hgroup hr html
|
53
|
+
i iframe img input ins
|
54
|
+
kbd keygen
|
55
|
+
label legend li link
|
56
|
+
map mark menu meta meter
|
57
|
+
nav noscript
|
58
|
+
object ol optgroup option output
|
59
|
+
p param pre progress
|
60
|
+
q
|
61
|
+
rp rt ruby
|
62
|
+
s samp script section select small source span strong style sub summary sup
|
63
|
+
table tbody td textarea tfoot th thead time title tr track
|
64
|
+
u ul
|
65
|
+
vav video
|
66
|
+
wbr
|
67
|
+
)
|
37
68
|
end
|
38
69
|
end
|
data/opal/virtual_dom.rb
CHANGED
data/opal-virtual-dom.gemspec
CHANGED
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.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michał Kalbarczyk
|
@@ -44,6 +44,7 @@ executables: []
|
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
+
- ".gitignore"
|
47
48
|
- Gemfile
|
48
49
|
- README.md
|
49
50
|
- Rakefile
|