Sha256: b7450a392da96b2991ad326dfccec48d12ac44a327b99b9e621308268b6d405c
Contents?: true
Size: 1.41 KB
Versions: 3
Compression:
Stored size: 1.41 KB
Contents
require "prawn" class Prawn::Document CARD_WIDTH = 72 * 5 # 5 inches CARD_HEIGHT = 72 * 3 # 3 inches 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 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 def outline_box stroke_rectangle bounds.top_left, bounds.width, bounds.height end 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.footer.nil? bounding_box [bounds.left, bounds.bottom + 10], :width => bounds.width, :height => 10 do text card.footer, :size => 8, :align => :right end end end end end end
Version data entries
3 entries across 3 versions & 3 rubygems
Version | Path |
---|---|
brynary-features2cards-0.3.0.0 | lib/features2cards/prawn.rb |
kosmas58-features2cards-0.3.92 | lib/features2cards/prawn.rb |
features2cards-0.3.1 | lib/features2cards/prawn.rb |