gbdev-pdf_filler 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -64,18 +64,37 @@ Another alternative is to install pdf_filler as a Rails plugin:
64
64
 
65
65
  1. You will need a PDF that has form fields to fill.
66
66
 
67
- 2. A hash of parameters for filling the PDF form. The hash must contain all of the required options:
68
- * :data (required) - A hash or array of hashes of fields to fill the pdf template with. Example: [{:field => 'value'}, {:field => 'value'}].
69
- * :template (required) - The full path to the PDF form to fill.
70
- * :dir (required) - The directory to write filled form to.
71
- * :file_name (optional) The name of the output file to create. If not specified a random file name will be used.
72
-
73
- 3. Example
74
- opts = {:data => {:full_name => 'Wes Hays'},
75
- :template => '/path/to/templates/certificate_template.pdf'),
76
- :dir => '/path/to/templates/output/'),
77
- :file_name => 'wes_hays.pdf'}
78
- PdfFiller(opts)
67
+ 2. A writable directory to store the generated PDFs.
68
+
69
+ 3. For a single page use the Page object?
70
+
71
+ // ** Single page **
72
+ page = GBDev::PDF::Page.new('/path/to/template.pdf')
73
+ page.set_text(:full_name, 'Wes Hays')
74
+ page.save_to('/path/to/save.pdf')
75
+
76
+ 4. For a collection of pages to be added to a single PDF use a Book object.
77
+
78
+ book = GBDev::PDF::Book.new
79
+
80
+ page1 = GBDev::PDF::Page.new('/path/to/template1.pdf')
81
+ page1.set_text(:full_name, 'Wes Hays')
82
+
83
+ page2 = GBDev::PDF::Page.new('/path/to/template2.pdf')
84
+ page2.set_text(:full_name, 'Darren Johnson')
85
+
86
+ book.add_page(page1)
87
+ book.add_page(page2)
88
+
89
+ book.save_to('/page/to/book.pdf')
90
+
91
+
92
+ Note: You can use the shorter kernel methods PDFPage instead of GBDev::PDF::Page.new. The same goes for PDFBook instead of GBDev::PDF::Book.new.
93
+
94
+ Example:
95
+
96
+ page = PDFPage('/path/to/template.pdf')
97
+ book = PDFBook()
79
98
 
80
99
 
81
100
  == License
@@ -15,18 +15,32 @@ Paragraph = Rjb::import('com.lowagie.text.Paragraph')
15
15
  AcroFields = Rjb::import('com.lowagie.text.pdf.AcroFields')
16
16
  PdfStamper = Rjb::import('com.lowagie.text.pdf.PdfStamper')
17
17
  HashMap = Rjb::import('java.util.HashMap')
18
+ Iterator = Rjb::import('java.util.Iterator')
18
19
 
19
20
  require 'pdf_filler/util_methods'
20
21
  require 'pdf_filler/page'
21
22
  require 'pdf_filler/book'
23
+ require 'pdf_filler/pdf_db_mapper'
22
24
 
23
25
 
24
26
  module Kernel
25
27
 
28
+ # A shortcut kernel method for creating a new PDF Page without having to specify the full path to the page.
29
+ # Therefore,
30
+ # * PDFPage(template)
31
+ # and
32
+ # * GBDev::PDF::Page.new(template)
33
+ # are the same thing.
26
34
  def PDFPage(template)
27
35
  GBDev::PDF::Page.new(template)
28
36
  end
29
37
 
38
+ # A shortcut kernel method for creating a new PDF Book without having to specify the full path to the book.
39
+ # Therefore,
40
+ # * PDFBook()
41
+ # and
42
+ # * GBDev::PDF::Book.new
43
+ # are the same thing.
30
44
  def PDFBook()
31
45
  GBDev::PDF::Book.new
32
46
  end
@@ -10,13 +10,15 @@ module GBDev
10
10
  end
11
11
 
12
12
  # Add a page to the book
13
+ #
14
+ # * new_page - The page object of type GBDev::PDF::Page
13
15
  def add_page(new_page)
