Module: Tramway::Helpers::ViewsHelper

Includes:
ComponentHelper
Included in:
ApplicationHelper, BaseComponent, BaseDecorator
Defined in:
lib/tramway/helpers/views_helper.rb

Overview

Provides view-oriented helpers for ActionView

Constant Summary collapse

FORM_SIZES =
%i[small medium large].freeze

Instance Method Summary collapse

Methods included from ComponentHelper

#component

Instance Method Details

#tramway_back_buttonObject



52
53
54
# File 'lib/tramway/helpers/views_helper.rb', line 52

def tramway_back_button
  component 'tramway/back_button'
end

#tramway_badge(text:, type: nil, color: nil) ⇒ Object



68
69
70
71
72
73
# File 'lib/tramway/helpers/views_helper.rb', line 68

def tramway_badge(text:, type: nil, color: nil)
  component 'tramway/badge',
            text:,
            type:,
            color:
end

#tramway_button(path: nil, text: nil, method: :get, form_options: {}, **options) ⇒ Object



46
47
48
49
50
# File 'lib/tramway/helpers/views_helper.rb', line 46

def tramway_button(path: nil, text: nil, method: :get, form_options: {}, **options, &)
  component 'tramway/button', text:, path:, method:, form_options:, color: options.delete(:color),
                              type: options.delete(:type), size: options.delete(:size),
                              tag: options.delete(:tag), options:, &
end

#tramway_cellObject



42
43
44
# File 'lib/tramway/helpers/views_helper.rb', line 42

def tramway_cell(&)
  component 'tramway/table/cell', &
end

#tramway_chat(chat_id:, messages:, message_form:, send_message_path:) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/tramway/helpers/views_helper.rb', line 83

def tramway_chat(chat_id:, messages:, message_form:, send_message_path:, **)
  unless messages.all? { _1[:id].present? && _1[:type].present? }
    raise ArgumentError, 'Each message must have :id and :type keys'
  end

  if messages.any? { !_1[:type].to_sym.in?(%i[sent received]) }
    raise ArgumentError, 'Message :type must be either :sent or :received'
  end

  component 'tramway/chat', chat_id:, messages:, message_form:, send_message_path:, **
end

#tramway_container(id: nil, **options) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/tramway/helpers/views_helper.rb', line 56

def tramway_container(id: nil, **options, &)
  if id.present?
    component 'tramway/containers/narrow', id:, options:, &
  else
    component 'tramway/containers/narrow', options:, &
  end
end

#tramway_flash(text:, type:, **options) ⇒ Object



79
80
81
# File 'lib/tramway/helpers/views_helper.rb', line 79

def tramway_flash(text:, type:, **options)
  component 'tramway/flash', text:, type:, options:
end

#tramway_form_for(object, size: :medium, **options) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/tramway/helpers/views_helper.rb', line 11

def tramway_form_for(object, *, size: :medium, **options, &)
  form_object_class = object.is_a?(Tramway::BaseForm) ? object.class : nil

  form_for(object, *, **options.merge(
    builder: Tramway::Form::Builder,
    size: normalize_form_size(size),
    form_object_class:,
    remote_submit: options[:remote] || false
  ), &)
end

#tramway_header(headers: nil, columns: nil) ⇒ Object



26
27
28
29
30
31
# File 'lib/tramway/helpers/views_helper.rb', line 26

def tramway_header(headers: nil, columns: nil, &)
  component 'tramway/table/header',
            headers:,
            columns:,
            &
end

#tramway_main_container(**options) ⇒ Object



64
65
66
# File 'lib/tramway/helpers/views_helper.rb', line 64

def tramway_main_container(**options, &)
  component 'tramway/containers/main', options:, &
end

#tramway_row(**options) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/tramway/helpers/views_helper.rb', line 33

def tramway_row(**options, &)
  component 'tramway/table/row',
            cells: options.delete(:cells),
            href: options.delete(:href),
            preview: options.delete(:preview),
            options:,
            &
end

#tramway_table(**options) ⇒ Object



22
23
24
# File 'lib/tramway/helpers/views_helper.rb', line 22

def tramway_table(**options, &)
  component 'tramway/table', options:, &
end

#tramway_title(text: nil, **options) ⇒ Object



75
76
77
# File 'lib/tramway/helpers/views_helper.rb', line 75

def tramway_title(text: nil, **options, &)
  component 'tramway/title', text:, options:, &
end