cells 4.1.4 → 4.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/lib/cell/collection.rb +1 -1
- data/lib/cell/util.rb +1 -1
- data/lib/cell/version.rb +1 -1
- data/lib/cell/view_model.rb +13 -1
- data/test/context_test.rb +18 -7
- data/test/layout_test.rb +5 -8
- data/test/render_test.rb +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac9cc75f99da78dcad2d164973de3e4258a5d79d
|
4
|
+
data.tar.gz: 8043f9990c1a7414fe80edac59664243f0aa1f76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11a8edb6918e0b4b3eb0436dd52a230d40642e362c8342dc000c04fd7a140d78e34debacc9b0e713ee662869e6d9d4a2a079fbc531e4e019456f514d80ace5b7
|
7
|
+
data.tar.gz: 71e754860b9534b399e342a47140bca8fdc86dc97208f11d2f82b33ff61ebf31f31d66da3838dbd51f7310ba9b59fd7e6251b555f043c189ce20a6fd18e7be9b
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 4.1.5
|
2
|
+
|
3
|
+
* Fix a bug where nested calls of `cell(name, context: {...})` would ignore the new context elements, resulting in the old context being passed on. By adding `Context::[]` the new elements are now properly merged into a **new context hash**. This means that adding elements to the child context won't leak up into the parent context anymore.
|
4
|
+
|
1
5
|
## 4.1.4
|
2
6
|
|
3
7
|
* Upgrading to Uber 0.1 which handles builders a bit differently.
|
data/lib/cell/collection.rb
CHANGED
data/lib/cell/util.rb
CHANGED
data/lib/cell/version.rb
CHANGED
data/lib/cell/view_model.rb
CHANGED
@@ -60,6 +60,8 @@ module Cell
|
|
60
60
|
|
61
61
|
# Build nested cell in instance.
|
62
62
|
def cell(name, model=nil, options={})
|
63
|
+
context = Context[options[:context], self.context]
|
64
|
+
|
63
65
|
self.class.cell(name, model, options.merge(context: context))
|
64
66
|
end
|
65
67
|
|
@@ -67,10 +69,20 @@ module Cell
|
|
67
69
|
setup!(model, options)
|
68
70
|
end
|
69
71
|
|
70
|
-
def context
|
72
|
+
def context
|
71
73
|
@options[:context]
|
72
74
|
end
|
73
75
|
|
76
|
+
# DISCUSS: we could use the same mechanism as TRB::Skills here for speed at runtime?
|
77
|
+
class Context# < Hash
|
78
|
+
# Only dup&merge when :context was passed in parent.cell(context: ..)
|
79
|
+
# Otherwise we can simply pass on the old context.
|
80
|
+
def self.[](options, context)
|
81
|
+
return context unless options
|
82
|
+
context.dup.merge(options) # DISCUSS: should we create a real Context object here, to make it overridable?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
74
86
|
module Rendering
|
75
87
|
# Invokes the passed method (defaults to :show) while respecting caching.
|
76
88
|
# In Rails, the return value gets marked html_safe.
|
data/test/context_test.rb
CHANGED
@@ -15,19 +15,30 @@ class ContextTest < MiniTest::Spec
|
|
15
15
|
let (:user) { Object.new }
|
16
16
|
let (:controller) { Object.new }
|
17
17
|
|
18
|
-
|
19
|
-
cell = ParentCell.(model, admin: true, context: { user: user, controller: controller })
|
20
|
-
# cell.extend(ParentController)
|
18
|
+
let (:parent) { ParentCell.(model, admin: true, context: { user: user, controller: controller }) }
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
it do
|
21
|
+
parent.model.must_equal model
|
22
|
+
parent.controller.must_equal controller
|
23
|
+
parent.user.must_equal user
|
25
24
|
|
26
25
|
# nested cell
|
27
|
-
child =
|
26
|
+
child = parent.cell("context_test/parent", "")
|
28
27
|
|
29
28
|
child.model.must_equal ""
|
30
29
|
child.controller.must_equal controller
|
31
30
|
child.user.must_equal user
|
32
31
|
end
|
32
|
+
|
33
|
+
# child can add to context
|
34
|
+
it do
|
35
|
+
child = parent.cell(ParentCell, nil, context: { "is_child?" => true })
|
36
|
+
|
37
|
+
parent.context["is_child?"].must_equal nil
|
38
|
+
|
39
|
+
child.model.must_equal nil
|
40
|
+
child.controller.must_equal controller
|
41
|
+
child.user.must_equal user
|
42
|
+
child.context["is_child?"].must_equal true
|
43
|
+
end
|
33
44
|
end
|
data/test/layout_test.rb
CHANGED
@@ -42,7 +42,7 @@ end
|
|
42
42
|
class LayoutTest < MiniTest::Spec
|
43
43
|
# render show.haml calling method.
|
44
44
|
# same context as content view as layout call method.
|
45
|
-
it { SongWithLayoutCell.new(nil).show.must_equal "Merry Xmas, <b>Papertiger</b
|
45
|
+
it { SongWithLayoutCell.new(nil).show.must_equal "Merry Xmas, <b>Papertiger</b>" }
|
46
46
|
|
47
47
|
# raises exception when layout not found!
|
48
48
|
|
@@ -51,7 +51,7 @@ class LayoutTest < MiniTest::Spec
|
|
51
51
|
it { }
|
52
52
|
|
53
53
|
# with ::layout.
|
54
|
-
it { SongWithLayoutOnClassCell.new(nil).show.must_equal "Merry Xmas, <b>Papertiger</b
|
54
|
+
it { SongWithLayoutOnClassCell.new(nil).show.must_equal "Merry Xmas, <b>Papertiger</b>" }
|
55
55
|
|
56
56
|
# with ::layout and :layout, :layout wins.
|
57
57
|
it { SongWithLayoutOnClassCell.new(nil).show_with_layout.must_equal "Happy Friday!" }
|
@@ -75,17 +75,14 @@ end
|
|
75
75
|
class ExternalLayoutTest < Minitest::Spec
|
76
76
|
it do
|
77
77
|
Comment::ShowCell.new(nil, layout: Comment::LayoutCell, context: { beer: true }).
|
78
|
-
().must_equal "$layout.erb{$show.erb, {:beer=>true}
|
78
|
+
().must_equal "$layout.erb{$show.erb, {:beer=>true}$show.erb, {:beer=>true}, {:beer=>true}}
|
79
|
+
"
|
79
80
|
end
|
80
81
|
|
81
82
|
# collection :layout
|
82
83
|
it do
|
83
84
|
Cell::ViewModel.cell("comment/show", collection: [Object, Module], layout: Comment::LayoutCell).().
|
84
|
-
must_equal "$layout.erb{$show.erb, nil
|
85
|
-
$show.erb, nil
|
86
|
-
$show.erb, nil
|
87
|
-
$show.erb, nil
|
88
|
-
, nil}
|
85
|
+
must_equal "$layout.erb{$show.erb, nil$show.erb, nil$show.erb, nil$show.erb, nil, nil}
|
89
86
|
"
|
90
87
|
end
|
91
88
|
end
|
data/test/render_test.rb
CHANGED
@@ -59,19 +59,19 @@ end
|
|
59
59
|
|
60
60
|
class RenderTest < MiniTest::Spec
|
61
61
|
# render show.haml calling method, implicit render.
|
62
|
-
it { SongCell.new(nil).show.must_equal "Papertiger
|
62
|
+
it { SongCell.new(nil).show.must_equal "Papertiger" }
|
63
63
|
|
64
64
|
# render ivar.haml using instance variable.
|
65
|
-
it { SongCell.new(nil).ivar.must_equal "Carnage
|
65
|
+
it { SongCell.new(nil).ivar.must_equal "Carnage" }
|
66
66
|
|
67
67
|
# render string.
|
68
68
|
it { SongCell.new(nil).string.must_equal "Right" }
|
69
69
|
|
70
70
|
# #call renders :show
|
71
|
-
it { SongCell.new(nil).call.must_equal "Papertiger
|
71
|
+
it { SongCell.new(nil).call.must_equal "Papertiger" }
|
72
72
|
|
73
73
|
# call(:form) renders :form
|
74
|
-
it { SongCell.new(nil).call(:with_view_name).must_equal "Man Of Steel
|
74
|
+
it { SongCell.new(nil).call(:with_view_name).must_equal "Man Of Steel" }
|
75
75
|
|
76
76
|
# works with state called `send`
|
77
77
|
it { SongCell.new(nil).call(:send).must_equal "send" }
|
@@ -83,10 +83,10 @@ class RenderTest < MiniTest::Spec
|
|
83
83
|
end
|
84
84
|
|
85
85
|
# allows locals
|
86
|
-
it { SongCell.new(nil).with_locals.must_equal "Shot Across The
|
86
|
+
it { SongCell.new(nil).with_locals.must_equal "Shot Across The Bow280" }
|
87
87
|
|
88
88
|
# render :form is a shortcut.
|
89
|
-
it { SongCell.new(nil).with_view_name.must_equal "Man Of Steel
|
89
|
+
it { SongCell.new(nil).with_view_name.must_equal "Man Of Steel" }
|
90
90
|
|
91
91
|
# :template_engine renders ERB.
|
92
92
|
# it { SongCell.new(nil).with_erb.must_equal "ERB:\n<span>\n Papertiger\n</span>" }
|
@@ -102,7 +102,7 @@ class RenderTest < MiniTest::Spec
|
|
102
102
|
it { SongCell.new(nil).call(:with_html).must_equal "<p>Yew!</p>" }
|
103
103
|
|
104
104
|
# render {} with block
|
105
|
-
it { SongCell.new(nil).with_block.must_equal "Yo! Clean Sheets<p>Yew!</p
|
105
|
+
it { SongCell.new(nil).with_block.must_equal "Yo! Clean Sheets<p>Yew!</p>" }
|
106
106
|
end
|
107
107
|
|
108
108
|
# test inheritance
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cells
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uber
|