Class: SimpleModelView::ResourceTableBuilder
- Inherits:
-
Object
- Object
- SimpleModelView::ResourceTableBuilder
- Includes:
- BuilderHelpers, TemplateHelpers
- Defined in:
- lib/simple_model_view/resource_table_builder.rb
Instance Attribute Summary collapse
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
- #actions(*_args, **options) ⇒ Object
-
#initialize(template, object, *_args, formatter: SimpleModelView.formatter) ⇒ ResourceTableBuilder
constructor
A new instance of ResourceTableBuilder.
-
#row(attr_name, title: nil, **options, &block) ⇒ Object
Renders row for given
attr_name.
Methods included from BuilderHelpers
Methods included from TemplateHelpers
#blank_span, #block_concat, #merge_html_attrs
Constructor Details
#initialize(template, object, *_args, formatter: SimpleModelView.formatter) ⇒ ResourceTableBuilder
Returns a new instance of ResourceTableBuilder.
8 9 10 11 12 |
# 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 |
Instance Attribute Details
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
14 15 16 |
# File 'lib/simple_model_view/resource_table_builder.rb', line 14 def formatter @formatter end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
14 15 16 |
# File 'lib/simple_model_view/resource_table_builder.rb', line 14 def object @object end |
Instance Method Details
#actions(*_args, **options) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/simple_model_view/resource_table_builder.rb', line 60 def actions(*_args, **) template.content_tag(:tr) do template.concat template.content_tag(:th, [:title]) block_concat do template.content_tag(:td) do yield object if block_given? end end end end |
#row(attr_name, title: nil, **options, &block) ⇒ Object
Renders row for given attr_name.
Arguments
-
attr_name- Attribute to be rendered as aSymbolorString. -
title:-Stringto use as attribute name in table. Usinghuman_attribute_nameor if not given. -
as:- Force attribute value type _(:boolean, :date, :time, :integer, :float, etc…)_. -
collection:- Iftruetryes 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:-Hashwith values asSymbolor 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 notfalseornilhash 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:
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/simple_model_view/resource_table_builder.rb', line 43 def row(attr_name, title: nil, **, &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: ) label_html = [:label_html] || {} value_html = [:value_html] || {} render_row title, render_data[:wrapper_html], label_html, value_html do render_value render_data, , &block end end |