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



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

def tramway_back_button
  component 'tramway/back_button'
end

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



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

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



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

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), tooltip: options.delete(:tooltip), options:, &
end

#tramway_cell(**options) ⇒ Object



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

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

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



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/tramway/helpers/views_helper.rb', line 88

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



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

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



84
85
86
# File 'lib/tramway/helpers/views_helper.rb', line 84

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, **options) ⇒ Object



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

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

#tramway_main_container(**options) ⇒ Object



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

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

#tramway_row(**options) ⇒ Object



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

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



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

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

#tramway_tooltip(text:, event: :hover, **options) ⇒ Object



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

def tramway_tooltip(text:, event: :hover, **options, &)
  component 'tramway/tooltip', text:, event:, options:, &
end