Class: BootWheel::Table
- Inherits:
-
Internals::Component
- Object
- Internals::Component
- BootWheel::Table
- Defined in:
- lib/boot_wheel/table.rb
Constant Summary collapse
- TEMPLATE =
t("table.erb")
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #applied_classes ⇒ Object
- #field_with_key(key) ⇒ Object
-
#initialize(items:, style_props: [], fields: items.first.keys, **params) ⇒ Table
constructor
A new instance of Table.
- #normalize_fields(fields) ⇒ Object
Methods inherited from Internals::Component
#helpers, #renderer, t, #to_html, #x
Constructor Details
#initialize(items:, style_props: [], fields: items.first.keys, **params) ⇒ Table
Returns a new instance of Table.
7 8 9 10 11 12 |
# File 'lib/boot_wheel/table.rb', line 7 def initialize(items:, style_props: [], fields: items.first.keys, **params) @items = items @style_props = style_props @fields = normalize_fields(fields) @params = params end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
14 15 16 |
# File 'lib/boot_wheel/table.rb', line 14 def fields @fields end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
14 15 16 |
# File 'lib/boot_wheel/table.rb', line 14 def items @items end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
14 15 16 |
# File 'lib/boot_wheel/table.rb', line 14 def params @params end |
Instance Method Details
#applied_classes ⇒ Object
16 17 18 |
# File 'lib/boot_wheel/table.rb', line 16 def applied_classes helpers.class_names(["table"] + @style_props.map { |e| "table-#{e}"} + (params[:table_class] || [])) end |
#field_with_key(key) ⇒ Object
28 29 30 |
# File 'lib/boot_wheel/table.rb', line 28 def field_with_key(key) @fields.find { |e| e[:key] == key } end |
#normalize_fields(fields) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/boot_wheel/table.rb', line 20 def normalize_fields(fields) item_keys = @items.first.keys fields.map.with_index do |e,i| Hash === e ? e : { key: item_keys[i], label: e } end end |