14
16
  @pages << new_page
15
17
  end
16
18
 
17
- # Renders the book with the given pages and saves to the given filename path.
19
+ # Renders the PDF Book and saves it to the specified file.
18
20
  #
19
- # String filename : A path to the file to be created.
21
+ # * filename - A path to the file to be created.
20
22
  def save_to(filename)
21
23
  dir = File.dirname(filename)
22
24
  temp_dir = [dir, "collection_temp_#{build_random_string}"].join('/')
@@ -42,9 +44,13 @@ module GBDev
42
44
  FileUtils.rm_rf(temp_dir, {:secure => true})
43
45
  end
44
46
 
47
+ # Renders the PDF Book without saving it to disk and displays it in the browser.
45
48
  def display
46
49
  end
47
50
 
51
+ # Renders the PDF Book, saves it to the specified file and then displays the PDF in the browser.
52
+ #
53
+ # * filename - A path to the file to be created.
48
54
  def save_and_display(filename)
49
55
  save(filename)
50
56
  display
@@ -5,56 +5,214 @@ module GBDev
5
5
  # A page that represents a PDF page.
6
6
  class Page
7
7
 
8
+ CHECK_BOX = 'Check Box'
9
+ COMBO_BOX = 'Combo Box'
10
+ LIST = 'List'
11
+ PUSH_BUTTON = 'Push Button'
12
+ RADIO_BUTTON = 'Radio Button'
13
+ SIGNATURE = 'Signature'
14
+ TEXT_FIELD = 'Text Field'
15
+ NONE = 'None'
16
+ UNKNOWN = '?'
17
+
8
18
  # String template : A path to the template file
9
19
  def initialize(template)
10
20
  @template = template
11
- @fields = {}
21
+
22
+ @pdf_fields = {}
23
+
24
+ @check_boxes = {}
12
25
  @images = {}
26
+ @radio_buttons = {}
27
+ @signature_fields = {}
28
+ @text_fields = {}
13
29
  end
14
30
 
15
- # Sets a known text field in the PDF template.
31
+ # Returns a hash where the keys are the field names in the template PDF and the values are the field types.
32
+ def get_pdf_fields
33
+ return @pdf_fields unless @pdf_fields.empty?
34
+
35
+ reader = PdfReader.new(@template)
36
+ form = reader.getAcroFields()
37
+ fields = form.getFields()
38
+ i = fields.keySet().iterator()
39
+
40
+ while(i.hasNext())
41
+ key = i.next()
42
+
43
+ case(form.getFieldType(key))
44
+ when AcroFields.FIELD_TYPE_CHECKBOX
45
+ @pdf_fields[key.to_string().to_sym] = GBDev::PDF::Page::CHECK_BOX
46
+ when AcroFields.FIELD_TYPE_COMBO
47
+ @pdf_fields[key.to_string().to_sym] = GBDev::PDF::Page::COMBO_BOX
48
+ when AcroFields.FIELD_TYPE_LIST
49
+ @pdf_fields[key.to_string().to_sym] = GBDev::PDF::Page::LIST
50
+ when AcroFields.FIELD_TYPE_NONE
51
+ @pdf_fields[key.to_string().to_sym] = GBDev::PDF::Page::NONE
52
+ when AcroFields.FIELD_TYPE_PUSHBUTTON
53
+ @pdf_fields[key.to_string().to_sym] = GBDev::PDF::Page::PUSH_BUTTON
54
+ when AcroFields.FIELD_TYPE_RADIOBUTTON
55
+ @pdf_fields[key.to_string().to_sym] = GBDev::PDF::Page::RADIO_BUTTON
56
+ when AcroFields.FIELD_TYPE_SIGNATURE
57
+ @pdf_fields[key.to_string().to_sym] = GBDev::PDF::Page::SIGNATURE
58
+ when AcroFields.FIELD_TYPE_TEXT
59
+ @pdf_fields[key.to_string().to_sym] = GBDev::PDF::Page::TEXT_FIELD
60
+ else
61
+ @pdf_fields[key.to_string().to_sym] = GBDev::PDF::Page::UNKNOWN
62
+ end
63
+ end
64
+
65
+ return @pdf_fields
66
+ end
67
+
68
+ # Returns an array of field states. For example if the field type is a list an array
69
+ # with all possible choices in the list will be returned.
16
70
  #
