Class: PivotalToPdf::Formatters::Default

Inherits:
Base
  • Object
show all
Defined in:
lib/pivotal_to_pdf-formatters/default.rb

Direct Known Subclasses

Asian, LargeText

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from PivotalToPdf::Formatters::Base

Instance Method Details

#write_to(destination) ⇒ Object



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
# File 'lib/pivotal_to_pdf-formatters/default.rb', line 9

def write_to(destination)
  Prawn::Document.generate("#{destination}.pdf",
                           :page_layout => :landscape,
                           :margin => [25, 25, 50, 25],
                           :page_size => [302, 432]) do |pdf|

    setup_font(pdf)

    stories.each_with_index do |story, index|
      padding = 10
      pdf.stroke_color = story.story_color
      pdf.stroke_bounds
      width = 370
      pdf.line_width=6
      # --- Write content
      pdf.bounding_box [pdf.bounds.left+padding, pdf.bounds.top-padding], :width => width do
        pdf.text story.formatted_name, :size => 14, :inline_format => true
        pdf.fill_color "52D017"
        pdf.text story.formatted_labels, :size => 8
        pdf.text "\n", :size => 14
        pdf.fill_color "444444"
        pdf.text story.formatted_description || "", :size => 10, :inline_format => true
        pdf.fill_color "000000"
      end
      pdf.line(pdf.bounds.bottom_left, pdf.bounds.bottom_right)
      pdf.stroke_bounds

      pdf.text_box story.points, :size => 12, :at => [12, 50], :width => width-18 unless story.points.nil?
      pdf.text_box "Owner: " + (story.respond_to?(:owned_by) ? story.owned_by : "None"),
                   :size => 8, :at => [12, 18], :width => width-18

      pdf.fill_color "999999"
      pdf.text_box story.story_type.capitalize, :size => 8, :align => :right, :at => [12, 18], :width => width-18
      pdf.fill_color "000000"
      pdf.start_new_page unless index == stories.size - 1
    end

    puts Rainbow(">>> Generated PDF file in '#{destination}.pdf'").foreground(:green)
  end
rescue Exception
  puts Rainbow("[!] There was an error while generating the PDF file... What happened was:").foreground(:red)
  raise
end