Class: Www::ReviewsIo::ReviewSliderComponent

Inherits:
ApplicationComponent show all
Includes:
Concerns::ReviewsIoSupport
Defined in:
app/components/www/reviews_io/review_slider_component.rb

Overview

Unified review track component — renders a Fancyapps carousel of review cards.
Used on the homepage (dots, autoplay, founder card) and every landing page
(arrows, product-line sourced reviews, section header with stats).

Data sources (at least one required):
product_line: 'floor-heating' — resolves SKUs via ltree
skus: ['SKU-001', 'SKU-002'] — explicit list
tags: ['for-homepage'] — JSONB tag filter
(sources are OR-combined when multiple are given)

Navigation variants:
navigation: :arrows — prev/next buttons (default, good for landing pages)
navigation: :dots — pagination dots + autoplay (good for homepage)

Lead card — the first slide, shown by default on every page:
lead_review: :founder — Julia Billen's founder quote card (DEFAULT)
lead_review: false — no lead card, customer reviews only
lead_review: 12345 — pin ReviewsIo#12345 as the first card

Examples:

Landing page — founder card shown by default

<%= render Www::ReviewsIo::ReviewSliderComponent.new(
product_line: 'floor-heating',
see_all_url: cms_link('/floor-heating/reviews')
) %>

Homepage

<%= render Www::ReviewsIo::ReviewSliderComponent.new(
tags: ['for-homepage'],
per_page: 3,
navigation: :dots,
autoplay: true,
show_header: false
) %>

Opt out of the lead card

<%= render Www::ReviewsIo::ReviewSliderComponent.new(
product_line: 'snow-melting',
lead_review: false
) %>

Constant Summary collapse

DEFAULT_REVIEWS_COUNT =

Default reviews count.

8
AVATAR_PALETTE =

Avatar colour palette.

%w[#c0392b #2e7d32 #1565c0 #6a1e5e #00695c #e65100].freeze
FOUNDER_LEAD =

Sentinel +lead_review+ value selecting the founder quote card.

:founder
FOUNDER =

Founder lead card content. Shown as the first slide unless +lead_review+
overrides it. The portrait uses the env-configurable top-level
FOUNDER_IMAGE_ID constant (see config/initializers/reviews_io.rb).

{
  name:  'Julia Billen',
  title: 'Owner & President, WarmlyYours',
  quote: "I picked the name ‘WarmlyYours’ because I really felt that it embodied " \
         "how we wanted to treat our customers and how we wanted them to see us – as a partner.",
  link:  '/company'
}.freeze

Instance Method Summary collapse

Methods inherited from ApplicationComponent

#cms_link, #fetch_or_fallback, #image_asset_tag, #image_tag, #number_to_currency, #number_with_delimiter, #post_path, #post_url, #strip_tags

Constructor Details

#initialize(tags: nil, product_line: nil, skus: nil, reviews_count: DEFAULT_REVIEWS_COUNT, see_all_url: nil, section_title: 'Customer Reviews', cta_label: 'View All Reviews', min_rating: nil, show_header: true, show_stats: false, border: nil, per_page: 3, navigation: :arrows, autoplay: false, sort: :date, storewide: false, lead_review: FOUNDER_LEAD) ⇒ ReviewSliderComponent

Returns a new instance of ReviewSliderComponent.

Parameters:

  • tags (Array<String>) (defaults to: nil)

    Primary source — JSONB tag filter (e.g. ['for-homepage'])

  • product_line (String) (defaults to: nil)

    Fallback source — fills remaining slots when tags yield fewer
    than reviews_count results. Also works as a standalone source.

  • skus (Array<String>) (defaults to: nil)

    Alternative explicit SKU list (used instead of product_line)

  • reviews_count (Integer) (defaults to: DEFAULT_REVIEWS_COUNT)

    Target number of reviews to display (default 8)

  • min_rating (Integer, nil) (defaults to: nil)

    Minimum star rating filter

  • per_page (Integer) (defaults to: 3)

    Slides visible at once (default 3)

  • navigation (Symbol) (defaults to: :arrows)

    :arrows or :dots

  • autoplay (Boolean) (defaults to: false)

    Auto-advance slides

  • show_header (Boolean) (defaults to: true)

    Section title + intro text

  • show_stats (Boolean) (defaults to: false)

    Aggregate rating/count line in header

  • section_title (String) (defaults to: 'Customer Reviews')
  • see_all_url (String, nil) (defaults to: nil)

    CTA link below carousel

  • cta_label (String) (defaults to: 'View All Reviews')
  • border (Symbol, nil) (defaults to: nil)

    :top :bottom :both

  • sort (Symbol) (defaults to: :date)

    :date (default) or :rating (highest first)

  • storewide (Boolean) (defaults to: false)

    When true, show aggregate stats for all visible reviews and
    fetch a mixed high-rated carousel (replaces legacy
    StoreAndProductsSliderComponent). Ignores tags/product_line/skus.

  • lead_review (Symbol, Integer, String, ReviewsIo, false) (defaults to: FOUNDER_LEAD)

    First slide:
    :founder (default) renders the founder quote card; false renders no lead
    card; an id/record pins that review as the first card.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/components/www/reviews_io/review_slider_component.rb', line 89

def initialize(
  tags: nil,
  product_line: nil,
  skus: nil,
  reviews_count: DEFAULT_REVIEWS_COUNT,
  see_all_url: nil,
  section_title: 'Customer Reviews',
  cta_label: 'View All Reviews',
  min_rating: nil,
  show_header: true,
  show_stats: false,
  border: nil,
  per_page: 3,
  navigation: :arrows,
  autoplay: false,
  sort: :date,
  storewide: false,
  lead_review: FOUNDER_LEAD
)
  @skus             = skus
  @product_line     = product_line
  @tags             = Array(tags).compact_blank.presence
  @reviews_count    = reviews_count
  @see_all_url      = see_all_url
  @section_title    = section_title
  @cta_label        = cta_label
  @min_rating       = min_rating
  @show_header      = show_header
  @show_stats       = show_stats
  @border           = border
  @per_page         = per_page
  @navigation       = navigation
  @autoplay         = autoplay
  @sort             = sort
  @storewide        = storewide
  @lead_review      = lead_review
  super()
end

Instance Method Details

#render?Boolean

Whether the carousel has anything to show — at least one review or the
founder lead card.

Returns:

  • (Boolean)


132
133
134
# File 'app/components/www/reviews_io/review_slider_component.rb', line 132

def render?
  reviews.any? || founder_card?
end