module TeachingPrintables::Gridable

Creates grid layouts for flashcards or math sheets. Delegates Prawn methods to Prawn::Document.

Attributes

grid_column_width[W]
grid_columns[W]
grid_gutter[W]
grid_row_height[W]
grid_rows[W]

Public Instance Methods

add_grid_content(content_array, options={}) click to toggle source
# File lib/teaching_printables/gridable.rb, line 36
def add_grid_content(content_array, options={})
  
  font_size = options[:font_size] || 60
  
  if (page_number ==0) || (options[:start_new_page] == true)
    start_new_page
  end

  
  @document.define_grid(grid_options)
  content_array.each_with_index {|obj,ind|
    
    if ind%(grid_rows*grid_columns)==0 && ind > 0
      @document.start_new_page
    end
  
    subs = ind2sub([grid_rows,grid_columns],ind%(grid_rows*grid_columns))
    @document.grid(subs[0],subs[1]).bounding_box do
      #place_contents_in_gridbox(obj)
      @document.text_box obj.to_s, align: :center, valign: :center, size: font_size, overflow: :shrink_to_fit
    end
  }
end
grid_column_width() click to toggle source
# File lib/teaching_printables/gridable.rb, line 22
def grid_column_width
  @grid_column_width ||= 100
end
grid_columns() click to toggle source
# File lib/teaching_printables/gridable.rb, line 16
def grid_columns
  @grid_coluns ||= 2
end
grid_gutter() click to toggle source
# File lib/teaching_printables/gridable.rb, line 19
def grid_gutter
  @grid_gutter ||= 0
end
grid_row_height() click to toggle source
# File lib/teaching_printables/gridable.rb, line 25
def grid_row_height
  @grid_row_height ||= 100
end
grid_rows() click to toggle source
# File lib/teaching_printables/gridable.rb, line 13
def grid_rows
  @grid_rows ||= 2
end
place_contents_in_gridbox(obj) click to toggle source
# File lib/teaching_printables/gridable.rb, line 62
def place_contents_in_gridbox(obj)
  text obj.to_s, fit: [grid_column_width,grid_row_height]
end
update_grid_options(options) click to toggle source
# File lib/teaching_printables/gridable.rb, line 30
def update_grid_options(options)
  options.each do |k,v|
    instance_variable_set("@grid_#{k}", options[k]) unless options[k].nil?
  end
end

Private Instance Methods

grid_options() click to toggle source
# File lib/teaching_printables/gridable.rb, line 67
def grid_options
  keys = %W[rows columns gutter column_width row_height]
  Hash[keys.map { |key| [key.to_sym, self.send("grid_#{key}")] } ]
end