opal-virtual-dom 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -0
- data/README.md +14 -3
- data/opal-virtual-dom.gemspec +1 -1
- data/opal/virtual_dom.rb +2 -0
- data/opal/virtual_dom/dom.rb +3 -11
- data/opal/virtual_dom/external_support.rb +13 -0
- data/opal/virtual_dom/external_support/browser.rb +13 -0
- data/opal/virtual_dom/hook.rb +44 -0
- data/opal/virtual_dom/virtual_node.rb +4 -4
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96d8fc092f2b2c0071b9c4f92d3e4695f2c9ce5e
|
4
|
+
data.tar.gz: 0afbc413e5c4e801371d3baf6621083ff6cbd8db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 682a9f128684da190e267aefa56ea2d7feb06b4c08eb092172bc3bd4f2ed04348160bc49e9663c66f4b4e5b2c9a6070a7c290510090f2dae34d3c5d576214a43
|
7
|
+
data.tar.gz: e65b248bbb68d1cd069cacda0cb94c0ecb3e5709f8d49604aa47bf409becaac2fb2419e49c5a3046d768d391bad96478a95d3b3f34a1a5e949e3bf2017581eff
|
data/.codeclimate.yml
ADDED
data/README.md
CHANGED
@@ -2,7 +2,11 @@
|
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/opal-virtual-dom.svg)](http://badge.fury.io/rb/opal-virtual-dom)
|
3
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
|
+
## Description
|
6
|
+
|
7
|
+
Opal wrapper for [virtual-dom](https://github.com/Matt-Esch/virtual-dom) javascript library. For more information see [virtual-dom wiki page](https://github.com/Matt-Esch/virtual-dom/wiki).
|
8
|
+
|
9
|
+
## Usage
|
6
10
|
|
7
11
|
Server side (config.ru, Rakefile, Rails, Sinatra, etc.)
|
8
12
|
|
@@ -15,7 +19,10 @@ Browser side
|
|
15
19
|
```ruby
|
16
20
|
require 'opal'
|
17
21
|
require 'browser' # not required
|
18
|
-
require '
|
22
|
+
require 'virtual_dom'
|
23
|
+
|
24
|
+
# if you're using broser and you want to have events and elements wrapped
|
25
|
+
require 'virtual_dom/external_support/browser'
|
19
26
|
|
20
27
|
class SampleList
|
21
28
|
include VirtualDOM
|
@@ -24,8 +31,12 @@ class SampleList
|
|
24
31
|
@elements = elements
|
25
32
|
end
|
26
33
|
|
34
|
+
def create_hook(node, name, previous)
|
35
|
+
puts "I'm created: #{node}"
|
36
|
+
end
|
37
|
+
|
27
38
|
def render
|
28
|
-
ul class: 'simple-list' do
|
39
|
+
ul class: 'simple-list', hook: Hook.method(:create_hook) do
|
29
40
|
@elements.each do |string|
|
30
41
|
li do
|
31
42
|
text string
|
data/opal-virtual-dom.gemspec
CHANGED
data/opal/virtual_dom.rb
CHANGED
data/opal/virtual_dom/dom.rb
CHANGED
@@ -43,17 +43,9 @@ module VirtualDOM
|
|
43
43
|
params
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
v.call(Browser::Event.new(e))
|
50
|
-
end
|
51
|
-
end
|
52
|
-
else
|
53
|
-
def event_callback(v)
|
54
|
-
proc do |e|
|
55
|
-
v.call(Native(e))
|
56
|
-
end
|
46
|
+
def event_callback(v)
|
47
|
+
proc do |e|
|
48
|
+
v.call(ExternalSupport.wrap_event(e))
|
57
49
|
end
|
58
50
|
end
|
59
51
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module VirtualDOM
|
2
|
+
class CommonHook
|
3
|
+
def self.method(mthd)
|
4
|
+
new do |node, name, previous|
|
5
|
+
mthd.call(node, name, previous)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(&block)
|
10
|
+
@block = block
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_n
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def call_block(node, name, previous)
|
18
|
+
node = ExternalSupport.wrap_node(node)
|
19
|
+
name = Native(name)
|
20
|
+
previous = Native(previous)
|
21
|
+
@block.call(node, name, previous)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Hook < CommonHook
|
26
|
+
%x{
|
27
|
+
Opal.defn(self, 'hook', function(node, name, previous) {
|
28
|
+
var self = this;
|
29
|
+
#{call_block(`node`, `name`, `previous`)};
|
30
|
+
});
|
31
|
+
Opal.defn(self, 'unhook', function(node, name, previous) {});
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
class UnHook < CommonHook
|
36
|
+
%x{
|
37
|
+
Opal.defn(self, 'unhook', function(node, name, previous) {
|
38
|
+
var self = this;
|
39
|
+
#{call_block(`node`, `name`, `previous`)};
|
40
|
+
});
|
41
|
+
Opal.defn(self, 'hook', function(node, name, previous) {});
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module VirtualDOM
|
2
2
|
class VirtualNode
|
3
|
-
def initialize(name, params = {},
|
3
|
+
def initialize(name, params = {}, children = [])
|
4
4
|
@name = name
|
5
5
|
@params = params
|
6
|
-
@
|
6
|
+
@children = children
|
7
7
|
end
|
8
8
|
|
9
9
|
def to_n
|
10
|
-
`virtualDom.h(#{@name}, #{@params.to_n}, #{@
|
10
|
+
`virtualDom.h(#{@name}, #{@params.to_n}, #{@children})`
|
11
11
|
end
|
12
12
|
|
13
13
|
def to_s
|
14
|
-
"<#{@name}#{to_s_params}>#{@
|
14
|
+
"<#{@name}#{to_s_params}>#{@children.map(&:to_s).join}</#{@name}>"
|
15
15
|
end
|
16
16
|
|
17
17
|
def to_s_params
|
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.
|
4
|
+
version: 0.4.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:
|
11
|
+
date: 2016-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -44,6 +44,7 @@ executables: []
|
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
+
- ".codeclimate.yml"
|
47
48
|
- ".gitignore"
|
48
49
|
- Gemfile
|
49
50
|
- LICENSE.md
|
@@ -56,6 +57,9 @@ files:
|
|
56
57
|
- opal/virtual-dom.rb
|
57
58
|
- opal/virtual_dom.rb
|
58
59
|
- opal/virtual_dom/dom.rb
|
60
|
+
- opal/virtual_dom/external_support.rb
|
61
|
+
- opal/virtual_dom/external_support/browser.rb
|
62
|
+
- opal/virtual_dom/hook.rb
|
59
63
|
- opal/virtual_dom/virtual_node.rb
|
60
64
|
- opal/virtual_dom/wrapper.rb
|
61
65
|
homepage: http://github.com/fazibear/opal-virtual-dom
|
@@ -77,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
81
|
version: '0'
|
78
82
|
requirements: []
|
79
83
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.
|
84
|
+
rubygems_version: 2.5.1
|
81
85
|
signing_key:
|
82
86
|
specification_version: 4
|
83
87
|
summary: virtual-dom wrapper for opal
|