prawn_cocktail 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
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 code can be run in the context of a Prawn document.
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
- ### `initialize_document`
121
+ ### `initialize_template`
122
122
 
123
- If you want to run some code in every document, use an `initialize_document` block:
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
- initialize_document do
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
- initialize_document { extend mod }
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 :doc_initializers
10
- self.doc_initializers = []
9
+ class_attribute :initializers
10
+ self.initializers = []
11
11
 
12
- def self.initialize_document(&block)
13
- self.doc_initializers += [block]
12
+ def self.initialize_template(&block)
13
+ self.initializers += [block]
14
14
  end
15
15
 
16
16
  def self.helper(mod)
17
- initialize_document { extend mod }
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.doc_initializers)
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, doc_initializers)
5
+ def initialize(template_name, data, initializers)
6
6
  @template_name = template_name
7
7
  @data = data
8
- @doc_initializers = doc_initializers
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
- @doc_initializers.each do |proc|
16
+ @initializers.each do |proc|
17
17
  prawn_document.instance_eval(&proc)
18
18
  end
19
19
 
@@ -1,3 +1,3 @@
1
1
  module PrawnCocktail
2
- VERSION = "0.5.4"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -6,7 +6,7 @@ end
6
6
 
7
7
  class TestDocument < PrawnCocktail::Document
8
8
  helper TestDocumentHelper
9
- initialize_document { text "Init works." }
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
- initialize_document { text "Sub-init works." }
23
+ initialize_template { text "Sub-init works." }
24
24
  end
@@ -51,7 +51,6 @@ describe PrawnCocktail do
51
51
  end
52
52
  end
53
53
 
54
-
55
54
  def assert_document_has_the_right_contents
56
55
  assert_equal(
57
56
  [ "Init works.", "Test document", "Status: success" ],
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.5.4
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-23 00:00:00.000000000 Z
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: &70243544258740 !ruby/object:Gem::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: *70243544258740
24
+ version_requirements: *70112015079480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &70243544274560 !ruby/object:Gem::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: *70243544274560
35
+ version_requirements: *70112015095380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70243544274080 !ruby/object:Gem::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: *70243544274080
46
+ version_requirements: *70112015094900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pdf-inspector
49
- requirement: &70243544273600 !ruby/object:Gem::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: *70243544273600
57
+ version_requirements: *70112015094400
58
58
  description:
59
59
  email:
60
60
  - henrik@barsoom.se