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 +4 -4
- data/lib/phlex/pdf/version.rb +1 -1
- data/lib/phlex/pdf.rb +27 -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: 670aa939ab2505d3783c38b9070adbce93e1ddf67c041c726efd7b4efed5296f
|
4
|
+
data.tar.gz: c1e31b9053d69c43c0fac102637fd2d63be0ef9e7f2002e33da8e2419462b90e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e815d9f10d1f527d51c250021060354dedbe7ba09153aa7ecd043b02a6e7bb9eba93932f30b2519c3649f4d689961fd6987fe93665b69617d69408e2f2c67cb6
|
7
|
+
data.tar.gz: 3f2283f3b9a6965a34cf08ff7b169b425e493de5f40591e2ed45e09602004953dc00a8a0e639b413f241dd503a693847582a8e41ced0454bdcf52ee149cff22b
|
data/lib/phlex/pdf/version.rb
CHANGED
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
|
-
|
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
|