Class: Nemo::Visitors::Viewer

Inherits:
Visitor
  • Object
show all
Defined in:
lib/nemo/visitors/viewer.rb

Direct Known Subclasses

Examples::PersonEditor::ListItemViewer

Instance Attribute Summary

Attributes inherited from Visitor

#metaobject

Instance Method Summary collapse

Methods included from Util::Accessors

#bool_accessor, #call_accessor, #proc_accessor

Constructor Details

#initialize(metaobject) ⇒ Viewer

Returns a new instance of Viewer.



3
4
5
6
# File 'lib/nemo/visitors/viewer.rb', line 3

def initialize(metaobject)
  super
  @viewer = true
end

Instance Method Details

#renderObject



8
9
10
# File 'lib/nemo/visitors/viewer.rb', line 8

def render
  r.table { render_fields }
end

#render_fieldsObject



12
13
14
# File 'lib/nemo/visitors/viewer.rb', line 12

def render_fields
  @metaobject.accept(self)
end

#render_label(a, &block) ⇒ Object



16
17
18
19
20
21
# File 'lib/nemo/visitors/viewer.rb', line 16

def render_label(a, &block)
  r.table_row do
    r.table_header(a.label)
    r.table_data { block ? block.call : r.space }
  end
end

#render_relationship_item(a, item) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/nemo/visitors/viewer.rb', line 23

def render_relationship_item(a, item)
  return if item.nil?
  text = a.format(item)
  if a.link_action.nil?
    r.encode_text(text)
  else
    r.anchor.callback{ a.link_action.call(item) }.with { r.encode_text(text) }
  end
end

#visit_boolean_attribute(a) ⇒ Object



45
46
47
# File 'lib/nemo/visitors/viewer.rb', line 45

def visit_boolean_attribute(a)
  visit_text_attribute(a)
end

#visit_date_attribute(a) ⇒ Object



41
42
43
# File 'lib/nemo/visitors/viewer.rb', line 41

def visit_date_attribute(a)
  visit_text_attribute(a)
end

#visit_multiple_attribute(a) ⇒ Object



49
50
51
# File 'lib/nemo/visitors/viewer.rb', line 49

def visit_multiple_attribute(a)
  visit_multiple_relationship_attribute(a)
end

#visit_multiple_relationship_attribute(a) ⇒ Object



57
58
59
60
61
# File 'lib/nemo/visitors/viewer.rb', line 57

def visit_multiple_relationship_attribute(a)
  render_label(a) do
    a.value.each { |item| render_relationship_item(a, item); r.break }
  end
end

#visit_password_attribute(a) ⇒ Object



37
38
39
# File 'lib/nemo/visitors/viewer.rb', line 37

def visit_password_attribute(a)
  render_label(a) { r.text('********') }
end

#visit_single_relationship_attribute(a) ⇒ Object



53
54
55
# File 'lib/nemo/visitors/viewer.rb', line 53

def visit_single_relationship_attribute(a) 	
  render_label(a) { render_relationship_item(a, a.value) }
end

#visit_text_attribute(a) ⇒ Object



33
34
35
# File 'lib/nemo/visitors/viewer.rb', line 33

def visit_text_attribute(a)
  render_label(a) { r.encode_text(a.formatted_value) }
end