Class: Admino::Table::ResourceRow
- Inherits:
-
Row
- Object
- Row
- Admino::Table::ResourceRow
show all
- Defined in:
- lib/admino/table/resource_row.rb
Instance Attribute Summary collapse
Attributes inherited from Row
#view_context
Instance Method Summary
collapse
Methods inherited from Row
#parse_action_args, #parse_column_args
Constructor Details
#initialize(resource, view_context) ⇒ ResourceRow
Returns a new instance of ResourceRow.
9
10
11
12
13
14
15
|
# File 'lib/admino/table/resource_row.rb', line 9
def initialize(resource, view_context)
@resource = resource
@columns = ""
@actions = []
super(view_context)
end
|
Instance Attribute Details
#resource ⇒ Object
Returns the value of attribute resource.
7
8
9
|
# File 'lib/admino/table/resource_row.rb', line 7
def resource
@resource
end
|
Instance Method Details
#action(*args, &block) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/admino/table/resource_row.rb', line 46
def action(*args, &block)
if block_given?
@actions << h.capture(resource, &block)
else
action_name, url, label, html_options = parse_action_args(args)
label ||= action_label(action_name)
url ||= action_url(action_name)
html_options = complete_action_html_options(
action_name,
html_options
)
@actions << h.link_to(label, url, html_options)
end
end
|
#actions(*actions, &block) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/admino/table/resource_row.rb', line 36
def actions(*actions, &block)
if block_given?
h.capture(&block)
else
actions.each do |action|
action(action)
end
end
end
|
#column(*args, &block) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/admino/table/resource_row.rb', line 17
def column(*args, &block)
attribute_name, label, html_options = parse_column_args(args)
html_options = complete_column_html_options(
attribute_name,
html_options
)
if block_given?
content = h.capture(resource, &block)
elsif attribute_name.present?
content = resource.send(attribute_name)
else
raise ArgumentError, 'attribute name or block required'
end
@columns << h.content_tag(:td, content, html_options)
end
|
#to_html ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/admino/table/resource_row.rb', line 63
def to_html
buffer = @columns
if @actions.any?
html_options = column_html_options(:actions)
buffer << h.content_tag(:td, html_options) do
@actions.join(" ").html_safe
end
end
buffer.html_safe
end
|