pbbuilder 0.7.0 → 0.8.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
  SHA256:
3
- metadata.gz: 83ca08d74d2463d2d14d5d57127e482a0ea9fde4a0cdcaac3f237c3a8f48ff23
4
- data.tar.gz: 828fe17a1b1be0feab98d7cc68940350df6093d0995751e0873c46d9a363f487
3
+ metadata.gz: e22f13cb28a04d0b767c619b7c63c91e86a246d524abc200e5062d92cadb977e
4
+ data.tar.gz: b323e88b227263bfbd4ebc8b0e50f05208afe24527a2069e1110a6a605e453cb
5
5
  SHA512:
6
- metadata.gz: 2c4285699991af59101b07e3e04dd987620065362febdc8623d62390b15a17fd2660031f9e3a4cc3eb602609504ab70cde82848012fc061759124a706809fd3a
7
- data.tar.gz: 214263e610fc46ab2bf978f17dd3dc8633ae757af8859906c4c588827c00e383b542ac749b5f9e089ede8401153a54629b82e83a29d5c212043965c70035fc58
6
+ metadata.gz: c245be23b0283a134b1dc28b1ab29d96bd9ca0023456f9e984ff3406b164f057147ab9e366bdcf150236fe494417ef182480cc1d89a53880c684403efb60bb95
7
+ data.tar.gz: e4c4bbd500f921b0b2a71a7fc0e23ec99ea005a872f7f0d66a72f04cca712de54ef3e4898023bf22880eedb9afe990d9fac54dfce62ae164fd4c0b267bfc03bb
@@ -27,12 +27,20 @@ class PbbuilderTemplate < Pbbuilder
27
27
  end
28
28
 
29
29
  def set!(field, *args, **kwargs, &block)
30
- # If partial options are being passed, we assume a collection is being rendered with a partial for every element
31
- # pb.friends @friends, partial: "friend", as: :friend
32
- if args.one? && _partial_options?(kwargs)
33
- # Call set! on the super class, passing in a block that renders a partial for every element
34
- super(field, *args) do |element|
35
- _set_inline_partial(element, kwargs)
30
+ # If partial options are being passed, we render a submessage with a partial
31
+ if kwargs.has_key?(:partial)
32
+ if args.one? && kwargs.has_key?(:as)
33
+ # pb.friends @friends, partial: "friend", as: :friend
34
+ # Call set! on the super class, passing in a block that renders a partial for every element
35
+ super(field, *args) do |element|
36
+ _set_inline_partial(element, kwargs)
37
+ end
38
+ else
39
+ # pb.best_friend partial: "person", person: @best_friend
40
+ # Call set! as a submessage, passing in the kwargs as partial options
41
+ super(field, *args) do
42
+ _render_partial_with_options(kwargs)
43
+ end
36
44
  end
37
45
  else
38
46
  super
@@ -41,10 +49,6 @@ class PbbuilderTemplate < Pbbuilder
41
49
 
42
50
  private
43
51
 
44
- def _partial_options?(options)
45
- ::Hash === options && options.key?(:as) && options.key?(:partial)
46
- end
47
-
48
52
  def _is_active_model?(object)
49
53
  object.class.respond_to?(:model_name) && object.respond_to?(:to_partial_path)
50
54
  end
data/pbbuilder.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "pbbuilder"
3
- spec.version = "0.7.0"
3
+ spec.version = "0.8.0"
4
4
  spec.authors = ["Bouke van der Bijl"]
5
5
  spec.email = ["bouke@cheddar.me"]
6
6
  spec.homepage = "https://github.com/cheddar-me/pbbuilder"
@@ -9,9 +9,7 @@ class PbbuilderTemplateTest < ActiveSupport::TestCase
9
9
  RACER_PARTIAL = <<-PBBUILDER
10
10
  pb.extract! racer, :name
11
11
  pb.friends racer.friends, partial: "racers/racer", as: :racer
12
- pb.best_friend do
13
- pb.partial! "racers/racer", racer: racer.best_friend
14
- end if racer.best_friend.present?
12
+ pb.best_friend partial: "racers/racer", racer: racer.best_friend if racer.best_friend.present?
15
13
  PBBUILDER
16
14
 
17
15
  PARTIALS = {
@@ -33,6 +31,18 @@ class PbbuilderTemplateTest < ActiveSupport::TestCase
33
31
  assert_equal "hello", result.name
34
32
  end
35
33
 
34
+ test "submessage partial" do
35
+ other_racer = Racer.new(2, "Max Verstappen", [])
36
+ racer = Racer.new(123, "Chris Harris", [], other_racer)
37
+ result = render('pb.best_friend partial: "person", person: @racer.best_friend', racer: racer)
38
+ assert_equal "Max Verstappen", result.best_friend.name
39
+ end
40
+
41
+ test "hash" do
42
+ result = render('pb.favourite_foods "pizza" => "yes"')
43
+ assert_equal({"pizza" => "yes"}, result.favourite_foods.to_h)
44
+ end
45
+
36
46
  test "partial by name with nested locals" do
37
47
  result = render('pb.partial! "partial", locals: { name: "hello" }')
38
48
  assert_equal "hello", result.name
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pbbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bouke van der Bijl