17
- # key : A known field in the PDF.
18
- # value : The value to apply to the know field.
19
- def set_text(key, value)
20
- @fields[key] = value
71
+ # * field_name - The field name to get all the possible states for.
72
+ def get_field_states(field_name)
73
+ reader = PdfReader.new(@template)
74
+ form = reader.getAcroFields()
75
+ form.getAppearanceStates(field_name.to_s);
21
76
  end
22
77
 
23
- # Alias for set_text method
24
- alias :text :set_text
25
78
 
26
- # Sets a know image area in the PDF template.
79
+ # Sets a know checkbox in the PDF template.
80
+ #
81
+ # * key - A known checkbox in the PDF.
82
+ # * value - The checkbox to update.
83
+ def set_checkbox(key, value)
84
+ @check_boxes[key] = value
85
+ end
86
+
87
+ # Alias for the set_checkbox method
88
+ alias :checkbox :set_checkbox
89
+
90
+ # NOT WORING YET
91
+ # Sets a known image area in the PDF template.
27
92
  #
28
- # key : A known field in the PDF.
29
- # value : The image to apply to the know image area.
93
+ # * key - A known image in the PDF.
94
+ # * value - The image to apply to the know image area.
30
95
  def set_image(key, value)
96
+ raise 'Image not working yet'
31
97
  @images[key] = value
32
- end
98
+ end
33
99
 
34
100
  # Alias for the set_image method
35
- alias :image :set_image
101
+ alias :image :set_image
102
+
103
+
104
+ # Sets a known radio button in the PDF template.
105
+ #
106
+ # * key - A known radio button group in the PDF.
107
+ # * value - The radio button group to update.
108
+ def set_radio_button(key, value)
109
+ @radio_buttons[key] = value
110
+ end
111
+
112
+ # Alias for the set_checkbox method
113
+ alias :radio_button :set_radio_button
114
+
115
+
116
+ # NOT WORKING YET
117
+ # Sets a known signature field in the PDF template.
118
+ #
119
+ # * key - A known signature field in the PDF.
120
+ # * value - The value to apply to the know field.
121
+ def set_signature_field(key, value)
122
+ raise 'Signature field not working yet'
123
+ @signature_fields[key] = value
124
+ end
125
+
126
+ # Alias for set_signature_field method
127
+ alias :signature_field :set_signature_field
128
+
129
+
130
+ # Sets a known text field in the PDF template.
131
+ #
132
+ # * key - A known text field in the PDF.
133
+ # * value - The value to apply to the know field.
134
+ def set_text_field(key, value)
135
+ @text_fields[key] = value
136
+ end
137
+
138
+ # Alias for set_text method
139
+ alias :text_field :set_text_field
140
+
141
+ # Maps PDF fields to an ActiveRecord object. The ActiveRecord object must use the
142
+ # acts_as_pdf_db_mapper module.
143
+ #
144
+ # * object - An ActiveRecord object that uses the acts_as_pdf_db_mapper module.
145
+ def map_to_object(object)
146
+ if object.methods.include?('mapped_fields')
147
+ fields = self.get_pdf_fields
148
+ object.mapped_fields.each do |mapped_field|
149
+
150
+ if mapped_field.class.to_s == 'Hash'
151
+ key_value_pair = mapped_field.first.to_a.flatten
152
+ key = key_value_pair[0]
153
+ value = key_value_pair[1]
154
+ else
155
+ key = mapped_field
156
+ value = mapped_field
157
+ end
158
+
159
+ case(fields[key])
160
+ when GBDev::PDF::Page::CHECK_BOX
161
+ self.set_checkbox(key, object.send(value))
162
+ when GBDev::PDF::Page::COMBO_BOX
163
+ #self.set_combobox(key, object.send(value))
164
+ when GBDev::PDF::Page::LIST
165
+ #self.set_list(key, object.send(value))
166
+ when GBDev::PDF::Page::NONE
167
+ #self.set_none(key, object.send(value))
168
+ when GBDev::PDF::Page::PUSH_BUTTON
169
+ #self.set_push_button(key, object.send(value))
170
+ when GBDev::PDF::Page::RADIO_BUTTON
171
+ self.set_radio_button(key, object.send(value))
172
+ when GBDev::PDF::Page::SIGNATURE
173
+ self.set_signature_field(key, object.send(value))
174
+ when GBDev::PDF::Page::TEXT_FIELD
175
+ self.set_text_field(key, object.send(value))
176
+ end
177
+
178
+ end
179
+ end
180
+ end
181
+
36
182
 
