Class: Www::FaqItemComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Www::FaqItemComponent
- Includes:
- ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
- Defined in:
- app/components/www/faq_item_component.rb
Instance Method Summary collapse
-
#initialize(article_faq:) ⇒ FaqItemComponent
constructor
A new instance of FaqItemComponent.
-
#plain_text(html) ⇒ Object
Strips HTML tags from a FAQ solution for use in plain-text contexts such as the clipboard copy button.
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(/&/, '&').gsub(/</, '<').gsub(/>/, '>').gsub(/ /, ' ') .gsub(/\s+/, ' ') .strip end |