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

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)
  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_tagsObject



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