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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0fbce5e7fa3d1ed96e8563dd882dc9e6ae1220f
4
- data.tar.gz: 015720ea081ebf2899d23a895a88da3cfff019c2
3
+ metadata.gz: 96d8fc092f2b2c0071b9c4f92d3e4695f2c9ce5e
4
+ data.tar.gz: 0afbc413e5c4e801371d3baf6621083ff6cbd8db
5
5
  SHA512:
6
- metadata.gz: 95d46a72a130793814ad75cd53f8ac1af3de3dad1ff3e6f23d67a24d8395925e62fb0eeb5c5eab251d43fd57fade10eace5a6c25bdcc52ef2e38e66ffbcfcf57
7
- data.tar.gz: de28efb4b7f1a522d3e0f0ea237fd501b4aa650c3137e91df17c5b6b8efe324133abc18ddd4531d90fb03e47b3d3fa049c7773f84af21ef1251c5015de933835
6
+ metadata.gz: 682a9f128684da190e267aefa56ea2d7feb06b4c08eb092172bc3bd4f2ed04348160bc49e9663c66f4b4e5b2c9a6070a7c290510090f2dae34d3c5d576214a43
7
+ data.tar.gz: e65b248bbb68d1cd069cacda0cb94c0ecb3e5709f8d49604aa47bf409becaac2fb2419e49c5a3046d768d391bad96478a95d3b3f34a1a5e949e3bf2017581eff
data/.codeclimate.yml ADDED
@@ -0,0 +1,2 @@
1
+ exclude_paths:
2
+ - opal/vendor/*
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
- ## usage
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 'virtual-dom'
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'opal-virtual-dom'
3
- s.version = '0.3.0'
3
+ s.version = '0.4.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
@@ -2,6 +2,8 @@ require 'vendor/virtual-dom'
2
2
  require 'virtual_dom/virtual_node'
3
3
  require 'virtual_dom/wrapper'
4
4
  require 'virtual_dom/dom'
5
+ require 'virtual_dom/hook'
6
+ require 'virtual_dom/external_support'
5
7
 
6
8
  module VirtualDOM
7
9
  include VirtualDOM::DOM
@@ -43,17 +43,9 @@ module VirtualDOM
43
43
  params
44
44
  end
45
45
 
46
- if defined?(Browser::Event)
47
- def event_callback(v)
48
- proc do |e|
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,13 @@
1
+ module VirtualDOM
2
+ module ExternalSupport
3
+ module_function
4
+
5
+ def wrap_node(node)
6
+ Native(node)
7
+ end
8
+
9
+ def wrap_event(event)
10
+ Native(event)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module VirtualDOM
2
+ module ExternalSupport
3
+ module_function
4
+
5
+ def wrap_node(node)
6
+ Browser::DOM::Element.new(node)
7
+ end
8
+
9
+ def wrap_event(event)
10
+ Browser::Event.new(event)
11
+ end
12
+ end
13
+ end
@@ -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 = {}, childrens = [])
3
+ def initialize(name, params = {}, children = [])
4
4
  @name = name
5
5
  @params = params
6
- @childrens = childrens
6
+ @children = children
7
7
  end
8
8
 
9
9
  def to_n
10
- `virtualDom.h(#{@name}, #{@params.to_n}, #{@childrens})`
10
+ `virtualDom.h(#{@name}, #{@params.to_n}, #{@children})`
11
11
  end
12
12
 
13
13
  def to_s
14
- "<#{@name}#{to_s_params}>#{@childrens.map(&:to_s).join}</#{@name}>"
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.3.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: 2015-11-28 00:00:00.000000000 Z
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.4.8
84
+ rubygems_version: 2.5.1
81
85
  signing_key:
82
86
  specification_version: 4
83
87
  summary: virtual-dom wrapper for opal