class Paperize::Layout
Attributes
document[RW]
layout[R]
total_columns[R]
total_rows[R]
Public Class Methods
new(options={})
click to toggle source
# File lib/paperize/layout.rb, line 6 def initialize(options={}) @layout = options[:layout] || '3x3' @orientation = options[:orientation] || :portrait if layout == :card_per_page else @total_columns, @total_rows = layout.split('x').map(&:to_i) || [3, 3] @current_column = total_columns @current_row = total_rows end @template = options[:template] # page_size = layout == :card_per_page ? [2.5.in, 3.5.in] : 'LETTER' # @document = Prawn::Document.new( # skip_page_creation: true, # page_size: page_size, # page_layout: @orientation # ) end
Public Instance Methods
increment_current_cell()
click to toggle source
# File lib/paperize/layout.rb, line 63 def increment_current_cell @current_column += 1 if @current_column >= total_columns @current_column = 0 @current_row += 1 if @current_row >= total_rows @current_row = 0 document.start_new_page document.define_grid(columns: total_columns, rows: total_rows) end end end
layout_cards(cards)
click to toggle source
# File lib/paperize/layout.rb, line 36 def layout_cards(cards) card_margin = 0 cards.each do |card| next_cell do shrink_bounds(2) do document.line_width = 2 document.stroke_bounds end shrink_bounds(card_margin) do @template.render_block.call(document, card) end end end end
next_cell(&block)
click to toggle source
# File lib/paperize/layout.rb, line 52 def next_cell &block if layout == :card_per_page document.start_new_page document.canvas(&block) else increment_current_cell document.grid(@current_row, @current_column).bounding_box(&block) end end
shrink_bounds(margin, &block)
click to toggle source
# File lib/paperize/layout.rb, line 27 def shrink_bounds(margin, &block) margin_left = margin margin_top = document.bounds.top - margin margin_width = document.bounds.width - 2*margin margin_height = document.bounds.height - 2*margin document.bounding_box [margin_left, margin_top], width: margin_width, height: margin_height, &block end