Class: Showbuilder::Builders::ModelViewBuilder

Inherits:
Object
  • Object
show all
Includes:
TemplateMethods, I18nText
Defined in:
lib/showbuilder/builders/model_view_builder.rb

Instance Attribute Summary collapse

Attributes included from TemplateMethods

#template

Instance Method Summary collapse

Methods included from I18nText

#show_current_itext, #show_itext

Methods included from TemplateMethods

#method_missing

Constructor Details

#initialize(model, template) ⇒ ModelViewBuilder

Returns a new instance of ModelViewBuilder.



12
13
14
15
# File 'lib/showbuilder/builders/model_view_builder.rb', line 12

def initialize(model, template)
  @model      = model
  @template   = template
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Showbuilder::Builders::TemplateMethods

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



10
11
12
# File 'lib/showbuilder/builders/model_view_builder.rb', line 10

def model
  @model
end

Instance Method Details

#build_model_view(&block) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/showbuilder/builders/model_view_builder.rb', line 17

def build_model_view(&block)
  unless @model
    return
  end
  self.(:table, :class => "table table-bordered nohead") do
    @template.capture(self, &block)
  end
end

#show_currency(method) ⇒ Object



58
59
60
61
62
# File 'lib/showbuilder/builders/model_view_builder.rb', line 58

def show_currency(method)
  self.show_method_field(method) do |value|
    self.currency_string(value)
  end
end

#show_date(method) ⇒ Object



52
53
54
55
56
# File 'lib/showbuilder/builders/model_view_builder.rb', line 52

def show_date(method)
  self.show_method_field(method) do |value|
    self.date_string(value)
  end
end

#show_method_field(*method, &block) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/showbuilder/builders/model_view_builder.rb', line 70

def show_method_field(*method, &block)
  method_label = self.show_current_itext(method)
  method_value = self.call_object_methods(model, method)
  if block
    method_value = block.call(method_value)
  end

  self.contents_tag :tr do |contents|
    contents << self.(:td, method_label.to_s)
    contents << self.(:td, method_value.to_s)
  end
end

#show_percent(method) ⇒ Object



64
65
66
67
68
# File 'lib/showbuilder/builders/model_view_builder.rb', line 64

def show_percent(method)
  self.show_method_field(method) do |value|
    self.percent_string(value)
  end
end

#show_text(*methods) ⇒ Object



26
27
28
29
30
# File 'lib/showbuilder/builders/model_view_builder.rb', line 26

def show_text(*methods)
  self.show_method_field(*methods) do |value|
    self.safe_html_string(value)
  end
end


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/showbuilder/builders/model_view_builder.rb', line 32

def show_text_link(link_method, text_method)
  methods      = [link_method, text_method]
  method_label = self.show_current_itext(methods)
  method_value = self.call_object_methods(model, methods)
  method_link  = self.call_object_methods(model, link_method)

  self.contents_tag :tr do |contents|
    contents << self.(:td, method_label.to_s)
    contents << self.(:td) do
      self.show_model_link_to(method_value.to_s, method_link)
    end
  end
end

#show_time(method) ⇒ Object



46
47
48
49
50
# File 'lib/showbuilder/builders/model_view_builder.rb', line 46

def show_time(method)
  self.show_method_field(method) do |value|
    self.time_string(value)
  end
end