Class: Www::FaqItemComponent

Inherits:
ApplicationComponent show all
Includes:
ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
Defined in:
app/components/www/faq_item_component.rb

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(article_faq:) ⇒ FaqItemComponent

Returns a new instance of FaqItemComponent.



7
8
9
# File 'app/components/www/faq_item_component.rb', line 7

def initialize(article_faq:)
  @article_faq = article_faq
end

Instance Method Details

#plain_text(html) ⇒ Object

Strips HTML tags from a FAQ solution for use in plain-text contexts such as
the clipboard copy button. Uses regex rather than an HTML5 parser — the full
Nokogiri parse is unnecessary overhead for producing readable clipboard text
from the simple HTML that FAQ solutions contain.



15
16
17
18
19
20
21
# File 'app/components/www/faq_item_component.rb', line 15

def plain_text(html)
  html.to_s
      .gsub(/<[^>]*>/, ' ')
      .gsub(/&amp;/, '&').gsub(/&lt;/, '<').gsub(/&gt;/, '>').gsub(/&nbsp;/, ' ')
      .gsub(/\s+/, ' ')
      .strip
end