lib/thinreports/generator/pdf.rb in thinreports-0.7.7 vs lib/thinreports/generator/pdf.rb in thinreports-0.8.0
- old
+ new
@@ -1,68 +1,65 @@
# coding: utf-8
begin
- gem 'prawn', '0.12.0'
+ gem 'prawn', '1.3.0'
require 'prawn'
rescue LoadError
- puts 'ThinReports requires Prawn = 0.12.0. ' +
- 'Please `gem install prawn -v 0.12.0` and try again.'
+ puts 'Thinreports requires Prawn = 1.3.0. ' +
+ 'Please `gem install prawn -v 1.3.0` and try again.'
end
-module ThinReports
+module Thinreports
module Generator
-
+
class PDF < Base
- # @param report (see ThinReports::Generator::Base#initialize)
+ # @param report (see Thinreports::Generator::Base#initialize)
# @param [Hash] options
# @option options [Hash] :security (nil)
# See Prawn::Document#encrypt_document
def initialize(report, options)
super
-
+
title = default_layout ? default_layout.format.report_title : nil
- @pdf = Document.new(options, :Title => title)
+ @document = Document.new(options, Title: title)
@drawers = {}
end
-
- # @see ThinReports::Generator::Base#generate
- def generate
+
+ # @see Thinreports::Generator::Base#generate
+ def generate(filename = nil)
draw_report
- @pdf.render
+ filename ? @document.render_file(filename) : @document.render
end
-
- # @see ThinReports::Generator::Base#generate_file
- def generate_file(filename)
- draw_report
- @pdf.render_file(filename)
- end
-
+
private
-
+
def draw_report
report.pages.each do |page|
draw_page(page)
end
end
-
+
def draw_page(page)
- return @pdf.add_blank_page if page.blank?
-
+ return @document.add_blank_page if page.blank?
+
format = page.layout.format
- @pdf.start_new_page(format)
-
+ @document.start_new_page(format)
+
drawer(format).draw(page)
end
-
+
def drawer(format)
- @drawers[format.identifier] ||= Drawer::Page.new(@pdf, format)
- end
+ @drawers[format.identifier] ||= Drawer::Page.new(@document, format)
+ end
end
-
+
end
end
require 'thinreports/generator/pdf/configuration'
require 'thinreports/generator/pdf/prawn_ext'
require 'thinreports/generator/pdf/document'
-require 'thinreports/generator/pdf/drawer'
+require 'thinreports/generator/pdf/drawer/base'
+require 'thinreports/generator/pdf/drawer/page'
+require 'thinreports/generator/pdf/drawer/list'
+require 'thinreports/generator/pdf/drawer/list_section'