Class: CardPrinter::A6Renderer

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

Constant Summary collapse

TITLE_SIZE =
12.mm
DESCRIPTION_SIZE =
7.mm

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stories, opts = {}) ⇒ A6Renderer

Returns a new instance of A6Renderer.



14
15
16
17
18
# File 'lib/card_printer/a6_renderer.rb', line 14

def initialize(stories, opts = {})
  @stories = stories
  @scale = 1
  @cards_per_page = 4
end

Class Method Details

.descriptionObject



10
11
12
# File 'lib/card_printer/a6_renderer.rb', line 10

def self.description
  "four a6 cards on one a4 sheet"
end

Instance Method Details

#render_to(destination) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/card_printer/a6_renderer.rb', line 20

def render_to(destination)
  @pdf = Prawn::Document.new(:page_layout => :landscape,
                           :margin      => 0,
                           :page_size   => 'A4')


  paginate_in_piles(@stories).each.with_index do |story_cluster, i|
    @pdf.start_new_page unless i == 0
    render_page(story_cluster)
  end

  @pdf.render_file destination
rescue Exception
  puts "[!] There was an error while generating the PDF file... What happened was:"
  raise
end