Class: Kms::SearchItem
- Inherits:
-
Object
- Object
- Kms::SearchItem
- Extended by:
- ActionView::Helpers::TextHelper
- Includes:
- Liquor::Dropable, Liquor::External
- Defined in:
- lib/kms/search_item.rb
Constant Summary collapse
- HIGHLIGHTER =
'<mark class="highlight">\1</mark>'.freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
-
.item_for_searchable(searchable, keywords, attributes_map) ⇒ Object
attributes_map for Kms::Page is: :title, link: :fullpath, content: :content.
Instance Method Summary collapse
-
#initialize(opts) ⇒ SearchItem
constructor
A new instance of SearchItem.
Constructor Details
#initialize(opts) ⇒ SearchItem
Returns a new instance of SearchItem.
11 12 13 14 15 |
# File 'lib/kms/search_item.rb', line 11 def initialize opts @title = opts[:title] @link = opts[:link] @content = opts[:content] end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
7 8 9 |
# File 'lib/kms/search_item.rb', line 7 def content @content end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
7 8 9 |
# File 'lib/kms/search_item.rb', line 7 def link @link end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/kms/search_item.rb', line 7 def title @title end |
Class Method Details
.item_for_searchable(searchable, keywords, attributes_map) ⇒ Object
attributes_map for Kms::Page is: :title, link: :fullpath, content: :content
35 36 37 38 39 40 41 42 43 |
# File 'lib/kms/search_item.rb', line 35 def self.item_for_searchable(searchable, keywords, attributes_map) sanitized_title = ActionController::Base.helpers.sanitize(searchable[attributes_map[:title]]) sanitized_content = ActionController::Base.helpers.sanitize(searchable[attributes_map[:content]]) Kms::SearchItem.new( title: highlight(sanitized_title, keywords, highlighter: HIGHLIGHTER, sanitize: false), link: searchable[attributes_map[:link]], content: highlight(sanitized_content, keywords, highlighter: HIGHLIGHTER, sanitize: false) ) end |