37
183
  # Renders the template with the given data and saves to the given filename path.
38
184
  #
39
- # String filename : A path to the file to be created.
40
- def save_to(filename)
185
+ # * filename - A path to the file to be created.
186
+ def save_to(filename)
41
187
  field_cache = HashMap.new
42
188
  reader = PdfReader.new(@template)
43
189
  stamper = PdfStamper.new( reader, FileOutputStream.new(filename) )
44
190
  form = stamper.getAcroFields()
45
191
  form.setFieldCache(field_cache)
192
+
193
+ all_fields = {}
194
+ all_fields.merge!(@check_boxes)
195
+ all_fields.merge!(@radio_buttons)
196
+ all_fields.merge!(@signature_fields)
197
+ all_fields.merge!(@text_fields)
46
198
 
47
- @fields.each do |field, value|
199
+ all_fields.each do |field, value|
48
200
  form.setField(field.to_s, value.to_s)
49
- end
201
+ end
202
+
203
+ # TODO: do something with @images
50
204
 
51
205
  stamper.setFormFlattening(true)
52
206
  stamper.close
53
207
  end
54
208
 
209
+ # Renders the PDF Book without saving it to disk and displays it in the browser.
55
210
  def display
56
211
  end
57
212
 
213
+ # Renders the PDF Page, saves it to the specified file and then displays the PDF in the browser.
214
+ #
215
+ # * filename - A path to the file to be created.
58
216
  def save_and_display(filename)
59
217
  save(filename)
60
218
  display
@@ -1,4 +1,5 @@
1
- module Gbdev
1
+ module Gbdev #:nodoc: all
2
+
2
3
  module Utils
3
4
 
4
5
  module PrivateMethods
@@ -9,13 +9,13 @@ describe 'Book' do
9
9
  pdf_book = File.expand_path(File.dirname(__FILE__) + '/../output/certs.pdf')
10
10
 
11
11
  page1 = GBDev::PDF::Page.new(template_file)
12
- page1.set_text(:full_name, 'Wes Hays')
12
+ page1.set_text_field(:full_name, 'Wes Hays')
13
13
 
14
14
  page2 = GBDev::PDF::Page.new(template_file)
15
- page2.set_text(:full_name, 'Darren Johnson')
15
+ page2.set_text_field(:full_name, 'Darren Johnson')
16
16
 
17
17
  page3 = GBDev::PDF::Page.new(template_file)
18
- page3.set_text(:full_name, 'John Dell')
18
+ page3.set_text_field(:full_name, 'John Dell')
19
19
 
20
20
  book.add_page(page1)
21
21
  book.add_page(page2)
@@ -33,13 +33,13 @@ describe 'Book' do
33
33
  pdf_book = File.expand_path(File.dirname(__FILE__) + '/../output/certs.pdf')
34
34
 
35
35
  page1 = GBDev::PDF::Page.new(template_file)
36
- page1.set_text(:full_name, 'Wes Hays')
36
+ page1.set_text_field(:full_name, 'Wes Hays')
37
37
 
38
38
  page2 = GBDev::PDF::Page.new(template_file)
