Module: Testimonials::WidgetHelper

Defined in:
lib/testimonials/widget_helper.rb

Overview

Included into the host's ActionView. This lives under lib and is required before the engine registers its Action View load hook: a host initializer may load Action View before Rails sets up application autoloaders, when an app/helpers constant cannot be resolved yet.

Instance Method Summary collapse

Instance Method Details

#testimonials_button(label: nil) ⇒ Object



21
22
23
24
25
# File 'lib/testimonials/widget_helper.rb', line 21

def testimonials_button(label: nil, **)
  return unless Testimonials.enabled?(request)

  tag.button(label || testimonials_cta_label, type: 'button', 'data-testimonial-prompt': '', **)
end

#testimonials_cta_labelObject



27
28
29
30
31
32
33
# File 'lib/testimonials/widget_helper.rb', line 27

def testimonials_cta_label
  if testimonials_existing_testimonial
    I18n.t(:update_title, scope: :testimonials, default: 'Update your review')
  else
    I18n.t(:cta, scope: :testimonials, default: 'Leave a review')
  end
end

#testimonials_tagObject



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

def testimonials_tag
  return unless Testimonials.enabled?(request)

  Widget.snippet(
    locale: I18n.locale,
    authenticated: testimonials_author.present?,
    auto_open: testimonials_auto_open,
    existing: testimonials_existing_testimonial,
    nonce: (content_security_policy_nonce if respond_to?(:content_security_policy_nonce))
  ).html_safe
end