Class: Prawn::Document
- Inherits:
-
Object
- Object
- Prawn::Document
- Defined in:
- lib/features2cards/prawn.rb
Constant Summary collapse
- CARD_WIDTH =
5 inches
72 * 5
- CARD_HEIGHT =
3 inches
72 * 3
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.generate_cards(outfile, cards) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/features2cards/prawn.rb', line 7 def self.generate_cards(outfile, cards) generate(outfile, :page_layout => :landscape) do row = 2 col = 0 cards.each do |card| if row == 0 start_new_page row = 2 col = 0 end draw_card(card, row, col) col += 1 if col > 1 col = 0 row -= 1 end end end end |
Instance Method Details
#draw_card(card, row, col) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/features2cards/prawn.rb', line 41 def draw_card(card, row, col) bounding_box [CARD_WIDTH * col, CARD_HEIGHT * row + ((bounds.height - (2*CARD_HEIGHT))/2)], :width => CARD_WIDTH, :height => CARD_HEIGHT do outline_box margin_box 8 do text card.type, :size => 12 margin_box 16 do text card.body, :size => 10, :align => :left end unless card..nil? bounding_box [bounds.left, bounds.bottom + 10], :width => bounds.width, :height => 10 do text card., :size => 8, :align => :right end end end end end |
#margin_box(margin, &block) ⇒ Object
31 32 33 34 35 |
# File 'lib/features2cards/prawn.rb', line 31 def margin_box(margin, &block) bounding_box [bounds.left + margin, bounds.top - margin], :width => bounds.width - (margin * 2), :height => bounds.height - (margin * 2), &block end |
#outline_box ⇒ Object
37 38 39 |
# File 'lib/features2cards/prawn.rb', line 37 def outline_box stroke_rectangle bounds.top_left, bounds.width, bounds.height end |