Module: FuiHelper
- Defined in:
- app/helpers/fui_helper.rb
Overview
Provides the fui_javascript_tags helper for loading jQuery and Fomantic-UI component scripts in the correct order.
Usage (in your application layout, before javascript_importmap_tags):
<%= fui_javascript_tags %>
<%= javascript_importmap_tags %>
This emits <script> tags for jQuery and each Fomantic-UI component. The Stimulus bridge controllers are loaded separately via importmap.
Constant Summary collapse
- FOMANTIC_SCRIPTS =
Fomantic component scripts in load order. site and transition must come first — other components depend on them.
%w[ site transition accordion api calendar checkbox dimmer dropdown embed flyout form modal nag popup progress rating search shape sidebar slider state sticky tab toast visibility ].freeze
Instance Method Summary collapse
-
#datatable(columns: [], options: {}, &block) ⇒ Object
Renders a DataTables-powered table via Stimulus controller.
- #fui_javascript_tags ⇒ Object
Instance Method Details
#datatable(columns: [], options: {}, &block) ⇒ Object
Renders a DataTables-powered table via Stimulus controller.
Generates a <table> with Fomantic-UI styling, wrapped in a <div> annotated with the fui-datatable Stimulus controller. The block should yield <tr> rows for the <tbody>.
datatable(columns: ["Name", "Status"], options: { pageLength: 50 }) do
@records.each do |record|
TableRow {
TableCell { text record.name }
TableCell { text record.status }
}
end
end
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/helpers/fui_helper.rb', line 70 def datatable(columns: [], options: {}, &block) = .to_json content_tag(:div, data: { controller: "fui-datatable", "fui-datatable-options-value": } ) do content_tag(:table, class: "ui celled striped table", style: "width:100%") do thead = content_tag(:thead) do content_tag(:tr) do safe_join(columns.map { |col| content_tag(:th, col) }) end end tbody = content_tag(:tbody, &block) thead + tbody end end end |
#fui_javascript_tags ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/fui_helper.rb', line 45 def = [] << javascript_include_tag("jquery") FOMANTIC_SCRIPTS.each do |name| << javascript_include_tag(name) end << javascript_include_tag("datatables") safe_join(, "\n") end |