class SimpleModelView::ResourceTableBuilder
Attributes
Public Class Methods
# File lib/simple_model_view/resource_table_builder.rb, line 8 def initialize(template, object, *_args, formatter: SimpleModelView.formatter) @template = template @object = object @formatter = formatter end
Public Instance Methods
# File lib/simple_model_view/resource_table_builder.rb, line 60 def actions(*_args, **options) template.content_tag(:tr) do template.concat template.content_tag(:th, options[:title]) block_concat do template.content_tag(:td) do yield object if block_given? end end end end
Renders row for given attr_name
.
Arguments¶ ↑
-
attr_name
- Attribute to be rendered as aSymbol
orString
. -
title:
-String
to use as attribute name in table. Usinghuman_attribute_name
or if not given. -
as:
- Force attribute value type _(:boolean, :date, :time, :integer, :float, etc…)_. -
collection:
- Iftrue
tryes to interpret value as a iterateble collection. -
type_specific_class:
- adds type specific classes to the wrapper <tr> tag. For numeric it would be `negative`, `zero`, `positieve`; For date and time it would be `past`, `future`, `yesterday`, etc; See Examples for more details. -
custom_class:
-Hash
with values asSymbol
or any +callable object+. symbol will be sent to the value as a method. Proc will be called and passed a value as an argument. If method or block retuns notfalse
ornil
hash key will be added as a class to the wrapper <tr> tag. -
wrapper_html:
- html attributes to add to wrapper <tr> tag. -
label_html:
- html attributes to add to attribute title <th> tag. -
value_html:
- html attributes to add to attribute value <td> tag. -
+**options+ - all other named arguments will be passed to the formatter.
-
&block - if block given it will render inside value cell.
Examples¶ ↑
TODO:
# File lib/simple_model_view/resource_table_builder.rb, line 43 def row(attr_name, title: nil, **options, &block) title ||= if object.class.respond_to?(:human_attribute_name) object.class.human_attribute_name attr_name else attr_name.to_s.humanize end render_data = prepare_render_data(attr_name: attr_name, options: options) label_html = options[:label_html] || {} value_html = options[:value_html] || {} render_row title, render_data[:wrapper_html], label_html, value_html do render_value render_data, options, &block end end
Private Instance Methods
# File lib/simple_model_view/resource_table_builder.rb, line 92 def default_label_html SimpleModelView.resource_label_html end
# File lib/simple_model_view/resource_table_builder.rb, line 96 def default_value_html SimpleModelView.resource_value_html end
# File lib/simple_model_view/resource_table_builder.rb, line 88 def default_wrapper_html SimpleModelView.resource_wrapper_html end
# File lib/simple_model_view/resource_table_builder.rb, line 75 def render_row(title, wrapper_html, label_html, value_html) template.content_tag(:tr, **merge_html_attrs(default_wrapper_html, wrapper_html)) do template.concat template.content_tag(:th, title, **merge_html_attrs(default_label_html, label_html)) block_concat do template.content_tag :td, nil, **merge_html_attrs(default_value_html, value_html) do yield end end end end