Class: DocsUI::SearchResults
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- DocsUI::SearchResults
- Defined in:
- app/components/docs_ui/search_results.rb
Overview
The server-rendered search results — the JS-off path. A plain page body (the host renders it inside DocsUI::Shell) that echoes the query, lists the hits grouped by page, and links each result to its section anchor. With JavaScript off this IS the search UX; the docs-nav palette is a progressive enhancement over the same DocsKit::SearchController that renders this.
render DocsUI::SearchResults.new(query: params[:q], hits: index.search(params[:q]))
hits are DocsKit::SearchHit value objects (already ranked, snippet pre-marked and HTML-safe). A blank query prompts the reader; a query with no hits renders guidance instead of an empty list.
Instance Method Summary collapse
-
#initialize(query:, hits:) ⇒ SearchResults
constructor
A new instance of SearchResults.
- #view_template ⇒ Object
Constructor Details
#initialize(query:, hits:) ⇒ SearchResults
Returns a new instance of SearchResults.
16 17 18 19 |
# File 'app/components/docs_ui/search_results.rb', line 16 def initialize(query:, hits:) @query = query.to_s @hits = hits end |
Instance Method Details
#view_template ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/components/docs_ui/search_results.rb', line 21 def view_template div(class: "mx-auto max-w-3xl") do header if @query.strip.empty? prompt elsif @hits.empty? empty_state else results end end end |