pbbuilder 0.7.0 → 0.8.0
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 +4 -4
- data/lib/pbbuilder/template.rb +14 -10
- data/pbbuilder.gemspec +1 -1
- data/test/pbbuilder_template_test.rb +13 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e22f13cb28a04d0b767c619b7c63c91e86a246d524abc200e5062d92cadb977e
|
4
|
+
data.tar.gz: b323e88b227263bfbd4ebc8b0e50f05208afe24527a2069e1110a6a605e453cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c245be23b0283a134b1dc28b1ab29d96bd9ca0023456f9e984ff3406b164f057147ab9e366bdcf150236fe494417ef182480cc1d89a53880c684403efb60bb95
|
7
|
+
data.tar.gz: e4c4bbd500f921b0b2a71a7fc0e23ec99ea005a872f7f0d66a72f04cca712de54ef3e4898023bf22880eedb9afe990d9fac54dfce62ae164fd4c0b267bfc03bb
|
data/lib/pbbuilder/template.rb
CHANGED
@@ -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
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
@@ -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
|
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
|