Class: ThinReports::Report::Internal
- Defined in:
- lib/thinreports/report/internal.rb
Instance Attribute Summary collapse
-
#default_layout ⇒ Object
readonly
Returns the value of attribute default_layout.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#layout_registry ⇒ Object
readonly
Returns the value of attribute layout_registry.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#page_count ⇒ Object
readonly
Returns the value of attribute page_count.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
Instance Method Summary collapse
- #add_page(new_page) ⇒ Object
- #copy_page ⇒ Object
- #finalize ⇒ Object
- #finalized? ⇒ Boolean
-
#initialize(report, options) ⇒ Internal
constructor
A new instance of Internal.
- #load_layout(id_or_filename) ⇒ Object
- #register_layout(layout, options = {}, &block) ⇒ Object
Constructor Details
#initialize(report, options) ⇒ Internal
Returns a new instance of Internal.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/thinreports/report/internal.rb', line 17 def initialize(report, ) @report = report # Default layout @default_layout = prepare_layout([:layout]) @layout_registry = {} @finalized = false @pages = [] @page = nil @page_count = 0 @events = Report::Events.new end |
Instance Attribute Details
#default_layout ⇒ Object (readonly)
Returns the value of attribute default_layout.
11 12 13 |
# File 'lib/thinreports/report/internal.rb', line 11 def default_layout @default_layout end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
13 14 15 |
# File 'lib/thinreports/report/internal.rb', line 13 def events @events end |
#layout_registry ⇒ Object (readonly)
Returns the value of attribute layout_registry.
12 13 14 |
# File 'lib/thinreports/report/internal.rb', line 12 def layout_registry @layout_registry end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
9 10 11 |
# File 'lib/thinreports/report/internal.rb', line 9 def page @page end |
#page_count ⇒ Object (readonly)
Returns the value of attribute page_count.
10 11 12 |
# File 'lib/thinreports/report/internal.rb', line 10 def page_count @page_count end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
8 9 10 |
# File 'lib/thinreports/report/internal.rb', line 8 def pages @pages end |
Instance Method Details
#add_page(new_page) ⇒ Object
46 47 48 49 |
# File 'lib/thinreports/report/internal.rb', line 46 def add_page(new_page) finalize_current_page insert_page(new_page) end |
#copy_page ⇒ Object
51 52 53 54 |
# File 'lib/thinreports/report/internal.rb', line 51 def copy_page finalize_current_page(:at => :copy) insert_page(page.copy) end |
#finalize ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/thinreports/report/internal.rb', line 56 def finalize unless finalized? finalize_current_page @finalized = true # Dispatch event on before generate. events.dispatch(Report::Events::Event.new(:generate, @report, nil, pages)) end end |
#finalized? ⇒ Boolean
67 68 69 |
# File 'lib/thinreports/report/internal.rb', line 67 def finalized? @finalized end |
#load_layout(id_or_filename) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/thinreports/report/internal.rb', line 71 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 prepare_layout(id_or_filename) else raise ArgumentError, 'Invalid argument for layout.' end @default_layout = layout unless @default_layout layout end |
#register_layout(layout, options = {}, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/thinreports/report/internal.rb', line 32 def register_layout(layout, = {}, &block) layout = if .empty? || [:default] @default_layout = init_layout(layout) else id = [:id].to_sym if layout_registry.key?(id) raise ArgumentError, "Id :#{id} is already in use." end layout_registry[id] = init_layout(layout, id) end layout.config(&block) end |