raybaxter (owner)

Fork Of

Revisions

  • 0a10a0 andrewc... Mon Apr 06 16:08:01 -0700 2009
gist: 91602 Download_button fork
public
Public Clone URL: git://gist.github.com/91602.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Prawn.generate do |pdf|
  mailing_labels( @organizations, :foo => bar ) do |box, org|
    box.text org.name
  end
end
 
 
 
module Prawn
  class Document
    def mailing_labels(data, options={}, &block)
      MailingLabel.new(data, self, options).draw(&block)
    end
  end
end
 
 
class MailingLabel
  def initialize(data, document, options = {})
    @data = data
    @document = document
    @options = options
  end
  
  def draw
    @data.in_groups_of(per_page).each do |records|
      records.each_with_index do |rec, i|
        document.bounding_box(bounding_box_options_for(i)) do |box|
          yield box, rec
        end
      end
      new_page
    end
  end
  
  private
  
  def per_page
    20
  end
  
  def bounding_box_options_for(num)
    {}
  end
end