Class: Blacklight::HiddenSearchStateComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/blacklight/hidden_search_state_component.rb

Overview

Writes out zero or more <input type=“hidden”> elements, completely representing a hash passed in using Rails-style request parameters for hashes nested with arrays and other hashes.

Constant Summary

Constants inherited from Component

Component::EXCLUDE_VARIABLES

Instance Method Summary collapse

Methods inherited from Component

compiler, config, #inspect

Constructor Details

#initialize(params:) ⇒ HiddenSearchStateComponent

Returns a new instance of HiddenSearchStateComponent.

Parameters:

  • params (Hash)


9
10
11
# File 'app/components/blacklight/hidden_search_state_component.rb', line 9

def initialize(params:)
  @params = params.except(:page, :utf8)
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
# File 'app/components/blacklight/hidden_search_state_component.rb', line 13

def call
  hidden_fields = []
  flatten_hash(@params).each do |name, value|
    value = Array.wrap(value)
    value.each do |v|
      hidden_fields << hidden_field_tag(name, v.to_s, id: nil)
    end
  end

  safe_join(hidden_fields, "\n")
end