class Handout
Constants
- COMIC_SANS_FONT
- DEFAULT_TRAINERS
- SERIF_FONT
Public Class Methods
create(parameters)
click to toggle source
# 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
new(arguments = {})
click to toggle source
# 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
Public Instance Methods
add_trainer_info(pdf)
click to toggle source
# 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_frontpage()
click to toggle source
# 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_tabs()
click to toggle source
# 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_toc()
click to toggle source
# 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
header(pdf)
click to toggle source
# 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 = "") { |pdf| ... }
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
tab_number(pdf, tab_nr)
click to toggle source
# 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)
click to toggle source
# 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