Sha256: 629705aa6df6a1f7a1d280f36e87753bc677c4575bbc014e8989054d2119a8c9

Contents?: true

Size: 1.04 KB

Versions: 26

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Blacklight
  module Response
    # Render spellcheck results for a search query
    class SpellcheckComponent < ViewComponent::Base
      # @param [Blacklight::Response] response
      # @param [Array<String>] options explicit spellcheck options to render
      def initialize(response:, options: nil)
        @response = response
        @options = options
        @options ||= options_from_response(@response)
      end

      def link_to_query(query)
        Deprecation.silence(Blacklight::UrlHelperBehavior) do
          helpers.link_to_query(query)
        end
      end

      def render?
        Deprecation.silence(Blacklight::BlacklightHelperBehavior) do
          @options&.any? && helpers.should_show_spellcheck_suggestions?(@response)
        end
      end

      private

      def options_from_response(response)
        if response&.spelling&.collation
          [response.spelling.collation]
        elsif response&.spelling&.words
          response.spelling.words
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
blacklight-7.38.0 app/components/blacklight/response/spellcheck_component.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/app/components/blacklight/response/spellcheck_component.rb
blacklight-7.37.0 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.36.2 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.36.1 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.36.0 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.35.0 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.34.0 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.33.1 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.33.0 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.32.0 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.31.0 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.30.0 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.29.0 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.28.0 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.27.1 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.27.0 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.26.1 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.26.0 app/components/blacklight/response/spellcheck_component.rb
blacklight-7.25.3 app/components/blacklight/response/spellcheck_component.rb