prawn_cocktail 0.3.1 → 0.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # PrawnCocktail
2
2
 
3
- Simple views, templates and helpers on top of Prawn in Ruby on Rails.
3
+ Simple documents, templates and helpers on top of Prawn in Ruby on Rails.
4
4
 
5
5
  Because writing Prawn documents PHP 4 style is no fun.
6
6
 
@@ -18,6 +18,14 @@ NOTE: Work in progress; well used but untested.
18
18
 
19
19
  ## Usage
20
20
 
21
+ ### Configuration
22
+
23
+ You can change where PrawnCocktail looks for its templates. This is the default:
24
+
25
+ ``` ruby
26
+ PrawnCocktail.template_root = "app/views/documents"
27
+ ```
28
+
21
29
  ### Controller
22
30
 
23
31
  Your controllers get a `send_pdf` method:
@@ -32,11 +40,9 @@ class InvoicesController < ApplicationController
32
40
  end
33
41
  ```
34
42
 
35
- ### Document/view
36
-
37
- Against Rails conventions, but in line with the idea of [two-step views](http://martinfowler.com/eaaCatalog/twoStepView.html), we think of these as "views" as opposed to "templates".
43
+ ### Document
38
44
 
39
- Build your view data in a document class:
45
+ The document class provides a data hash for the template, and optionally a filename:
40
46
 
41
47
  ``` ruby
42
48
  # app/documents/invoice_document.rb
@@ -64,13 +70,15 @@ end
64
70
 
65
71
  The document has `render` and `render_file(name)` methods, just like `Prawn::Document`.
66
72
 
67
- The filename, if defined, is used when generating the document. The `data` value is passed to the template as an `OpenStruct`.
73
+ The filename, if defined, is used by `send_pdf` in the controller. You might also want to use it with mail attachments, scripts etc.
74
+
75
+ The `data` value is passed to the template as an `OpenStruct`.
68
76
 
69
77
  If the data becomes complex, you are advised to extract one or many builder classes like `InvoiceDocument::Data` and call those from `data`.
70
78
 
71
79
  ### Template
72
80
 
73
- Put the Prawn code in a template named after the view:
81
+ Put the Prawn code in a template named after the document:
74
82
 
75
83
  ``` ruby
76
84
  # app/views/documents/invoice_document.pdf.rb
@@ -0,0 +1,9 @@
1
+ module PrawnCocktail
2
+ class << self
3
+ attr_accessor :template_root
4
+ end
5
+
6
+ # Defaults.
7
+
8
+ self.template_root = "app/views/documents"
9
+ end
@@ -31,7 +31,6 @@ module PrawnCocktail
31
31
  private
32
32
 
33
33
  def render
34
- # We pass the filename for better backtraces.
35
34
  instance_eval(read_template, template_path)
36
35
  end
37
36
 
@@ -44,15 +43,15 @@ module PrawnCocktail
44
43
  end
45
44
 
46
45
  def read_template
47
- File.read(File.join(app_root, template_path))
46
+ File.read(template_path)
48
47
  end
49
48
 
50
49
  def template_path
51
- "app/views/documents/#{@template}.pdf.rb"
50
+ File.join(template_root, "#{@template}.pdf.rb")
52
51
  end
53
52
 
54
- def app_root
55
- Rails.root
53
+ def template_root
54
+ PrawnCocktail.template_root
56
55
  end
57
56
  end
58
57
  end
@@ -1,3 +1,3 @@
1
1
  module PrawnCocktail
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "prawn_cocktail/version"
2
+ require "prawn_cocktail/configuration"
2
3
  require "prawn_cocktail/controller"
3
4
  require "prawn_cocktail/document"
4
5
  require "prawn_cocktail/railtie"
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.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: prawn
16
- requirement: &70270245325880 !ruby/object:Gem::Requirement
16
+ requirement: &70228826573820 !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: *70270245325880
24
+ version_requirements: *70228826573820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70270245325220 !ruby/object:Gem::Requirement
27
+ requirement: &70228826573200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70270245325220
35
+ version_requirements: *70228826573200
36
36
  description:
37
37
  email:
38
38
  - henrik@barsoom.se
@@ -45,6 +45,7 @@ files:
45
45
  - README.md
46
46
  - Rakefile
47
47
  - lib/prawn_cocktail.rb
48
+ - lib/prawn_cocktail/configuration.rb
48
49
  - lib/prawn_cocktail/controller.rb
49
50
  - lib/prawn_cocktail/document.rb
50
51
  - lib/prawn_cocktail/railtie.rb