Class: Kms::SearchItem

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/kms/search_item.rb', line 7

def content
  @content
end

Returns the value of attribute link.



7
8
9
# File 'lib/kms/search_item.rb', line 7

def link
  @link
end

#titleObject (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