inesita 0.4.4 → 0.5.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: fdaaffe2e4aafb5d72428c08684f3c3c2330611d
4
- data.tar.gz: 6f1453ef8e9cdd016baf70935a2a719144fe1667
3
+ metadata.gz: b37363ed5044f4dc5a61efe0d92ba7f2eecd8938
4
+ data.tar.gz: d04e1ee6dd0e06d748777b60adfaa2fb0446085a
5
5
  SHA512:
6
- metadata.gz: 26968cf01a88384d6eee6ee5a66f54e588437c652abbf18ec50fcd8c63a8fe3783c6ea11352ff4c0384a9e79f4466a9a2854e70b1a8cb3753e5a4e2d9fd6ca52
7
- data.tar.gz: 112e86389819cd90b5b9f864ba59acd540e989f18a8bb27d962e7323ab71c5681cac57c1004e89ba44ac21ab07206b4af3a5d1e08daa6b5abf74c3135c57cd83
6
+ metadata.gz: 53a97e1c19d97eff209dc3e9b7daa1be6a34b72a9ab5549cd8af76c73c526cb13a3a5a5a62c489af34b6806b5af285f40aba0c3f0b6e4fded198f474555ab01b
7
+ data.tar.gz: 40bc04dadbe5c5244fc46cf4c80548c47d085e77a4d1d4c60247f1c080be0797079882c8b30951ecc44b88ab9419955d0b5962406a47a6319a94c02562151cc4
data/CHANGELOG.md CHANGED
@@ -1,4 +1,16 @@
1
- ## [0.4.4] - 2016.10.4
1
+ ## [0.5.0] - 2016.10.22
2
+
3
+ ### Added
4
+ - Injection (you can inject any object)
5
+ - `before_render` callback to `Component`
6
+
7
+ ### Changed
8
+ - Store is deprecated, use Injection
9
+
10
+ ### Removed
11
+ - `init` callback, use `initialize` instead
12
+
13
+ ## [0.4.4] - 2016.10.04
2
14
 
3
15
  ### Added
4
16
  - `on_enter` callback to Router
data/inesita.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'inesita'
3
- s.version = '0.4.4'
3
+ s.version = '0.5.0'
4
4
  s.authors = ['Michał Kalbarczyk']
5
5
  s.email = 'fazibear@gmail.com'
6
6
  s.homepage = 'http://github.com/inesita-rb/inesita'
@@ -1,7 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  # inesita gem
4
- gem 'inesita', '~> 0.4.0'
4
+ gem 'inesita', '~> 0.5.0'
5
5
  gem 'inesita-livereload', '~> 0.1.0'
6
6
 
7
7
  # add this gems to minify files on build
@@ -1,5 +1,5 @@
1
1
  class Store
2
- include Inesita::Store
2
+ include Inesita::Injection
3
3
 
4
4
  def initialize
5
5
  @store = {}
data/opal/inesita.rb CHANGED
@@ -7,8 +7,8 @@ require 'virtual_dom'
7
7
  require 'inesita/browser'
8
8
  require 'inesita/error'
9
9
  require 'inesita/component_virtual_dom_extension'
10
- require 'inesita/component_properties'
11
10
  require 'inesita/component_helpers'
11
+ require 'inesita/injection'
12
12
  require 'inesita/component'
13
13
  require 'inesita/routes'
14
14
  require 'inesita/router'
@@ -3,10 +3,10 @@ module Inesita
3
3
  include Inesita::Component
4
4
 
5
5
  def initialize(options = {})
6
- setup_router(options[:router])
7
- setup_layout(options[:layout])
6
+ setup_router(options.delete(:router))
7
+ setup_layout(options.delete(:layout))
8
8
  setup_root
9
- setup_store(options[:store])
9
+ setup_injections(options)
10
10
  end
11
11
 
12
12
  def render
@@ -18,7 +18,7 @@ module Inesita
18
18
  def setup_router(router)
19
19
  if router
20
20
  raise Error, "Invalid #{router} class, should mixin Inesita::Router" unless router.include?(Inesita::Router)
21
- @router = router.new
21
+ @router = inject(:router, router.new)
22
22
  else
23
23
  @router = Class.new { define_method(:method_missing) { raise 'Router missing' } }.new
24
24
  end
@@ -27,7 +27,7 @@ module Inesita
27
27
  def setup_layout(layout)
28
28
  if layout
29
29
  raise Error, "Invalid #{layout} class, should mixin Inesita::Layout" unless layout.include?(Inesita::Layout)
30
- @layout = layout.new
30
+ @layout = inject(:layout, layout.new)
31
31
  end
32
32
  end
33
33
 
@@ -41,11 +41,12 @@ module Inesita
41
41
  end
42
42
  end
43
43
 
