Module: Livechat::WidgetHelper

Defined in:
lib/livechat/widget_helper.rb

Overview

Included into the host's ActionView. Kept under lib and required before the engine registers its Action View load hook: a host initializer may load Action View before Rails sets up application autoloaders, when a helper living only under app/helpers is not yet a resolvable constant.

Instance Method Summary collapse

Instance Method Details

#livechat_button(label = nil, message: nil, **options) ⇒ Object

A plain, unstyled



23
24
25
26
27
28
29
30
31
32
# File 'lib/livechat/widget_helper.rb', line 23

def livechat_button(label = nil, message: nil, **options)
  return unless Livechat.enabled?(request)

  label ||= options.delete(:label)
  label ||= I18n.t(:launcher, scope: :livechat, default: 'Chat with us')
  data = (options.delete(:data) { {} } || {}).merge(livechat_open: '')
  data[:livechat_message] = message if message.present?

  tag.button(label, type: 'button', data:, **options)
end

#livechat_tagObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/livechat/widget_helper.rb', line 9

def livechat_tag
  return unless Livechat.enabled?(request)

  Widget.snippet(
    locale: I18n.locale,
    authenticated: livechat_visitor.present?,
    avatar_url: livechat_avatar_url,
    nonce: (content_security_policy_nonce if respond_to?(:content_security_policy_nonce))
  ).html_safe
end