Class: Blacklight::DocumentComponent
- Defined in:
 - app/components/blacklight/document_component.rb
 
Overview
    Note:
    
  
when subclassing this component, if you override the initializer, you must explicitly specify the counter variable ‘document_counter` even if you don’t use it. Otherwise view_component will not provide the count value when calling the component.
A component for rendering a single document
Constant Summary collapse
- COLLECTION_INDEX_OFFSET =
          
ViewComponent 3 changes iteration counters to begin at 0 rather than 1
 ViewComponent::VERSION::MAJOR < 3 ? 0 : 1
Instance Method Summary collapse
- #before_render ⇒ Object
 - 
  
    
      #classes  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
HTML classes to apply to the root element.
 - 
  
    
      #initialize(document: nil, presenter: nil, partials: nil, id: nil, classes: [], component: :article, title_component: nil, counter: nil, document_counter: nil, counter_offset: 0, show: false, **args)  ⇒ DocumentComponent 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
rubocop:disable Metrics/ParameterLists.
 
Methods inherited from Component
reset_compiler!, sidecar_files, upstream_sidecar_files
Constructor Details
#initialize(document: nil, presenter: nil, partials: nil, id: nil, classes: [], component: :article, title_component: nil, counter: nil, document_counter: nil, counter_offset: 0, show: false, **args) ⇒ DocumentComponent
rubocop:disable Metrics/ParameterLists
      94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116  | 
    
      # File 'app/components/blacklight/document_component.rb', line 94 def initialize(document: nil, presenter: nil, partials: nil, id: nil, classes: [], component: :article, title_component: nil, counter: nil, document_counter: nil, counter_offset: 0, show: false, **args) Blacklight.deprecation.warn('the `presenter` argument to DocumentComponent#initialize is deprecated; pass the `presenter` in as document instead') if presenter # .collection_parameter only works in view_component3, and functionality removed in BL9 @presenter = presenter || document || (self.class.respond_to?(:collection_parameter) && args[self.class.collection_parameter]) @document = @presenter.document @view_partials = partials || [] @component = component @title_component = title_component @id = id || ('document' if show) @classes = classes @counter = counter # .collection_parameter only works in view_component3, and functionality removed in BL9 @document_counter = document_counter || (self.class.respond_to?(:collection_counter_parameter) && args.fetch(self.class.collection_counter_parameter, nil)) @counter ||= @document_counter + COLLECTION_INDEX_OFFSET + counter_offset if @document_counter.present? @show = show end  | 
  
Instance Method Details
#before_render ⇒ Object
      129 130 131 132 133 134 135 136 137 138 139 140  | 
    
      # File 'app/components/blacklight/document_component.rb', line 129 def before_render with_title unless title with_thumbnail unless thumbnail || show? (fields: presenter.field_presenters, show: @show) unless unless view_partials.each do |view_partial| with_partial(view_partial) do helpers.render_document_partial @document, view_partial, component: self, document_counter: @counter end end end  | 
  
#classes ⇒ Object
HTML classes to apply to the root element
      120 121 122 123 124 125 126 127  | 
    
      # File 'app/components/blacklight/document_component.rb', line 120 def classes [ @classes, helpers.render_document_class(@document), 'document', ("document-position-#{@counter}" if @counter) ].compact.flatten end  |