39
- page2.set_text(:full_name, 'Darren Johnson')
39
+ page2.set_text_field(:full_name, 'Darren Johnson')
40
40
 
41
41
  page3 = GBDev::PDF::Page.new(template_file)
42
- page3.set_text(:full_name, 'John Dell')
42
+ page3.set_text_field(:full_name, 'John Dell')
43
43
 
44
44
  book.add_page(page1)
45
45
  book.add_page(page2)
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe 'PDF_DB_Mapper' do
4
+
5
+ before(:each) do
6
+ Address.create_corpus!
7
+ end
8
+
9
+ after(:each) do
10
+ Address.destroy_all
11
+ end
12
+
13
+ it 'should allow all database columns to be mapped if no :only or :except is specified' do
14
+ address = Address.first
15
+ fields_array = address.mapped_fields.collect{|f| f.to_s}.sort
16
+ fields_array.should == ['id', 'address1', 'address2', 'city', 'state', 'postal_code'].sort
17
+ end
18
+
19
+ it 'should only map the fields specified by :only' do
20
+ address = ClientAddress.first
21
+ fields_array = address.mapped_fields.collect{|f| f.to_s}.sort
22
+ fields_array.should == ['city', 'state'].sort
23
+ end
24
+
25
+ it 'should map all the fields except the fields specified by :except' do
26
+ address = ContactAddress.first
27
+ fields_array = address.mapped_fields.collect{|f| f.to_s}.sort
28
+ fields_array.should == ['address2', 'city', 'state'].sort
29
+ end
30
+
31
+ it 'should include the additional mappings specified by :include' do
32
+ address = UserAddress.first
33
+ fields_array = address.mapped_fields.collect{|f| f.class.to_s == 'Hash' ? f.first.to_a.flatten.join('::') : f.to_s}.sort
34
+ fields_array.should == ['id', 'address1', 'address2', 'city', 'state', 'postal_code','full_address::address'].sort
35
+ end
36
+
37
+ it 'should only include the mappings specified by :only_include' do
38
+ address = FamilyAddress.first
39
+ fields_array = address.mapped_fields.collect{|f| f.first.to_a.flatten.join('::')}.sort
40
+ fields_array.should == ['full_address::address'].sort
41
+ end
42
+
43
+ it 'should map the specified fields for a single record to a single page' do
44
+ page = PDFPage(File.expand_path(File.dirname(__FILE__) + '/../templates/address_template.pdf'))
45
+ address = Address.first
46
+ page.map_to_object(address)
47
+ page.save_to(File.expand_path(File.dirname(__FILE__) + '/../output/db_address.pdf'))
48
+ File.exist?(File.dirname(__FILE__) + '/../output/db_address.pdf').should be_true
49
+ end
50
+
51
+ end
@@ -4,16 +4,80 @@ describe 'Page' do
4
4
 
5
5
  it 'should create the page and write to the output directory' do
6
6
  page = GBDev::PDF::Page.new(File.expand_path(File.dirname(__FILE__) + '/../templates/certificate_template.pdf'))
7
- page.set_text(:full_name, 'Wes Hays')
7
+ page.set_text_field(:full_name, 'Wes Hays')
8
8
  page.save_to(File.expand_path(File.dirname(__FILE__) + '/../output/wes_hays.pdf'))
9
9
  File.exist?(File.dirname(__FILE__) + '/../output/wes_hays.pdf').should be_true
10
10
  end
11
11
 
12
12
  it 'should create the page and write to the output directory with Kernel method' do
13
13
  page = PDFPage(File.expand_path(File.dirname(__FILE__) + '/../templates/certificate_template.pdf'))
14
- page.set_text(:full_name, 'Wes Hays')
14
+ page.set_text_field(:full_name, 'Wes Hays')
15
15
  page.save_to(File.expand_path(File.dirname(__FILE__) + '/../output/wes_hays.pdf'))
16
16
  File.exist?(File.dirname(__FILE__) + '/../output/wes_hays.pdf').should be_true
17
17
  end
18
18
 
