lib/mork/sheet_pdf.rb in mork-0.8.1 vs lib/mork/sheet_pdf.rb in mork-0.9.0
- old
+ new
@@ -1,34 +1,41 @@
require 'mork/grid_pdf'
require 'prawn'
module Mork
- #TODO: read the prawn manual, we should probably use views
-
+ # Generating response sheets as PDF files.
+ # See the README file for usage
class SheetPDF < Prawn::Document
- def initialize(content, grip=GridPDF.new)
- @grip = case grip
- when String, Hash; GridPDF.new grip
- when Mork::GridPDF; grip
+ def initialize(content, layout=nil)
+ @grip = case layout
+ when NilClass; GridPDF.new
+ when String, Hash; GridPDF.new layout
+ when Mork::GridPDF; layout
else raise ArgumentError, 'Invalid initialization parameter'
end
super my_page_params
# @content should be an array of hashes, one per page;
# convert to array if a single hash was passed
@content = content.class == Hash ? [content] : content
process
end
- def save(fn)
- render_file fn
+ # Saving the PDF file to disk
+ #
+ # @param fname [String] the path/filename for the target PDF document
+ def save(fname)
+ render_file fname
end
+ # The PDF document as a string
def to_pdf
render
end
+ ###########################################################################
private
+ ###########################################################################
def my_page_params
{
page_size: @grip.page_size,
margin: @grip.margins