44
- def setup_store(store)
45
- return unless store
46
- raise Error, "Invalid #{store} class, should mixin Inesita::Store" unless store.include?(Inesita::Store)
47
- @store = store.new.with_root_component(@root).with_router(@router).store
48
- @store.init
44
+ def setup_injections(injections)
45
+ return unless injections
46
+ return unless injections.is_a?(Hash)
47
+ injections.each do |key, value|
48
+ inject(key, value.new)
49
+ end
49
50
  end
50
51
  end
51
52
  end
@@ -2,10 +2,8 @@ module Inesita
2
2
  module Component
3
3
  include VirtualDOM::DOM
4
4
  include ComponentHelpers
5
- include ComponentProperties
6
5
  include ComponentVirtualDomExtension
7
-
8
- def init; end
6
+ include Injection
9
7
 
10
8
  def render
11
9
  raise Error, "Implement #render in #{self.class} component"
@@ -13,7 +11,7 @@ module Inesita
13
11
 
14
12
  def mount_to(element)
15
13
  raise Error, "Can't mount #{self.class}, target element not found!" unless element
16
- @root_component = self
14
+ inject(:root_component, self)
17
15
  @virtual_dom = render_virtual_dom
18
16
  @root_node = VirtualDOM.create(@virtual_dom)
19
17
  Browser.append_child(element, @root_node)
@@ -28,7 +26,10 @@ module Inesita
28
26
  @virtual_dom = new_virtual_dom
29
27
  end
30
28
 
29
+ def before_render; end;
30
+
31
31
  def render_virtual_dom
32
+ before_render
32
33
  @cache_component_counter = 0
33
34
  @__virtual_nodes__ = []
34
35
  render
@@ -39,14 +40,6 @@ module Inesita
39
40
  end
40
41
  end
41
42
 
42
- def render!
43
- Browser.animation_frame do
44
- if @root_component
45
- @root_component.render_if_root
46
- end
47
- end
48
- end
49
-
50
43
  def cache_component(component, &block)
51
44
  @cache_component ||= {}
52
45
  @cache_component_counter ||= 0
@@ -61,5 +54,11 @@ module Inesita
61
54
  def unhook(mthd)
62
55
  VirtualDOM::UnHook.method(method(mthd))
63
56
  end
57
+
58
+ attr_reader :props
59
+ def with_props(props)
60
+ @props = props
61
+ self
62
+ end
64
63
  end
65
64
  end
@@ -1,5 +1,14 @@
1
1
  module Inesita
2
2
  module ComponentHelpers
3
+ def inject(name, what)
4
+ Injection.class_eval do
5
+ define_method(name) do
6
+ what
7
+ end
8
+ end
9
+ what
10
+ end
11
+
3
12
  def class_names(hash)
4
13
  class_names = []
5
14
  hash.each do |key, value|
@@ -3,7 +3,7 @@ module Inesita
3
3
  def self.included(base)
4
4
  base.alias_method :__a, :a
5
5
  base.define_method(:a) do |params, &block|
6
- params = { onclick: -> { @router.go_to(params[:href]) } }.merge(params) if params[:href] && @router
6
+ params = { onclick: -> { router.go_to(params[:href]) } }.merge(params) if params[:href] && router
7
7
  __a(params, &block)
8
8
  end
9
9
  end
@@ -12,12 +12,7 @@ module Inesita
12
12
  raise Error, "Component is nil in #{self.class} class" if comp.nil?
13
13
  @__virtual_nodes__ ||= []
14
14
  @__virtual_nodes__ << cache_component(comp) do
15
- comp = (comp.is_a?(Class) ? comp.new : comp)
16
- .with_root_component(@root_component)
17
- .with_router(@router)
18
- .with_store(@store)
19
- comp.init
20
- comp
15
+ comp.is_a?(Class) ? comp.new : comp
21
16
  end.with_props(opts[:props] || {}).render_virtual_dom
22
17
  end
23
18
  end
@@ -0,0 +1,9 @@
1
+ module Inesita
2
+ module Injection
3
+ def render!
4
+ Browser.animation_frame do
5
+ root_component.render_if_root
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Inesita
2
+ module InjectionMethods
3
+ def render!
4
+ root_component.render!
5
+ end
6
+ end
7
+ end
@@ -3,7 +3,7 @@ module Inesita
3
3
  include Component
4
4
 
5
5
  def outlet
6
- @router
6
+ router
7
7
  end
8
8
  end
9
9
  end
@@ -1,23 +1,15 @@
1
1
  module Inesita
2
+ # TODO: Remove it.
2
3
  module Store
3
-
4
- def init; end
5
- def store; self end
6
-
7
- def render!
8
- root_component.render!
4
+ def self.included(base)
5
+ $console.warn('"include Inesita::Store" is deprecated. Use "include Inesita::Injection" insted.')
6
+ self.include Injection
9
7
  end
