Class: Effective::TableRow

Inherits:
Object
  • Object
show all
Defined in:
app/models/effective/table_row.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, builder:) ⇒ TableRow

So this takes in the options for an entire form group.



11
12
13
14
15
16
17
# File 'app/models/effective/table_row.rb', line 11

def initialize(name, options, builder:)
  @builder = builder
  @template = builder.template

  @name = name
  @options = options
end

Instance Attribute Details

#builderObject

Returns the value of attribute builder.



5
6
7
# File 'app/models/effective/table_row.rb', line 5

def builder
  @builder
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'app/models/effective/table_row.rb', line 5

def name
  @name
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'app/models/effective/table_row.rb', line 5

def options
  @options
end

#templateObject

Returns the value of attribute template.



5
6
7
# File 'app/models/effective/table_row.rb', line 5

def template
  @template
end

Instance Method Details

#contentObject

Intended for override



24
25
26
# File 'app/models/effective/table_row.rb', line 24

def content
  value
end

#controller_namespaceObject



19
20
21
# File 'app/models/effective/table_row.rb', line 19

def controller_namespace
  Effective::Resource.new(template.controller.controller_path).namespace
end

#hintObject



53
54
55
56
57
58
59
60
# File 'app/models/effective/table_row.rb', line 53

def hint
  text = options[:hint]
  return if text.blank?

  (:div) do
    (:small, text.html_safe, class: 'text-muted')
  end
end

#labelObject

Humanized label or the label from form



46
47
48
49
50
51
# File 'app/models/effective/table_row.rb', line 46

def label
  text = options[:label] || EffectiveResources.et(builder.object, name)
  prefix = builder.options[:prefix]

  [*prefix, text].join(': ')
end

#label_contentObject



39
40
41
42
43
# File 'app/models/effective/table_row.rb', line 39

def label_content
  label.html_safe
  # hint = self.hint
  # (hint.present? ? "#{label}#{hint}" : label).html_safe
end

#to_html(&block) ⇒ Object

Render method



33
34
35
36
37
# File 'app/models/effective/table_row.rb', line 33

def to_html(&block)
  (:tr, class: tr_class) do
    (:th, label_content) + (:td, content.presence || '-')
  end
end

#tr_classObject



28
29
30
# File 'app/models/effective/table_row.rb', line 28

def tr_class
  "row-#{name}" # This matches datatables which is "col-#{name}"
end

#valueObject

Value from resource



63
64
65
# File 'app/models/effective/table_row.rb', line 63

def value
  options[:value] || builder.value(name)
end