Class: Marsdawn::Site::SearchPage

Inherits:
Page
  • Object
show all
Defined in:
lib/marsdawn/site/search_page.rb

Instance Attribute Summary

Attributes inherited from Page

#level, #site, #sysinfo, #title, #type, #uri

Instance Method Summary collapse

Methods inherited from Page

#breadcrumb, #link, #neighbor, #page_nav, #parent, #search_box, #to_html, #to_page_html, #to_s, #top, #under

Constructor Details

#initialize(doc_info, site, search_word, search_results) ⇒ SearchPage

Returns a new instance of SearchPage.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/marsdawn/site/search_page.rb', line 6

def initialize doc_info, site, search_word, search_results
  @word = search_word
  @results = search_results
  exvars = {title: 'Search Results'}
  sysinfo = {
    uri: site.search_path,
    breadcrumb: [],
    prev_page: nil,
    next_page: nil
  }
  page = {
    content: content,
    exvars: exvars,
    sysinfo: sysinfo
  }
  super doc_info, page, site
  @search_word = search_word
end

Instance Method Details

#contentObject



25
26
27
28
29
30
31
32
# File 'lib/marsdawn/site/search_page.rb', line 25

def content
  ret = %!<h1>Search Results for '#{Marsdawn::Util.html_escape(@word)}'</h1>!
  @content ||= @results.each_with_object ret do |res, ret|
    ret << %!<h4><a href=".#{res[:uri]}">#{res[:title]}</a></h4>!
    blocks = res[:results].join(' ... ')
    ret << %!<div class="search-result">#{blocks}</div>!
  end
end