Class: ThinReports::Report::Internal

Inherits:
Object
  • Object
show all
Defined in:
lib/thinreports/report/internal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report, options) ⇒ Internal

Returns a new instance of Internal.

Parameters:



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/thinreports/report/internal.rb', line 17

def initialize(report, options)
  @report = report
  # Default layout
  @default_layout = prepare_layout(options[:layout])

  @layout_registry = {}
  @finalized  = false
  @pages      = []
  @page       = nil
  @page_count = 0
  
  @events = Report::Events.new
end

Instance Attribute Details

#default_layoutObject (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

#eventsObject (readonly)

Returns the value of attribute events.



13
14
15
# File 'lib/thinreports/report/internal.rb', line 13

def events
  @events
end

#layout_registryObject (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

#pageObject (readonly)

Returns the value of attribute page.



9
10
11
# File 'lib/thinreports/report/internal.rb', line 9

def page
  @page
end

#page_countObject (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

#pagesObject (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_pageObject



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

#finalizeObject



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

Returns:

  • (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

See Also:



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, options = {}, &block)
  layout = if options.empty? || options[:default]
    @default_layout = init_layout(layout)
  else
    id = options[: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