Module: Bootstrap5RailsExtensions::TableHelper
- Defined in:
- app/helpers/bootstrap5_rails_extensions/table_helper.rb
Defined Under Namespace
Classes: TableBuilder
Instance Method Summary collapse
-
#render_table(data: {}, wrapper_class: nil, wrapper_html: {}, **html_options) {|builder| ... } ⇒ Object
Bootstrapのtableコンポーネント向け簡易DSL。.
Instance Method Details
#render_table(data: {}, wrapper_class: nil, wrapper_html: {}, **html_options) {|builder| ... } ⇒ Object
Bootstrapのtableコンポーネント向け簡易DSL。
使い方:
<%= render_table class: "table-striped" do |table| %>
<%= table.thead class: "table-light" do %>
<tr><th>
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/bootstrap5_rails_extensions/table_helper.rb', line 16 def render_table(data: {}, wrapper_class: nil, wrapper_html: {}, **) raise ArgumentError, "theadかtbodyを定義してください" unless block_given? builder = TableBuilder.new(self) yield(builder) raise ArgumentError, "theadかtbodyを最低1つは定義してください" if builder.empty? [:class] = build_table_class([:class]) [:data] = merge_data_attributes([:data], data) if data.present? = (wrapper_html, wrapper_class) content_tag(:div, **) do content_tag(:table, builder.render, **) end end |