inesita 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 458b9936036113bd22c7281e5540805eaf750859
4
- data.tar.gz: 7863484c3dc1751231b3e0f3e2dee9b72e777a63
3
+ metadata.gz: 1e1ab35a96ca0e0be0d5e6b5f673c0d4d4d41aa2
4
+ data.tar.gz: e6631eb22bf44f14f912cd424deb9bea2b6b1db0
5
5
  SHA512:
6
- metadata.gz: 0da6474d7bd3f30e9c4e66c5d71614c29bd788c7e23cc0393b1a081c44a6a3816685452c52515aa6d5c6ce7017a04664e7846c0054a5f21652adb2451462f275
7
- data.tar.gz: da1834d65e9c268644463ec5a86e4121249f9159989e98e47212be7b76814eba7a179a76a8b0c893d8d38c32c0e5286e868f2cc702b404287b1d79b5893bf73c
6
+ metadata.gz: 012401b46fcb01f87440465e4ee08ae6de69d4fb4a481a467b1373b9d5a2b7344d4c25c0cf1dc2c3a620f612e05bd7d2531a17a399f78447e2297478035591d5
7
+ data.tar.gz: 542547268bc1bf4eca309993a3c60fd01bc0ce95e0c9e8891bb5027b4dc1d23adac1aaeefb4af5607369b5a88e435b006ba7ff936114bc18cf5698113ade6db3
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'inesita'
3
- s.version = '0.0.10'
3
+ s.version = '0.0.11'
4
4
  s.authors = [ 'Michał Kalbarczyk' ]
5
5
  s.email = 'fazibear@gmail.com'
6
6
  s.homepage = 'http://github.com/fazibear/inesita'
@@ -1,8 +1,10 @@
1
1
  class Layout
2
2
  include Inesita::Layout
3
3
 
4
+ components :navbar
5
+
4
6
  def initialize
5
- component :navbar, NavBar.new
7
+ @navbar ||= NavBar.new
6
8
  end
7
9
 
8
10
  def render
@@ -1,5 +1,6 @@
1
1
  class Welcome
2
2
  include Inesita::Component
3
+
3
4
  def render
4
5
  div class: 'jumbotron text-center' do
5
6
  h1 do
@@ -2,7 +2,7 @@ module Inesita
2
2
  class Application
3
3
  include Inesita::Component
4
4
 
5
- attr_reader :layout
5
+ components :parent
6
6
 
7
7
  def initialize(options)
8
8
  raise 'Routes missing' unless options[:routes]
@@ -10,11 +10,13 @@ module Inesita
10
10
  @router = Router.new(options[:routes])
11
11
  @layout = options[:layout]
12
12
 
13
- component :parent, @layout ? @layout.create(@router) : @router
13
+ @parent = @layout ? @layout.create(@router) : @router
14
14
  end
15
15
 
16
16
  def render
17
- component parent
17
+ dom do
18
+ component parent
19
+ end
18
20
  end
19
21
  end
20
22
  end
@@ -2,19 +2,24 @@ module Inesita
2
2
  module Component
3
3
  include VirtualDOM
4
4
 
5
- def parent(component)
5
+ def with_parent(component)
6
6
  @parent = component
7
+ self
8
+ end
9
+
10
+ def dom(&block)
11
+ NodeFactory.new(block, self).nodes.first
7
12
  end
8
13
 
9
14
  def mount(element)
10
- @virtual_dom = NodeFactory.new(method(:render), self).nodes.first
15
+ @virtual_dom = render
11
16
  @mount_point = VirtualDOM.create(@virtual_dom)
12
17
  element.inner_dom = @mount_point
13
18
  end
14
19
 
15
20
  def update
16
21
  if @virtual_dom && @mount_point
17
- new_virtual_dom = NodeFactory.new(method(:render), self).nodes.first
22
+ new_virtual_dom = render
18
23
  diff = VirtualDOM.diff(@virtual_dom, new_virtual_dom)
19
24
  VirtualDOM.patch(@mount_point, diff)
20
25
  @virtual_dom = new_virtual_dom
@@ -27,13 +32,20 @@ module Inesita
27
32
  `document.location.pathname`
28
33
  end
29
34
 
30
- def component(name, instance)
31
- self.class.define_method name do
32
- unless instance_variable_get(:"@#{name}")
33
- instance_variable_set(:"@#{name}", instance)
34
- instance_variable_get(:"@#{name}").parent(self)
35
+ def self.included(base)
36
+ base.extend(ClassMethods)
37
+ end
38
+
39
+ module ClassMethods
40
+ def components(*attrs)
41
+ attrs.flatten.each do |component|
42
+ if VirtualDOM::NodeFactory::HTML_TAGS.include?(component)
43
+ fail "Forbidden component name '#{component}' in #{self} component"
44
+ else
45
+ attr_reader component
46
+ end
35
47
  end
36
- instance_variable_get(:"@#{name}")
48
+ attr_reader *attrs.flatten
37
49
  end
38
50
  end
39
51
  end
@@ -3,13 +3,17 @@ module Inesita
3
3
  def self.included(base)
4
4
  base.include(Component)
5
5
  base.extend(ClassMethods)
6
+ base.components :outlet
7
+ end
8
+
9
+ def with_outlet(outlet)
10
+ @outlet = outlet
11
+ self
6
12
  end
7
13
 
8
14
  module ClassMethods
9
15
  def create(outlet)
10
- new.tap do |l|
11
- l.component :outlet, outlet
12
- end
16
+ new.with_outlet(outlet)
13
17
  end
14
18
  end
15
19
  end
@@ -2,23 +2,24 @@ module Inesita
2
2
  class Router
3
3
  include Inesita::Component
4
4
  class << self; attr_accessor :handle_browser_history; end
5
- attr_reader :routes
5
+
6
+ components :routes
6
7
 
7
8
  def initialize(routes)
8
9
  default_component = routes.values.first.new
9
- default_component.parent(self)
10
10
 
11
11
  @routes = Hash.new(default_component)
12
12
  routes.map do |route, component|
13
13
  @routes[route] = component.new
14
- @routes[route].parent(self)
15
14
  end
16
15
 
17
16
  handle_browser_history
18
17
  end
19
18
 
20
19
  def render
21
- component routes[url]
20
+ dom do
21
+ component routes[url]
22
+ end
22
23
  end
23
24
 
24
25
  def handle_browser_history
@@ -1,7 +1,8 @@
1
1
  module VirtualDOM
2
2
  class NodeFactory
3
3
  def component(comp)
4
- @nodes << NodeFactory.new(comp.method(:render), comp).nodes.first
4
+ fail "Component is nil in #{@parent.class} class" if comp.nil?
5
+ @nodes << comp.with_parent(@parent).render
5
6
  end
6
7
 
7
8
  def a(params, &block)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inesita
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
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-07-27 00:00:00.000000000 Z
11
+ date: 2015-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal