prawn_cocktail 0.5.4 → 0.6.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.
- data/README.md +9 -5
- data/lib/prawn_cocktail/document.rb +6 -6
- data/lib/prawn_cocktail/renderer.rb +3 -3
- data/lib/prawn_cocktail/version.rb +1 -1
- data/spec/fixtures/document.rb +2 -2
- data/spec/integration_spec.rb +0 -1
- metadata +10 -10
data/README.md
CHANGED
@@ -112,19 +112,19 @@ module BaseDocumentHelper
|
|
112
112
|
end
|
113
113
|
```
|
114
114
|
|
115
|
-
Any loaded module can be used as a helper, as long as its
|
115
|
+
Any loaded module can be used as a helper, as long as its methods can run in the context of a Prawn document.
|
116
116
|
|
117
117
|
If you use `PrawnCocktailRails`, you can put modules in `app/documents/helpers`, e.g. `app/documents/helpers/base_document_helper.rb`, and they will be autoloaded.
|
118
118
|
|
119
119
|
Note that you must explicitly declare the helpers you want. No helpers are automatically included. You can declare base helpers in a base document class, though, and they will be inherited.
|
120
120
|
|
121
|
-
### `
|
121
|
+
### `initialize_template`
|
122
122
|
|
123
|
-
If you want to run some code in every
|
123
|
+
If you want to run some code in every template, use an `initialize_template` block:
|
124
124
|
|
125
125
|
``` ruby
|
126
126
|
class BaseDocument < PrawnCocktail::Document
|
127
|
-
|
127
|
+
initialize_template do
|
128
128
|
font "Courier"
|
129
129
|
end
|
130
130
|
end
|
@@ -134,10 +134,14 @@ This is incidentally how helpers are implemented:
|
|
134
134
|
|
135
135
|
```
|
136
136
|
def self.helper(mod)
|
137
|
-
|
137
|
+
initialize_template { extend mod }
|
138
138
|
end
|
139
139
|
```
|
140
140
|
|
141
|
+
You can have any number of template initializers, not just one.
|
142
|
+
|
143
|
+
Template initializers in a superclass are inherited by subclasses, and the subclass can add its own.
|
144
|
+
|
141
145
|
## Installation
|
142
146
|
|
143
147
|
Add this line to your application's Gemfile:
|
@@ -6,15 +6,15 @@ require_relative "renderer"
|
|
6
6
|
|
7
7
|
module PrawnCocktail
|
8
8
|
class Document
|
9
|
-
class_attribute :
|
10
|
-
self.
|
9
|
+
class_attribute :initializers
|
10
|
+
self.initializers = []
|
11
11
|
|
12
|
-
def self.
|
13
|
-
self.
|
12
|
+
def self.initialize_template(&block)
|
13
|
+
self.initializers += [block]
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.helper(mod)
|
17
|
-
|
17
|
+
initialize_template { extend mod }
|
18
18
|
end
|
19
19
|
|
20
20
|
def render
|
@@ -33,7 +33,7 @@ module PrawnCocktail
|
|
33
33
|
private
|
34
34
|
|
35
35
|
def renderer
|
36
|
-
@renderer ||= Renderer.new(template_name, data, self.class.
|
36
|
+
@renderer ||= Renderer.new(template_name, data, self.class.initializers)
|
37
37
|
end
|
38
38
|
|
39
39
|
def template_name
|
@@ -2,10 +2,10 @@ require_relative "template"
|
|
2
2
|
|
3
3
|
module PrawnCocktail
|
4
4
|
class Renderer
|
5
|
-
def initialize(template_name, data,
|
5
|
+
def initialize(template_name, data, initializers)
|
6
6
|
@template_name = template_name
|
7
7
|
@data = data
|
8
|
-
@
|
8
|
+
@initializers = initializers
|
9
9
|
end
|
10
10
|
|
11
11
|
def meta(opts)
|
@@ -13,7 +13,7 @@ module PrawnCocktail
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def content(&block)
|
16
|
-
@
|
16
|
+
@initializers.each do |proc|
|
17
17
|
prawn_document.instance_eval(&proc)
|
18
18
|
end
|
19
19
|
|
data/spec/fixtures/document.rb
CHANGED
@@ -6,7 +6,7 @@ end
|
|
6
6
|
|
7
7
|
class TestDocument < PrawnCocktail::Document
|
8
8
|
helper TestDocumentHelper
|
9
|
-
|
9
|
+
initialize_template { text "Init works." }
|
10
10
|
|
11
11
|
def initialize(status)
|
12
12
|
@status = status
|
@@ -20,5 +20,5 @@ class TestDocument < PrawnCocktail::Document
|
|
20
20
|
end
|
21
21
|
|
22
22
|
class SubTestDocument < TestDocument
|
23
|
-
|
23
|
+
initialize_template { text "Sub-init works." }
|
24
24
|
end
|
data/spec/integration_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn_cocktail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: prawn
|
16
|
-
requirement: &
|
16
|
+
requirement: &70112015079480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70112015079480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &70112015095380 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70112015095380
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70112015094900 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70112015094900
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: pdf-inspector
|
49
|
-
requirement: &
|
49
|
+
requirement: &70112015094400 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70112015094400
|
58
58
|
description:
|
59
59
|
email:
|
60
60
|
- henrik@barsoom.se
|