Class: Grouik::Formatter

Inherits:
Object
  • Object
show all
Defined in:
src/lib/grouik/formatter.rb

Overview

Formatter used to render loadables

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loadables, options = {}) ⇒ Formatter

Returns a new instance of Formatter.



18
19
20
21
22
23
24
# File 'src/lib/grouik/formatter.rb', line 18

def initialize(loadables, options = {})
  @loadables = loadables
  @options   = options
  @formatted = nil
  @engine    = Tenjin::Engine.new(cache: false)
  @template  = options[:template]
end

Instance Attribute Details

#loadablesObject (readonly)

Returns the value of attribute loadables.



15
16
17
# File 'src/lib/grouik/formatter.rb', line 15

def loadables
  @loadables
end

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'src/lib/grouik/formatter.rb', line 14

def options
  @options
end

#templatePathname|nil (readonly)

Returns:

  • (Pathname|nil)


27
28
29
# File 'src/lib/grouik/formatter.rb', line 27

def template
  @template
end

Class Method Details

.format(loadables, options = {}) ⇒ Object



47
48
49
# File 'src/lib/grouik/formatter.rb', line 47

def format(loadables, options = {})
  self.new(loadables, options).format
end

Instance Method Details

#formatObject



35
36
37
38
39
# File 'src/lib/grouik/formatter.rb', line 35

def format
  @formatted = @formatted.nil? ? output : @formatted

  return self
end

#formattedObject



41
42
43
44
# File 'src/lib/grouik/formatter.rb', line 41

def formatted
  format
  @formatted.clone
end

#to_sObject



31
32
33
# File 'src/lib/grouik/formatter.rb', line 31

def to_s
  formatted
end