lib/thinreports/generator/pdf.rb in thinreports-0.9.1 vs lib/thinreports/generator/pdf.rb in thinreports-0.10.0
- old
+ new
@@ -1,40 +1,40 @@
-# coding: utf-8
+# frozen_string_literal: true
-begin
- gem 'prawn', '1.3.0'
- require 'prawn'
-rescue LoadError
- puts 'Thinreports requires Prawn = 1.3.0. ' +
- 'Please `gem install prawn -v 1.3.0` and try again.'
-end
+require 'prawn'
module Thinreports
module Generator
+ class PDF
+ # @return [Thinreports::Report::Base]
+ attr_reader :report
- class PDF < Base
- # @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
+ # @param [Thinreports::Report::Base] report
+ # @param [Hash] security (nil)
+ def initialize(report, security: nil)
+ report.finalize
+ @report = report.internal
title = default_layout ? default_layout.format.report_title : nil
- @document = Document.new(options, Title: title)
+ @document = Document.new(title: title, security: security)
@drawers = {}
end
- # @see Thinreports::Generator::Base#generate
+ # @param [String, nil] filename
+ # @return [String, nil]
def generate(filename = nil)
draw_report
filename ? @document.render_file(filename) : @document.render
end
- private
+ def default_layout
+ report.default_layout
+ end
+ private
+
def draw_report
report.pages.each do |page|
draw_page(page)
end
end
@@ -50,15 +50,14 @@
def drawer(format)
@drawers[format.identifier] ||= Drawer::Page.new(@document, format)
end
end
-
end
end
-require 'thinreports/generator/pdf/prawn_ext'
-require 'thinreports/generator/pdf/document'
-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'
+require_relative 'pdf/prawn_ext'
+require_relative 'pdf/document'
+require_relative 'pdf/drawer/base'
+require_relative 'pdf/drawer/page'
+require_relative 'pdf/drawer/list'
+require_relative 'pdf/drawer/list_section'