Created
May 26, 2011 14:26
-
-
Save fnando/993249 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
class Certificate < Base | |
class PDF | |
PDF_OPTIONS = { | |
:page_size => "A5", | |
:page_layout => :landscape, | |
:background => Rails.root.join("public/images/certificate/bg.png"), | |
:margin => [30, 70] | |
} | |
attr_accessor :subscription | |
def initialize(subscription = nil) | |
@subscription = subscription | |
end | |
def path | |
File.join(root_dir, "#{subscription.uid}.pdf") | |
end | |
def root_dir | |
File.join(AppConfig[:certificates_directory], "certificates") | |
end | |
def workshop | |
subscription.workshop | |
end | |
def speaker | |
workshop.speaker | |
end | |
def attendee | |
subscription.user | |
end | |
def pdf | |
Prawn::Document.new(PDF_OPTIONS) do |pdf| | |
pdf.fill_color "40464e" | |
pdf.text workshop.name, :size => 40, :style => :bold, :align => :center | |
if workshop.tagline? | |
pdf.move_up 10 | |
pdf.text workshop.tagline, :size => 16, :align => :center | |
end | |
pdf.move_down 30 | |
pdf.text "Certificado", :size => 24, :align => :center, :style => :bold | |
pdf.move_down 30 | |
starts = I18n.l(workshop.starts_at, :format => :date) | |
ends = I18n.l(workshop.ends_at, :format => :date) | |
if starts != ends | |
period = "de #{starts} a #{ends}" | |
else | |
period = "em #{starts}" | |
end | |
pdf.text "Certificamos que <b>#{attendee.name}</b> participou do workshop online “#{[workshop.name, workshop.tagline].compact.join(": ")}”, ministrado por #{speaker.name} e promovido pelo HOWTO, que aconteceu #{period}, com carga horária de #{workshop.workload} horas.", :inline_format => true | |
pdf.move_down 15 | |
pdf.text "São Paulo, #{I18n.l(Time.now, :format => :short_date)}." | |
pdf.move_down 30 | |
pdf.font Rails.root.join("public/rb.ttf").to_s | |
pdf.text "howto", :size => 24 | |
pdf.move_up 5 | |
pdf.font "Helvetica" | |
pdf.text "http://howtocode.com.br", :size => 10 | |
end | |
end | |
def save | |
FileUtils.mkdir_p(root_dir) | |
pdf.render_file(path) | |
true | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment