Module: Crm::ReviewsIoHelper
- Defined in:
- app/helpers/crm/reviews_io_helper.rb
Overview
View helpers for the CRM Reviews.io dashboard: rating badge styling,
safe external links, and review headline extraction.
Instance Method Summary collapse
-
#auto_extracted_headline(comments) ⇒ String
First sentence or first 12 words from stripped review HTML — matches review card display logic.
-
#rating_badge_class(rating) ⇒ String
Returns the appropriate Bootstrap badge class for a review rating.
-
#safe_external_url(url) ⇒ String
Validates an external URL and returns it only if it uses http/https.
Instance Method Details
#auto_extracted_headline(comments) ⇒ String
First sentence or first 12 words from stripped review HTML — matches review card display logic.
37 38 39 40 41 |
# File 'app/helpers/crm/reviews_io_helper.rb', line 37 def auto_extracted_headline(comments) body = ActionController::Base.helpers.(comments.to_s) match = body.match(/\A(.+?[.!?])(?:\s|$)/) match ? match[1] : body.split.first(12).join(' ') end |
#rating_badge_class(rating) ⇒ String
Returns the appropriate Bootstrap badge class for a review rating
10 11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/crm/reviews_io_helper.rb', line 10 def () case .to_i when 5 then 'bg-success' when 4 then 'bg-primary' when 3 then 'bg-warning text-dark' when 2 then 'bg-orange' when 1 then 'bg-danger' else 'bg-secondary' end end |
#safe_external_url(url) ⇒ String
Validates an external URL and returns it only if it uses http/https.
Returns '#' for invalid or non-http(s) URLs to prevent injection.
25 26 27 28 29 30 31 32 |
# File 'app/helpers/crm/reviews_io_helper.rb', line 25 def safe_external_url(url) return '#' if url.blank? uri = URI.parse(url) %w[http https].include?(uri.scheme) && uri.host.present? ? url : '#' rescue URI::InvalidURIError '#' end |