mileszs (owner)

Forks

Revisions

gist: 125953 Download_button fork
public
Public Clone URL: git://gist.github.com/125953.git
Embed All Files: show embed
prawn_term_sheet.rb #
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/ruby -w
#
# Testing Prawn PDF generation
 
require 'rubygems'
require 'prawn'
require 'prawn/layout'
require 'prawn/format'
 
class TermSheet < Prawn::Document
  def initialize(options={})
    @recipient = options[:recipient]
    @recipient_addy = options[:recipient_addy]
    @ticket = options[:ticket]
    @sales_rep = options[:sales_rep]
    @doc_no = options[:doc_no]
    @project = options[:project]
    @date = options[:date]
    super
  end
 
  def draw_term_sheet
    line_width(0.2)
    font_size(8)
    nframe_address
    info_table
    recipient_address
    hr
    draw_footer
  end
 
  def save_as(file)
    draw_term_sheet
    render_file(file)
  end
 
  def info_table
    tags :blue => { :color => 'blue' },
         :green => { :color => 'green' }
 
    bounding_box [235, 700], :width => 300 do
      font "Times-Roman"
      fill_color('999999')
      text "TERM SHEET", :size => 24, :align => :right
      fill_color('000000')
      font "Helvetica"
      text "<blue>Keep IT Safe,</blue> <green>Keep IT Simple</green>", :size => 12, :align => :right
    end
    bounding_box [260, 650] do
      table [[@ticket, @sales_rep, @doc_no, @project, @date]],
        :headers => ['TICKET', 'SALES REP', 'DOC. NO.', 'PROJECT NO.', 'DATE'],
        :header_color => '000000',
        :header_text_color => 'ffffff',
        :align_headers => :center,
        :vertical_padding => 2,
        :horizontal_padding => 2,
        :font_size => 8,
        :width => 272,
        :border_width => 0.2,
        :align => { 0 => :center, 1 => :center, 2 => :center, 3 => :center, 4 => :center, 5 => :center, 6 => :left }
    end
  end
 
  def nframe_address
    address = <<-EOF
 
701 Congressional Blvd. Ste 100
Carmel, IN 46032
Phone: (317) 805-3759
Fax: (317) 324-9013
Web: www.nframe.com
 
EOF
 
    bounding_box [0, 700], :width => 130 do
      nframe = "nframe.jpg"
      image nframe, :scale => 0.25
      text address, :size => 6
    end
  end
 
  def recipient_address
    pad_bottom(5) do
      bounding_box [100, 700], :width => 150, :height => 95 do
        line bounds.top_left, bounds.top_right
        line bounds.top_left, bounds.bottom_left
        line bounds.top_right, bounds.bottom_right
        line bounds.bottom_right, bounds.bottom_left
        padded_box(5) do
          text "<strong>TO: #{@recipient.upcase}</strong>"
          stroke_horizontal_rule
          text @recipient_addy
        end
      end
    end
  end
 
  def hr
    stroke_horizontal_rule
  end
 
  def draw_footer
    footer [margin_box.left, margin_box.bottom + 25] do
      pad_bottom(3) do
        text "Freq. = Frequency | MRC = Monthly Recurring Charge | NRC = Non-Recurring Charge | Term = Term in Months"
      end
      hr
      pad(5) do
        text "#{@date} \t To: #{@recipient} \t\t #{@doc_no} \t \"Keep IT Safe, Keep IT Simple\" "
        text "CONFIDENTIAL", :size => 16, :at => [bounds.right - (font_size * 16), bounds.top - 32]
      end
    end
  end
end
 
customer_addy = <<EOF
 
Attn: Tom Bombadil
8847 Old Forest Lane
Old Forest, Middle-Earth 46260
Phone: (317) 888-8888
Fax: (317) 888-8887
Email: tom@bombadil.net
EOF
 
i = TermSheet.new(:recipient_addy => customer_addy, :recipient => 'Indifferent Enigmas', :ticket => '0', :sales_rep => 'Frodo Baggins', :doc_no => 'NFIQ3836', :project => 'NFIPROJECT2553', :date => '5/15/2006')
i.save_as('term_sheet.pdf')