Sha256: 371517e2a2e3d6326b29b93ea90ddbd8b2f2b4e3cd7a8ea1141d3ef27587de80

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

require 'prawn'
require "prawn/measurement_extensions"

module DotGrid
  class Generator
    attr_accessor(
      :pdf,
      :file_name,
      :page_size,
      :grid,
      :dot_grid_page,
      :grid_page,
      :margin,
      :pages,
      :planner,
      :planner_page,
      :horizontal_rule,
      :horizontal_rule_page,
      :checkerboard,
      :checkerboard_page,
    )

    def initialize(params)
      @file_name = params[:file_name] || "dotgrid.pdf"
      @page_size = params[:page_size] || "LETTER"
      @margin = params[:margin] || 0.5
      @pages = params[:pages] || 1
      @pdf = Prawn::Document.new(margin: margin, page_size: page_size, skip_page_creation: true)
      params[:pdf] = pdf

      @dot_grid_page = DotGrid::Page::DotGrid.new(params) if params[:dot_grid]
      @planner_page = DotGrid::Page::Planner.new(params) if params[:planner]
      @grid_page = DotGrid::Page::Grid.new(params) if params[:grid]
      @horizontal_rule_page = DotGrid::Page::HorizontalRule.new(params) if params[:horizontal_rule]
      @checkerboard_page = DotGrid::Page::Checkerboard.new(params) if params[:checkerboard]
    end

    def generate
      (1..pages).each do |page|
        planner_page.generate if planner_page
        grid_page.generate if grid_page
        dot_grid_page.generate if dot_grid_page
        horizontal_rule_page.generate if horizontal_rule_page
        checkerboard_page.generate if checkerboard_page
      end
      pdf.render_file file_name
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dot_grid-0.0.5 lib/dot_grid/generator.rb
dot_grid-0.0.4 lib/dot_grid/generator.rb