Class: ThousandIsland::Components::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/thousand_island/components/base.rb

Direct Known Subclasses

Body, Footer, Header

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pdf, args = nil) ⇒ Base

Returns a new instance of Base.



7
8
9
10
# File 'lib/thousand_island/components/base.rb', line 7

def initialize(pdf, args=nil)
  @options = args || self.defaults
  @pdf = pdf
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/thousand_island/components/base.rb', line 5

def options
  @options
end

#pdfObject (readonly)

Returns the value of attribute pdf.



5
6
7
# File 'lib/thousand_island/components/base.rb', line 5

def pdf
  @pdf
end

Class Method Details

.defaultsObject



39
40
41
# File 'lib/thousand_island/components/base.rb', line 39

def self.defaults
  {}
end

Instance Method Details

#after_renderObject



21
22
23
# File 'lib/thousand_island/components/base.rb', line 21

def after_render
  nil
end

#defaultsObject



43
44
45
# File 'lib/thousand_island/components/base.rb', line 43

def defaults
  self.class.defaults
end

#draw(&block) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/thousand_island/components/base.rb', line 12

def draw(&block)
  if repeated?
    render_all &block
  else
    render &block
  end
  after_render
end

#render(&block) ⇒ Object

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/thousand_island/components/base.rb', line 31

def render(&block)
  raise NotImplementedError
end

#render_all(&block) ⇒ Object



25
26
27
28
29
# File 'lib/thousand_island/components/base.rb', line 25

def render_all(&block)
  pdf.repeat :all do
    render &block
  end
end

#repeated?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/thousand_island/components/base.rb', line 35

def repeated?
  false
end