Class: DTK::Client::ViewProcessor

Inherits:
Object
  • Object
show all
Extended by:
Auxiliary
Defined in:
lib/view_processor.rb

Constant Summary collapse

AdapterCache =
Hash.new
AdapterCacheAug =
Hash.new

Class Method Summary collapse

Methods included from Auxiliary

cap_form, snake_form

Class Method Details

.get_adapter(type, command_class, data_type = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/view_processor.rb', line 50

def get_adapter(type,command_class,data_type=nil)

  data_type_index = use_data_type_index?(command_class,data_type)
  cached = 
    if data_type_index
      ((AdapterCacheAug[type]||{})[command_class]||{})[data_type_index]
    else
      (AdapterCache[type]||{})[command_class]
    end               

  return cached if cached
  dtk_nested_require("view_processor",type)
  klass = DTK::Client.const_get "ViewProc#{cap_form(type)}" 
  if data_type_index
    AdapterCacheAug[type] ||= Hash.new
    AdapterCacheAug[type][command_class] ||= Hash.new
    AdapterCacheAug[type][command_class][data_type_index] = klass.new(type,command_class,data_type_index)
  else
    AdapterCache[type] ||= Hash.new
    AdapterCache[type][command_class] = klass.new(type,command_class)               
  end
end

.render(command_class, ruby_obj, type, data_type, adapter = nil, print_error_table = false) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/view_processor.rb', line 30

def render(command_class, ruby_obj, type, data_type, adapter=nil, print_error_table=false)
  adapter ||= get_adapter(type,command_class,data_type)
  if type == RenderView::TABLE
    # for table there is only one rendering, we use command class to
    # determine output of the table
    adapter.render(ruby_obj, command_class, data_type, nil, print_error_table)
      
    # saying no additional print needed (see core class)
    return false
  elsif ruby_obj.kind_of?(Hash)
    adapter.render(ruby_obj)
  elsif ruby_obj.kind_of?(Array)
    ruby_obj.map{|el|render(command_class,el,type,nil,adapter)}
  elsif ruby_obj.kind_of?(String)
    ruby_obj
  else
    raise Error.new("ruby_obj has unexepected type")
  end
end