phlex-pdf 0.1.1 → 0.1.2

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: 3ed0d33ef620bd813370875bbe924058ebaea8cb3788d9945a0f56bb909cd468
4
- data.tar.gz: 1fef48340c15401133fbc9a9fb90482996b3edd0382b94dd6be97611a1a533b4
3
+ metadata.gz: 670aa939ab2505d3783c38b9070adbce93e1ddf67c041c726efd7b4efed5296f
4
+ data.tar.gz: c1e31b9053d69c43c0fac102637fd2d63be0ef9e7f2002e33da8e2419462b90e
5
5
  SHA512:
6
- metadata.gz: c1a8850366e024fad4342f07c4c11c5525cb6b253603767ee79e825e1cb9c58ff6d2d46283b039504bee2f8f68ce36f5659e2b109a87f23749bee76d267b487c
7
- data.tar.gz: d3df818ae52444f7799b7f33099f4d570caac8e5132f55401c2df646513377476883f45c41e4c9308eb884b277f48eff9fae7a8b1867d1f9120e0ff8937e331b
6
+ metadata.gz: e815d9f10d1f527d51c250021060354dedbe7ba09153aa7ecd043b02a6e7bb9eba93932f30b2519c3649f4d689961fd6987fe93665b69617d69408e2f2c67cb6
7
+ data.tar.gz: 3f2283f3b9a6965a34cf08ff7b169b425e493de5f40591e2ed45e09602004953dc00a8a0e639b413f241dd503a693847582a8e41ced0454bdcf52ee149cff22b
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlex
4
4
  module Pdf
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
data/lib/phlex/pdf.rb CHANGED
@@ -13,7 +13,13 @@ module Phlex
13
13
  def call(document, &block)
14
14
  @document = document
15
15
  around_template do
16
- view_template(&block)
16
+ if block_given?
17
+ view_template do
18
+ yield_content(&block)
19
+ end
20
+ else
21
+ view_template
22
+ end
17
23
  end
18
24
  end
19
25
 
@@ -38,12 +44,30 @@ module Phlex
38
44
  nil
39
45
  end
40
46
 
47
+ def yield_content(&block)
48
+ return unless block_given?
49
+
50
+ if block.arity.zero?
51
+ # This handles lambdas and ->
52
+ yield
53
+ else
54
+ # This handles Proc and proc
55
+ yield self
56
+ end
57
+ end
58
+
41
59
  def render(renderable, &block)
42
60
  case renderable
43
- when String
44
- @document.text renderable
45
61
  when Phlex::PDF
46
62
  renderable.call(@document, &block)
63
+ when String
64
+ @document.text renderable
65
+ when Class
66
+ render(renderable.new, &block) if renderable < Phlex::PDF
67
+ when Proc, Method
68
+ yield_content(&renderable)
69
+ when Enumerable
70
+ renderable.each { |r| render(r, &block) }
47
71
  else
48
72
  raise ArgumentError, "You can't render a #{renderable.inspect}."
49
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex-pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler