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 ⇒ 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) ⇒ Object
- #tramway_main_container(**options) ⇒ Object
- #tramway_row(**options) ⇒ Object
- #tramway_table(**options) ⇒ Object
- #tramway_title(text: nil, **options) ⇒ Object
Methods included from ComponentHelper
Instance Method Details
#tramway_back_button ⇒ Object
52 53 54 |
# File 'lib/tramway/helpers/views_helper.rb', line 52 def 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 (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), options:, & end |
#tramway_cell ⇒ Object
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 .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
56 57 58 59 60 61 62 |
# File 'lib/tramway/helpers/views_helper.rb', line 56 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
79 80 81 |
# File 'lib/tramway/helpers/views_helper.rb', line 79 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) ⇒ 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(**, &) 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(**, &) 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
75 76 77 |
# File 'lib/tramway/helpers/views_helper.rb', line 75 def tramway_title(text: nil, **, &) component 'tramway/title', text:, options:, & end |