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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a86688cd5527e045dc5c369601748ad37bf23dee
4
- data.tar.gz: 71f61f1b7b909f8eaa80673fef462e8c21f85fd9
3
+ metadata.gz: ac9cc75f99da78dcad2d164973de3e4258a5d79d
4
+ data.tar.gz: 8043f9990c1a7414fe80edac59664243f0aa1f76
5
5
  SHA512:
6
- metadata.gz: 20509fd3dd471cfe6019b6f933d8aba0ae45b19268b765ba2c4c6dfa7cf81e8a916a0a00920619e5b0cb519a05bb24a4b33ae0dbd1739d64e8a7ec510fdb86a1
7
- data.tar.gz: cd0e8ed5e41833f4110f949b0ae49b7c58dc270ae5e87c48186295663370e16c4899948a94cac0bf508e67e893e6556f834d046cf8f9526c8d924c1bc9004c09
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.
@@ -5,7 +5,7 @@ module Cell
5
5
  set_deprecated_options(options) # TODO: remove in 5.0.
6
6
 
7
7
  @ary = ary
8
- @options = options
8
+ @options = options # these options are "final" and will be identical for all collection cells.
9
9
  @cell_class = cell_class
10
10
  end
11
11
 
@@ -19,7 +19,7 @@ module Cell::Util
19
19
  part.split('_').collect(&:capitalize).join
20
20
  end.join('::')
21
21
 
22
- Object.const_get(class_name)
22
+ Object.const_get(class_name, false)
23
23
  end
24
24
  end
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module Cell
2
- VERSION = "4.1.4"
2
+ VERSION = "4.1.5"
3
3
  end
@@ -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 # TODO: explicit test.
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.
@@ -15,19 +15,30 @@ class ContextTest < MiniTest::Spec
15
15
  let (:user) { Object.new }
16
16
  let (:controller) { Object.new }
17
17
 
18
- it do
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
- cell.model.must_equal model
23
- cell.controller.must_equal controller
24
- cell.user.must_equal user
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 = cell.cell("context_test/parent", "")
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
@@ -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>\n" }
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>\n" }
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}\n$show.erb, {:beer=>true}\n, {:beer=>true}}\n"
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
@@ -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\n" }
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\n" }
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\n" }
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\n" }
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 Bow\n280\n" }
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\n" }
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>\n" }
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
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-10 00:00:00.000000000 Z
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber