Module: TurboChat::ApplicationHelper::MessageRendering
- Included in:
- TurboChat::ApplicationHelper
- Defined in:
- app/helpers/turbo_chat/application_helper/message_rendering.rb
Instance Method Summary collapse
- #chat_mentions_container_inline_style(chat: nil) ⇒ Object
- #chat_message_css_classes(chat_message:, own_message:) ⇒ Object
- #chat_message_inline_style(chat_message:, own_message:) ⇒ Object
- #chat_message_mention_tokens(chat_message) ⇒ Object
- #render_chat_message_body(chat_message) ⇒ Object
Instance Method Details
#chat_mentions_container_inline_style(chat: nil) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/helpers/turbo_chat/application_helper/message_rendering.rb', line 19 def chat_mentions_container_inline_style(chat: nil) hex_color = normalize_hex_color(chat_config_value(:mention_mark_hex_color, chat: chat)) || normalize_hex_color(chat_config_value(:mention_highlight_hex_color, chat: chat)) return nil if hex_color.blank? mention_mark_background = hex_color_with_alpha(hex_color, alpha: 0.22) "--chat-mention-highlight-color: #{hex_color}; --chat-mention-mark-background: #{mention_mark_background};" end |
#chat_message_css_classes(chat_message:, own_message:) ⇒ Object
4 5 6 7 8 9 10 |
# File 'app/helpers/turbo_chat/application_helper/message_rendering.rb', line 4 def (chat_message:, own_message:) [ "chat-bubble", ( ? "chat-bubble--own" : nil), *(chat_message: , own_message: ) ].compact.uniq.join(" ") end |
#chat_message_inline_style(chat_message:, own_message:) ⇒ Object
12 13 14 15 16 17 |
# File 'app/helpers/turbo_chat/application_helper/message_rendering.rb', line 12 def (chat_message:, own_message:) hex_color = (chat_message: , own_message: ) return nil if hex_color.blank? "--chat-bubble-bg: #{hex_color}; --chat-bubble-border: #{hex_color};" end |
#chat_message_mention_tokens(chat_message) ⇒ Object
45 46 47 48 49 50 |
# File 'app/helpers/turbo_chat/application_helper/message_rendering.rb', line 45 def () chat = .respond_to?(:chat) ? .chat : nil return [] unless chat_enable_mentions?(chat: chat) && .present? .body.to_s.scan(MENTION_PATTERN).uniq end |
#render_chat_message_body(chat_message) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/turbo_chat/application_helper/message_rendering.rb', line 28 def () chat = .respond_to?(:chat) ? .chat : nil body = .body.to_s # html_safe is safe here: decorate_plain_message_text guarantees the body # is html_escaped before any markup injection (see method comment above). unless (chat: chat) return content_tag(:p, (body, chat: chat).html_safe, class: "chat-body") end sanitized_html = sanitize( body, tags: Array(chat_config_value(:message_html_tags, default: [], chat: chat)), attributes: Array(chat_config_value(:message_html_attributes, default: [], chat: chat)) ) content_tag(:div, sanitized_html, class: "chat-body") end |