Class: ListBuilder
Instance Attribute Summary
#args, #block, #context, #model
Instance Method Summary
collapse
#initialize, render
Instance Method Details
#localized_value(key, model, attribute) ⇒ Object
13
14
15
|
# File 'lib/activeadmin_addons/addons/list.rb', line 13
def localized_value(key, model, attribute)
I18n.t("addons_list.#{model.class.name.underscore}.#{attribute}.#{key}")
end
|
#render ⇒ Object
3
4
5
6
7
8
9
10
11
|
# File 'lib/activeadmin_addons/addons/list.rb', line 3
def render
options[:localize] = options.fetch(:localize, false)
options[:list_type] = options.fetch(:list_type, :ul)
raise 'invalid list type (ul, ol)' unless [:ul, :ol].include?(options[:list_type])
raise "list must be Array or Hash" if !data.is_a?(Hash) && !data.is_a?(Array)
data.is_a?(Array) ? render_array : render_hash
end
|
#render_array ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/activeadmin_addons/addons/list.rb', line 17
def render_array
context.content_tag(options[:list_type]) do
data.each do |value|
value = localized_value(value, model, attribute) if !!options[:localize]
context.concat(context.content_tag(:li, value))
end
end
end
|
#render_hash ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/activeadmin_addons/addons/list.rb', line 26
def render_hash
context.content_tag(options[:list_type]) do
data.keys.each do |key|
label = !!options[:localize] ? localized_value(key, model, attribute) : key
value = data[key]
context.concat(context.content_tag(:li) do
if value.blank?
context.content_tag(:span, label)
else
context.content_tag(:span) do
context.concat("#{label}: ".html_safe)
context.concat(context.content_tag(:span) do
context.content_tag(:i, value)
end)
end
end
end)
end
end
end
|