Module: FluxBase::BulmaHelpers

Defined in:
app/helpers/flux_base/bulma_helpers.rb

Instance Method Summary collapse

Instance Method Details

#actions_fieldset(title = '') ⇒ Object

Add controls in the block passed to this method.



6
7
8
9
10
11
12
# File 'app/helpers/flux_base/bulma_helpers.rb', line 6

def actions_fieldset(title = '')
  field_set_tag(title) do
    (:div, class: 'field has-addons') do
      yield
    end
  end.concat(tag(:hr))
end

#create_message(title, options = {}) ⇒ Object

Creates a Bulma message with the given title and options. Use a block to define the message body.



45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/flux_base/bulma_helpers.rb', line 45

def create_message(title, options = {})
  (:article, class: 'message ' + options.delete(:class), **options) do
    header = (:div, title, class: 'message-header')
    body = (:div, class: 'message-body') do
      yield
    end

    header.concat(body)
  end
end

#display_alertObject



22
23
24
25
26
27
28
# File 'app/helpers/flux_base/bulma_helpers.rb', line 22

def display_alert
  return unless alert.present?

  (:div, class: 'notification is-danger') do
    alert
  end
end

#display_errors(record) ⇒ Object

Replaces the auto-generated errors div for record forms.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/flux_base/bulma_helpers.rb', line 31

def display_errors(record)
  return unless record.errors.any?

  title = "#{pluralize(record.errors.count, 'error')} prohibited this #{record.class.name.downcase} from being saved:"
  create_message(title, class: 'is-danger') do
    (:ul) do
      record.errors.full_messages.map do |msg|
        (:li, msg)
      end.inject(&:concat)
    end
  end
end

#display_noticeObject



14
15
16
17
18
19
20
# File 'app/helpers/flux_base/bulma_helpers.rb', line 14

def display_notice
  return unless notice.present?

  (:div, class: 'notification is-info') do
    notice
  end
end