lib/thinreports/report/base.rb in thinreports-0.7.6 vs lib/thinreports/report/base.rb in thinreports-0.7.7
- old
+ new
@@ -5,10 +5,13 @@
class Base
# @return [ThinReports::Report::Internal]
# @private
attr_reader :internal
+
+ # @return [Integer]
+ attr_reader :start_page_number
class << self
# @param options (see #initialize)
# @option options (see #initialize)
# @yield [report]
@@ -50,14 +53,15 @@
# @overload generate_file(filename, options = {}, &block)
# @param filename (see #generate_file)
# @yield (see .create)
# @yieldparam (see .create)
# @see .generate
+ # @deprecated Please use the #generate method with :filename option instead.
# @return [void]
def generate_file(*args, &block)
raise ArgumentError, '#generate_file requires a block' unless block_given?
-
+
report_opts, generator_opts = extract_options!(args)
report = create(report_opts, &block)
report.generate_file(*args.push(generator_opts))
end
@@ -85,11 +89,17 @@
# @param [Hash] options
# @option options [String, nil] :layout (nil)
def initialize(options = {})
@internal = Report::Internal.new(self, options)
+ @start_page_number = 1
end
+
+ # @param [Integer] page_number
+ def start_page_number_from(page_number)
+ @start_page_number = page_number
+ end
# @param [String] layout path to layout-file.
# @param [Hash] options
# @option options [Boolean] :default (true)
# @option options [Symbol] :id (nil)
@@ -100,19 +110,20 @@
internal.register_layout(layout, options, &block)
end
# @param [Hash] options
# @option options [String, Symbol] :layout (nil)
+ # @option options [Boolean] :count (true)
# @yield [page]
# @yieldparam [ThinReports::Core::Page] page
# @return [ThinReports::Core::Page]
def start_new_page(options = {}, &block)
- unless layout = internal.load_layout(options[:layout])
+ unless layout = internal.load_layout(options.delete(:layout))
raise ThinReports::Errors::NoRegisteredLayoutFound
end
- page = internal.add_page(layout.init_new_page(self))
+ page = internal.add_page(layout.init_new_page(self, options))
block_exec_on(page, &block)
end
# @param [Hash] options
# @option options [Boolean] :count (true)
@@ -145,27 +156,46 @@
# @return [String]
# @overload generate(options = {})
# Using the default generator type.
# @param [Hash] options ({})
# @return [String]
+ # @example Generate the PDF data
+ # report.generate(:pdf) #=> "%PDF-1.4...."
+ #
+ # # Or, you can omit the type of generator
+ # report.generate
+ # @example Create the PDF file (Since v0.8)
+ # report.generate(:pdf, :filename => 'foo.pdf')
def generate(*args)
options = args.last.is_a?(::Hash) ? args.pop : {}
- type = args.first || ThinReports.config.generator.default
- ThinReports::Generator.new(type, self, options).generate
+ type = args.first || ThinReports.config.generator.default
+ filename = options.delete(:filename)
+ generator = ThinReports::Generator.new(type, self, options)
+
+ if filename
+ generator.generate_file(filename)
+ else
+ generator.generate
+ end
end
# @overload generate_file(type, filename, options = {})
# @param type (#generate)
# @return [void]
# @overload generate_file(filename, options = {})
# @param [String] filename
# @param options (see #generate)
# @return [void]
+ # @deprecated Please use the #generate method with :filename option instead.
def generate_file(*args)
+ warn '[DEPRECATION] The #generate_file method is deprecated. ' +
+ 'Please use the #generate(:filename => "filename") instead.'
+
options = args.last.is_a?(::Hash) ? args.pop : {}
args.unshift(ThinReports.config.generator.default) if args.size == 1
type, filename = args
- ThinReports::Generator.new(type, self, options).generate_file(filename)
+
+ generate(type, options.merge(:filename => filename))
end
# @see ThinReports::Core::Shape::Manager::Target#list
def list(id = nil, &block)
start_new_page if page.nil? || page.finalized?