19
+ it 'should find all three fields: text field, checkbox and radio buttons' do
20
+ page = PDFPage(File.expand_path(File.dirname(__FILE__) + '/../templates/form_template.pdf'))
21
+ fields = page.get_pdf_fields
22
+
23
+ fields.has_key?(:full_name).should be_true
24
+ fields[:full_name].should == GBDev::PDF::Page::TEXT_FIELD
25
+
26
+ fields.has_key?(:home_owner).should be_true
27
+ fields[:home_owner].should == GBDev::PDF::Page::RADIO_BUTTON
28
+
29
+ fields.has_key?(:newsletter).should be_true
30
+ fields[:newsletter].should == GBDev::PDF::Page::CHECK_BOX
31
+
32
+ fields.has_key?(:car_types).should be_true
33
+ fields[:car_types].should == GBDev::PDF::Page::LIST
34
+
35
+ fields.has_key?(:sibling_count).should be_true
36
+ fields[:sibling_count].should == GBDev::PDF::Page::COMBO_BOX
37
+
38
+ # fields.has_key?(:owner_signature).should be_true
39
+ # fields[:owner_signature].should == GBDev::PDF::Page::SIGNATURE
40
+ #
41
+ # fields.has_key?(:submit_button).should be_true
42
+ # fields[:submit_button].should == GBDev::PDF::Page::PUSH_BUTTON
43
+ #
44
+ # fields.has_key?(:photo).should be_true
45
+ # fields[:photo].should == GBDev::PDF::Page::IMAGE
46
+ end
47
+
48
+ it 'should find all the valid states for the check box' do
49
+ page = PDFPage(File.expand_path(File.dirname(__FILE__) + '/../templates/form_template.pdf'))
50
+ states = page.get_field_states(:newsletter) # Checkbox
51
+ states.should == ['Yes','Off']
52
+ end
53
+
54
+ it 'should find all the valid states for the radio button' do
55
+ page = PDFPage(File.expand_path(File.dirname(__FILE__) + '/../templates/form_template.pdf'))
56
+ states = page.get_field_states(:home_owner) # radio button
57
+ states.should == ['Yes','No','Off'] # Off will not be used but AcroFields returns it anyway.
58
+ end
59
+
60
+ it 'should find all the valid states for the list' do
61
+ page = PDFPage(File.expand_path(File.dirname(__FILE__) + '/../templates/form_template.pdf'))
62
+ states = page.get_field_states(:car_types) # List
63
+ states.sort.should == ['Chevy', 'Ford', 'Honda', 'Jeep', 'Toyota'].sort
64
+ end
65
+
66
+ it 'should find all the valid states for the combo box' do
67
+ page = PDFPage(File.expand_path(File.dirname(__FILE__) + '/../templates/form_template.pdf'))
68
+ states = page.get_field_states(:sibling_count) # List
69
+ states.sort.should == ['Zero','One','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten'].sort
70
+ end
71
+
72
+ it 'should fill all fields' do
73
+ page = PDFPage(File.expand_path(File.dirname(__FILE__) + '/../templates/form_template.pdf'))
74
+ page.set_text_field(:full_name, 'Anna Hays')
75
+ page.set_checkbox(:home_owner, 'Yes')
76
+ page.set_checkbox(:newsletter, 'Yes')
77
+ page.set_checkbox(:car_types, 'Jeep')
78
+ page.set_checkbox(:sibling_count, 'One')
79
+ page.save_to(File.expand_path(File.dirname(__FILE__) + '/../output/form_test.pdf'))
80
+ File.exist?(File.dirname(__FILE__) + '/../output/form_test.pdf').should be_true
81
+ end
82
+
19
83
  end
@@ -41,16 +41,65 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
41
41
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
42
42
  require 'pdf_filler'
43
43
 
