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

Renders a DataTables-powered table via Stimulus controller.

Generates a

with Fomantic-UI styling, wrapped in a
annotated with the fui-datatable Stimulus controller. The block should yield
rows for the .

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)
  options_json = options.to_json

  (:div,
    data: {
      controller: "fui-datatable",
      "fui-datatable-options-value": options_json
    }
  ) do
    (:table, class: "ui celled striped table", style: "width:100%") do
      thead = (:thead) do
        (:tr) do
          safe_join(columns.map { |col| (:th, col) })
        end
      end
      tbody = (: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 fui_javascript_tags
  tags = []
  tags << javascript_include_tag("jquery")
  FOMANTIC_SCRIPTS.each do |name|
    tags << javascript_include_tag(name)
  end
  tags << javascript_include_tag("datatables")
  safe_join(tags, "\n")
end