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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c56e43b7c45be94787d99ca10c30bf46db403f9e
4
- data.tar.gz: 55e255e70937cbc43f0fedc862a8435ae5d7533f
3
+ metadata.gz: 3f111cca8efc994a90bbfbd969ea76a15bd2b1a7
4
+ data.tar.gz: e88e013e2ae11c3b67b41f628bf7273e6e4d20ea
5
5
  SHA512:
6
- metadata.gz: 99336d26f7a317f6a95f5a48f75b2ac833e1a9050489af078d30fffc3aca32b8749f98545e3ed24409e01b86d46f623c18a2de42c30ab2d7882f5f1348d72103
7
- data.tar.gz: 4e8bf55b6534d825fd266355d9ce87b705a232cf8a41d1d1ea952abca0941c915beeeb3652cd723ac78036097115fe2f6cf835b09e31c42125fe4c7c0ef253ed
6
+ metadata.gz: 44f2eda3f7a0e236c61218f0b1b4c6547271d118276548b1c3895feaa39f54c15a3e6fe15359d318a0144c4e577a09b8243c148b2edb7e25c82b1fd7fad600ef
7
+ data.tar.gz: 2def8797c05f166a3b88446899fa3e08d1a1aaf3c1e5b2060902f13e08f7cd51e34157c5ca9e99ff8cd76ea08432ec2c657469eca2ff488d7d48ee7b8c654cc2
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/
2
+
3
+ Gemfile.lock
4
+
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # virtual-dom support for Opal
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
- class VirtualDOM
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
- @eval = instance_eval(&dom)
7
+ @self = _self
8
+ instance_eval(&dom)
8
9
  end
9
10
 
10
11
  def method_missing(name, *args, &block)
11
- @nodes << if name == 'text'
12
- VirtualTextNode.new(args.first).vnode
13
- else
14
- VirtualNode.new(name, params(args), childrens(args, block)).vnode
15
- end
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
@@ -4,7 +4,7 @@ require 'virtual_dom/node_factory'
4
4
 
5
5
  module VirtualDOM
6
6
  def virtual_dom(&block)
7
- NodeFactory.new(block).nodes
7
+ NodeFactory.new(block, self).nodes.first
8
8
  end
9
9
 
10
10
  module_function
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'opal-virtual-dom'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.authors = [ 'Michał Kalbarczyk' ]
5
5
  s.email = 'fazibear@gmail.com'
6
6
  s.homepage = 'http://github.com/fazibear/opal-virtual-dom'
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.1
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