Class: Handout

Inherits:
Object
  • Object
show all
Defined in:
lib/qhandout.rb

Constant Summary collapse

DEFAULT_TRAINERS =
[
      ["Rob Westgeest", "Westgeest-Consultancy",
"Gondelstraat 2", "5017 CK  Tilburg, NL", "+31 6 45 776 328", "[email protected]"],
      ["Marc Evers", "Piecemeal Growth", "Delftseschans 18",
"3432 TD  Nieuwegein, NL", "+31 6 4455 0003", "[email protected]"],
      ["Willem van den Ende", "Living Software B.V.", "Spilmanstraat 25",
"5645 JE  Eindhoven, NL", "+31 6 4130 6965", "[email protected]"]]
SERIF_FONT =
"Times-Roman"
COMIC_SANS_FONT =
"#{Prawn::BASEDIR}/data/fonts/comicsans.ttf"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments = {}) ⇒ Handout

Returns a new instance of Handout.



68
69
70
71
72
73
74
# File 'lib/qhandout.rb', line 68

def initialize arguments = {}
  @trainers = arguments[:trainers] || DEFAULT_TRAINERS
  @course = arguments[:course] || ""
  @date = arguments[:date] || ""
  @location = arguments[:location] || ""
  @tabs = arguments[:tabs] || [[]]
end

Class Method Details

.create(parameters) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/qhandout.rb', line 56

def self.create(parameters)
  raise "need course name" unless parameters[:course]
  raise "need course dates" unless parameters[:date]
  raise "need location/client" unless parameters[:location]
  raise "need titles and goals for tabs" unless parameters[:tabs]

  handout = Handout.new parameters
  handout.create_frontpage
  handout.create_toc
  handout.create_tabs
end

Instance Method Details

#add_trainer_info(pdf) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/qhandout.rb', line 103

def add_trainer_info(pdf)
  pdf.column_box([0, pdf.cursor], :columns => 3, :width => pdf.bounds.width) do
    pdf.texts @trainers[0], :size => 11, :align => :left
    pdf.bounds.move_past_bottom
    pdf.texts @trainers[1], :size => 11, :align => :center
    pdf.bounds.move_past_bottom
    pdf.texts @trainers[2], :size => 11, :align => :right
  end
end

#create_frontpageObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/qhandout.rb', line 113

def create_frontpage
  footer = "(c) 2005-2013 QWAN -Quality Without a Name\nwww.qwan.eu"

  new_page("frontpage.pdf", footer) do | pdf |
    pdf.image "#{File.dirname(__FILE__)}/qwan_logo_small.png", :position => :center

    pdf.font "Helvetica"
    pdf.text "\n\n\nCourse Handout\n\n\n\n", :size => 20, :align => :center

    pdf.fill_color ORCHID
    pdf.font COMIC_SANS_FONT
    pdf.text_with_shadow @course, :size => 36, :align => :center

    pdf.fill_color BLACK
    pdf.font "Helvetica"
    pdf.text "\n\n\n\n\n\n#{@date}", :size => 20, :align => :center

    pdf.text "#{@location}\n\n\n\n\n\n\n\n", :align => :center

    add_trainer_info(pdf)
  end
end

#create_tabsObject



189
190
191
192
193
# File 'lib/qhandout.rb', line 189

def create_tabs
  @tabs.each_with_index do | (title, goal), index |
    tab title, goal, (index+1).to_s
  end
end

#create_tocObject



164
165
166
167
168
169
170
171
172
173
174
# File 'lib/qhandout.rb', line 164

def create_toc
  new_page("toc.pdf", tab_footer) do | pdf |
    header(pdf)

    pdf.move_down 10.mm

    @tabs.each_with_index do | (title, goal), index |
      tab_entry(pdf, title, goal, (index + 1).to_s)
    end
  end
end


85
86
87
88
# File 'lib/qhandout.rb', line 85

def footer(pdf, text)
  pdf.move_cursor_to(10.mm)
  pdf.text text, :align => :center
end

#header(pdf) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/qhandout.rb', line 76

def header(pdf)
  pdf.font COMIC_SANS_FONT
  pdf.fill_color GRAY
  
  pdf.with_shadow :color => BLACK do
    pdf.text @course, :size => 20, :align => :center
  end
end

#new_page(pdf_file, footer_text = "") ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/qhandout.rb', line 90

def new_page(pdf_file, footer_text = "")
  Prawn::Document.generate(pdf_file, :page_size => 'A4',
      :left_margin => 15.mm,
      :right_margin => 15.mm,
      :top_margin => 20.mm,
      :bottom_margin => 15.mm
  ) do | pdf |
    yield pdf

    footer(pdf, footer_text)
  end
end

#tab(title, goal, tab_nr) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/qhandout.rb', line 176

def tab(title, goal, tab_nr)
  new_page("tab#{tab_nr}.pdf", tab_footer) do |pdf|
    pdf.move_down 40.mm

    tab_entry(pdf, title, "", tab_nr)

    pdf.bounding_box [30.mm, pdf.cursor - 20.mm], :width => 140.mm do
      pdf.fill_color BLACK
      pdf.text goal, :size => 16
    end
  end
end

#tab_entry(pdf, title, goal, tab_nr) ⇒ Object



150
151
152
153
154
155
156
157
158
# File 'lib/qhandout.rb', line 150

def tab_entry(pdf, title, goal, tab_nr)
  pdf.bounding_box [15.mm, pdf.cursor - 5.mm], :width => 600 do
    pdf.font SERIF_FONT
    pdf.fill_color ORCHID

    tab_number(pdf, tab_nr)
    title_and_goal(pdf, goal, title)
  end
end


160
161
162
# File 'lib/qhandout.rb', line 160

def tab_footer
  "#{@course} / #{@date}, #{@location}"
end

#tab_number(pdf, tab_nr) ⇒ Object



136
137
138
139
140
# File 'lib/qhandout.rb', line 136

def tab_number(pdf, tab_nr)
  pdf.bounding_box [pdf.bounds.left, pdf.bounds.top], :width => 60, :height => 60 do
    pdf.text_with_shadow tab_nr, :size => 42
  end
end

#title_and_goal(pdf, goal, title) ⇒ Object



142
143
144
145
146
147
148
# File 'lib/qhandout.rb', line 142

def title_and_goal(pdf, goal, title)
  pdf.bounding_box [pdf.bounds.left + 28, pdf.bounds.top], :width => 500, :height => 60 do
    pdf.text_with_shadow title, :size => 18
    pdf.fill_color BLACK
    pdf.text goal, :size => 12
  end
end