10
8
 
11
- attr_reader :root_component
12
- def with_root_component(component)
13
- @root_component = component
14
- self
15
- end
16
-
17
- attr_reader :router
18
- def with_router(router)
19
- @router = router
20
- self
9
+ def render!
10
+ Browser.animation_frame do
11
+ root_component.render_if_root
12
+ end
21
13
  end
22
14
  end
23
15
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Inesita::Application do
4
4
  let(:application) { Inesita::Application }
5
5
  let(:layout) { Class.new { include Inesita::Layout } }
6
- let(:store) { Class.new { include Inesita::Store } }
6
+ let(:injection) { Class.new { include Inesita::Injection } }
7
7
  let(:router) do
8
8
  Class.new do
9
9
  include Inesita::Router
@@ -38,11 +38,11 @@ describe Inesita::Application do
38
38
  expect { application.new(layout: layout) }.not_to raise_error
39
39
  end
40
40
 
41
- it 'should fail with wrong :store class' do
42
- expect { application.new(store: Class) }.to raise_error Inesita::Error
43
- end
44
-
45
41
  it 'should not fail with :layout class' do
46
42
  expect { application.new(router: router) }.not_to raise_error
47
43
  end
44
+
45
+ it 'should not fail with any class for injection' do
46
+ expect { application.new(test: injection) }.not_to raise_error
47
+ end
48
48
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Inesita::Injection do
4
+ let(:application) { Inesita::Application }
5
+ let(:injection) { Class.new { include Inesita::Injection } }
6
+
7
+ it 'should respond to #render!' do
8
+ expect(injection.new).to respond_to(:render!)
9
+ end
10
+
11
+ it 'should respond to #root_component' do
12
+ expect(injection.new).to respond_to(:root_component)
13
+ end
14
+
15
+ it 'should respond to injection name method' do
16
+ expect(application.new(test: injection)).to respond_to(:test)
17
+ end
18
+ end
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.4.4
4
+ version: 0.5.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: 2016-10-04 00:00:00.000000000 Z
11
+ date: 2016-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -214,9 +214,10 @@ files:
214
214
  - opal/inesita/browser.rb
215
215
  - opal/inesita/component.rb
216
216
  - opal/inesita/component_helpers.rb
217
- - opal/inesita/component_properties.rb
218
217
  - opal/inesita/component_virtual_dom_extension.rb
219
218
  - opal/inesita/error.rb
219
+ - opal/inesita/injection.rb
220
+ - opal/inesita/injection_methods.rb
220
221
  - opal/inesita/layout.rb
221
222
  - opal/inesita/router.rb
222
223
  - opal/inesita/routes.rb
@@ -225,10 +226,10 @@ files:
225
226
  - spec/lib/spec_helper.rb
226
227
  - spec/opal/application_spec.rb
227
228
  - spec/opal/component_spec.rb
229
+ - spec/opal/injecion_spec.rb
228
230
  - spec/opal/layout_spec.rb
229
231
  - spec/opal/router_spec.rb
230
232
  - spec/opal/spec_helper.rb
231
- - spec/opal/store_spec.rb
232
233
  homepage: http://github.com/inesita-rb/inesita
233
234
  licenses:
234
235
  - MIT
@@ -258,7 +259,7 @@ test_files:
258
259
  - spec/lib/spec_helper.rb
259
260
  - spec/opal/application_spec.rb
260
261
  - spec/opal/component_spec.rb
262
+ - spec/opal/injecion_spec.rb
261
263
  - spec/opal/layout_spec.rb
262
264
  - spec/opal/router_spec.rb
263
265
  - spec/opal/spec_helper.rb
264
- - spec/opal/store_spec.rb
@@ -1,27 +0,0 @@
1
- module Inesita
2
- module ComponentProperties
3
- attr_reader :root_component
4
- def with_root_component(component)
5
- @root_component = component
6
- self
7
- end
8
-
9
- attr_reader :router
10
- def with_router(router)
11
- @router = router
12
- self
13
- end
14
-
15
- attr_reader :store
16
- def with_store(store)
17
- @store = store
18
- self
19
- end
20
-
21
- attr_reader :props
22
- def with_props(props)
23
- @props = props
24
- self
25
- end
26
- end
27
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Inesita::Store do
4
- let(:store) { Class.new { include Inesita::Store } }
5
-
6
- it 'should respond to #store' do
7
- expect(store.new).to respond_to(:store)
8
- end
9
-
10
- it 'should respond to #render!' do
11
- expect(store.new).to respond_to(:render!)
12
- end
13
-
14
- it 'should respond to #with_root_component' do
15
- expect(store.new).to respond_to(:with_root_component)
16
- end
17
- end