class Thinreports::Report::Internal
Attributes
default_layout[R]
layout_registry[R]
page[R]
page_count[R]
page_create_handler[RW]
pages[R]
Public Class Methods
new(report, options)
click to toggle source
@param [Thinreports::Report::Base] report @param options (see Thinreports::Report::Base#initialize)
# File lib/thinreports/report/internal.rb, line 16 def initialize(report, options) @report = report @default_layout = options[:layout] ? init_layout(options[:layout]) : nil @layout_registry = {} @finalized = false @pages = [] @page = nil @page_count = 0 @page_create_handler = nil end
Public Instance Methods
add_page(new_page)
click to toggle source
# File lib/thinreports/report/internal.rb, line 41 def add_page(new_page) finalize_current_page insert_page(new_page) end
copy_page()
click to toggle source
# File lib/thinreports/report/internal.rb, line 46 def copy_page finalize_current_page(at: :copy) insert_page(page.copy) end
finalize()
click to toggle source
# File lib/thinreports/report/internal.rb, line 51 def finalize return if finalized? finalize_current_page @finalized = true end
finalized?()
click to toggle source
# File lib/thinreports/report/internal.rb, line 58 def finalized? @finalized end
load_layout(id_or_filename)
click to toggle source
# File lib/thinreports/report/internal.rb, line 62 def load_layout(id_or_filename) return @default_layout if id_or_filename.nil? layout = case id_or_filename when Symbol layout_registry[id_or_filename] when String init_layout(id_or_filename) else raise ArgumentError, 'Invalid argument for layout.' end @default_layout ||= layout layout end
register_layout(layout, options = {})
click to toggle source
@see Thinreports::Report::Base#use_layout
# File lib/thinreports/report/internal.rb, line 30 def register_layout(layout, options = {}) if options.empty? || options[:default] @default_layout = init_layout(layout) else id = options[:id].to_sym raise ArgumentError, "Id :#{id} is already in use." if layout_registry.key?(id) layout_registry[id] = init_layout(layout, id) end end
Private Instance Methods
finalize_current_page(options = {})
click to toggle source
@param (see Thinreports::Report::Page#finalize
)
# File lib/thinreports/report/internal.rb, line 94 def finalize_current_page(options = {}) page.finalize(options) unless page.nil? || page.blank? end
init_layout(filename, id = nil)
click to toggle source
# File lib/thinreports/report/internal.rb, line 98 def init_layout(filename, id = nil) filename = filename.to_path if filename.is_a?(Pathname) Thinreports::Layout.new(filename, id: id) end
insert_page(new_page)
click to toggle source
# File lib/thinreports/report/internal.rb, line 81 def insert_page(new_page) @pages << new_page if new_page.count? @page_count += 1 new_page.no = @page_count end @page_create_handler.call(new_page) if !new_page.blank? && @page_create_handler @page = new_page end