Class: ThinreportsHandler::ThinreportsTemplate

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/thinreports-handler/template_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thinreports_report_base_obj, template_context, template_virtual_path) ⇒ ThinreportsTemplate

Returns a new instance of ThinreportsTemplate.



10
11
12
13
14
# File 'lib/thinreports-handler/template_handler.rb', line 10

def initialize(thinreports_report_base_obj, template_context, template_virtual_path)
  @_template_context = template_context
  @_template_virtual_path = template_virtual_path
  super(thinreports_report_base_obj)
end

Instance Attribute Details

#_generate_optionsObject

Returns the value of attribute _generate_options.



8
9
10
# File 'lib/thinreports-handler/template_handler.rb', line 8

def _generate_options
  @_generate_options
end

Instance Method Details

#generate_options(options) ⇒ Object



31
32
33
# File 'lib/thinreports-handler/template_handler.rb', line 31

def generate_options(options)
  self._generate_options = options
end

#partial!(options, locals = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/thinreports-handler/template_handler.rb', line 16

def partial!(options, locals = {})
  case options
  when Hash
    options[:locals] ||= {}
    options[:locals].merge!(:report => self)
    @_template_context.render(options)
  else
    @_template_context.render(options, locals.merge(:report => self))
  end
end

#search_tlf_path(virtual_path) ⇒ Object



27
28
29
# File 'lib/thinreports-handler/template_handler.rb', line 27

def search_tlf_path(virtual_path)
  "#{virtual_path || @_template_virtual_path}.tlf"
end

#set_layout(options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/thinreports-handler/template_handler.rb', line 35

def set_layout(options = {})
  _options = options ? options.dup: {}
  tlf_path = search_tlf_path(_options[:tlf])

  ActionController::Base.view_paths.each do |view_path|
    full_path = File.join(view_path.to_s, tlf_path)
    if File.exist?(full_path)
      return self.use_layout(full_path, *([_options[:layout_options]].compact))
    end
  end
  raise("#{tlf_path} not found.")
end