44
+
45
+ module GBDev
46
+ module TestData
47
+ module Addresses
48
+ def create_corpus!
49
+ create!(:address1 => '111 AAA St', :address2 => 'Suite 444', :city => 'Reno', :state => 'Nevada', :postal_code => '89506')
50
+ create!(:address1 => '222 BBB St', :address2 => 'Suite 555', :city => 'Sparks', :state => 'Nevada', :postal_code => '89434')
51
+ create!(:address1 => '333 CCC St', :address2 => 'Suite 666', :city => 'Fernley', :state => 'Nevada', :postal_code => '89408')
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+
44
58
  Spec::Runner.configure do |config|
45
59
  config.before(:each) do
46
60
  class Client < ActiveRecord::Base
61
+ acts_as_pdf_db_mapper :only => [:first_name, :last_name]
47
62
  has_many :addresses, :dependent => :destroy
63
+
64
+ def full_name
65
+ [self.first_name, self.last_name].join(' ')
66
+ end
48
67
  end
49
68
 
50
69
  class Address < ActiveRecord::Base
51
- belongs_to :client
70
+ acts_as_pdf_db_mapper
71
+ belongs_to :client
72
+ extend GBDev::TestData::Addresses
52
73
  end
53
74
 
75
+ class ClientAddress < ActiveRecord::Base
76
+ set_table_name :addresses
77
+ acts_as_pdf_db_mapper :only => [:state, :city]
78
+ end
79
+
80
+ class ContactAddress < ActiveRecord::Base
81
+ set_table_name :addresses
82
+ acts_as_pdf_db_mapper :except => [:id, :address1, :postal_code]
83
+ end
84
+
85
+ class UserAddress < ActiveRecord::Base
86
+ set_table_name :addresses
87
+ acts_as_pdf_db_mapper :include => [{:full_address => :address}]
88
+
89
+ def full_address
90
+ [self.address1, self.address2].join(', ')
91
+ end
92
+ end
93
+
94
+ class FamilyAddress < ActiveRecord::Base
95
+ set_table_name :addresses
96
+ acts_as_pdf_db_mapper :only_include => [{:full_address => :address}]
97
+
98
+ def full_address
99
+ [self.address1, self.address2].join(', ')
100
+ end
101
+ end
102
+
54
103
  Client.destroy_all
55
104
  Address.destroy_all
56
105
  end
@@ -27,12 +27,14 @@ begin
27
27
  'lib/pdf_filler.rb',
28
28
  'lib/pdf_filler/page.rb',
29
29
  'lib/pdf_filler/book.rb',
30
+ 'lib/pdf_filler/pdf_db_mapper',
30
31
  'lib/pdf_filler/util_methods.rb',
31
32
  'tasks/documentation.rake',
32
33
  'tasks/build_gem.rake',
33
34
  'spec/spec_helper.rb',
34
35
  'spec/lib/pdf_page_spec.rb',
35
36
  'spec/lib/pdf_book_spec.rb',
37
+ 'spec/lib/pdf_db_mapper_spec.rb',
36
38
  'spec/output',
37
39
  'spec/templates/certificate_template.pdf']
38
40
 
@@ -4,7 +4,7 @@ require 'rake/rdoctask'
4
4
  desc 'Generate documentation for PDF-Filler.'
5
5
  Rake::RDocTask.new do |rdoc|
6
6
  rdoc.rdoc_dir = 'doc/html'
7
- rdoc.title = 'scoped_search'
7
+ rdoc.title = 'pdf_filler'
8
8
  rdoc.options << '--line-numbers' << '--inline-source'
9
9
  rdoc.main = 'README.rdoc'
10
10
  rdoc.rdoc_files.include('LICENSE', 'lib/')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gbdev-pdf_filler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wes Hays
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-08-01 00:00:00 -07:00
13
+ date: 2009-08-03 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -44,6 +44,7 @@ files:
44
44
  - lib/pdf_filler/page.rb
45
45
  - lib/pdf_filler/util_methods.rb
46
46
  - spec/lib/pdf_book_spec.rb
47
+ - spec/lib/pdf_db_mapper_spec.rb
47
48
  - spec/lib/pdf_page_spec.rb
48
49
  - spec/spec_helper.rb
49
50
  - spec/templates/certificate_template.pdf