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
- #tramway_back_button ⇒ Object
- #tramway_badge(text:, type: nil, color: nil) ⇒ Object
- #tramway_button(path: nil, text: nil, method: :get, form_options: {}, **options) ⇒ Object
- #tramway_cell(**options) ⇒ Object
- #tramway_chat(chat_id:, messages:, message_form:, send_message_path:) ⇒ Object
- #tramway_container(id: nil, **options) ⇒ Object
- #tramway_flash(text:, type:, **options) ⇒ Object
- #tramway_form_for(object, size: :medium, **options) ⇒ Object
- #tramway_header(headers: nil, columns: nil, **options) ⇒ Object
- #tramway_main_container(**options) ⇒ Object
- #tramway_row(**options) ⇒ Object
- #tramway_table(**options) ⇒ Object
- #tramway_title(text: nil, **options) ⇒ Object
- #tramway_tooltip(text:, event: :hover, **options) ⇒ Object
Methods included from ComponentHelper
Instance Method Details
#tramway_back_button ⇒ Object
53 54 55 |
# File 'lib/tramway/helpers/views_helper.rb', line 53 def 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 (path: nil, text: nil, method: :get, form_options: {}, **, &) component 'tramway/button', text:, path:, method:, form_options:, color: .delete(:color), type: .delete(:type), size: .delete(:size), tag: .delete(:tag), tooltip: .delete(:tooltip), options:, & end |
#tramway_cell(**options) ⇒ Object
43 44 45 |
# File 'lib/tramway/helpers/views_helper.rb', line 43 def tramway_cell(**, &) 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 .all? { _1[:id].present? && _1[:type].present? } raise ArgumentError, 'Each message must have :id and :type keys' end if .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, **, &) 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:, **) 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, **, &) form_object_class = object.is_a?(Tramway::BaseForm) ? object.class : nil form_for(object, *, **.merge( builder: Tramway::Form::Builder, size: normalize_form_size(size), form_object_class:, remote_submit: [: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, **, &) 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(**, &) 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(**, &) component 'tramway/table/row', cells: .delete(:cells), href: .delete(:href), preview: .delete(:preview), options:, & end |
#tramway_table(**options) ⇒ Object
22 23 24 |
# File 'lib/tramway/helpers/views_helper.rb', line 22 def tramway_table(**, &) 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, **, &) 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, **, &) component 'tramway/tooltip', text:, event:, options:, & end |