Module: Testimonials::WidgetHelper

Defined in:
app/helpers/testimonials/widget_helper.rb

Overview

Included into the host's ActionView. Drop <%= testimonials_tag %> before in your layout; it renders nothing unless reviews are enabled for the request. The widget stays invisible until opened — by a testimonial_prompt! from a controller (throttled), by any element with a data-testimonial-prompt attribute, or by window.Testimonials.open().

testimonials_button renders a ready-made opener with a localized label ("Leave a review", or "Update your review" once the user has one), so hosts get a user-facing entry point without any i18n setup.

Instance Method Summary collapse

Instance Method Details

#testimonials_button(label: nil) ⇒ Object

A plain, unstyled



30
31
32
33
34
# File 'app/helpers/testimonials/widget_helper.rb', line 30

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

The localized call-to-action on its own — "Leave a review", or "Update your review" once the user has one — for hosts composing their own opener markup (icons, list items) around a data-testimonial-prompt element.



39
40
41
42
43
44
45
# File 'app/helpers/testimonials/widget_helper.rb', line 39

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



14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/testimonials/widget_helper.rb', line 14

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