Skip to content

Commit

Permalink
Extract a base component for blacklight
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Mar 25, 2022
1 parent 64ec202 commit 60cb79b
Show file tree
Hide file tree
Showing 33 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/components/blacklight/constraint_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class ConstraintComponent < ::ViewComponent::Base
class ConstraintComponent < Blacklight::Component
with_collection_parameter :facet_item_presenter

def initialize(facet_item_presenter:, classes: 'filter', layout: Blacklight::ConstraintLayoutComponent)
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/constraint_layout_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class ConstraintLayoutComponent < ::ViewComponent::Base
class ConstraintLayoutComponent < Blacklight::Component
def initialize(value:, label: nil, remove_path: nil, classes: nil, search_state: nil)
@value = value
@label = label
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/constraints_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class ConstraintsComponent < ::ViewComponent::Base
class ConstraintsComponent < Blacklight::Component
renders_many :query_constraints_area
renders_many :facet_constraints_area
renders_many :additional_constraints
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/document/action_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
module Document
# Render a bookmark widget to bookmark / unbookmark a document
class ActionComponent < ::ViewComponent::Base
class ActionComponent < Blacklight::Component
with_collection_parameter :action

# @param [Blacklight::Document] document
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/document/actions_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
module Document
# Render a bookmark widget to bookmark / unbookmark a document
class ActionsComponent < ::ViewComponent::Base
class ActionsComponent < Blacklight::Component
renders_many :actions, (lambda do |action:, component: nil, **kwargs|
component ||= action.component || Blacklight::Document::ActionComponent
component.new(action: action, document: @document, options: @options, url_opts: @url_opts, link_classes: @link_classes, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/document/bookmark_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
module Document
# Render a bookmark widget to bookmark / unbookmark a document
class BookmarkComponent < ::ViewComponent::Base
class BookmarkComponent < Blacklight::Component
# @param [Blacklight::Document] document
# @param [Boolean] checked
# @param [Object] bookmark_path the rails route to use for bookmarks
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/document/citation_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
module Document
# Render citations for the document
class CitationComponent < ::ViewComponent::Base
class CitationComponent < Blacklight::Component
DEFAULT_FORMATS = {
'blacklight.citation.mla': :export_as_mla_citation_txt,
'blacklight.citation.apa': :export_as_apa_citation_txt,
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/document/group_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
module Document
# Render the 'more like this' results from the response
class GroupComponent < ::ViewComponent::Base
class GroupComponent < Blacklight::Component
with_collection_parameter :group

# @param [Blacklight::Solr::Response::Group] group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
module Document
# Render the 'more like this' results from the response
class MoreLikeThisComponent < ::ViewComponent::Base
class MoreLikeThisComponent < Blacklight::Component
with_collection_parameter :document

# @param [Blacklight::Document] document
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/document/thumbnail_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
module Document
# Render the thumbnail for the document
class ThumbnailComponent < ::ViewComponent::Base
class ThumbnailComponent < Blacklight::Component
with_collection_parameter :presenter

# @param [Blacklight::DocumentPresenter] presenter
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/document_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class DocumentComponent < ::ViewComponent::Base
class DocumentComponent < Blacklight::Component
# Content appearing before the document
renders_one :header

Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/document_metadata_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class DocumentMetadataComponent < ::ViewComponent::Base
class DocumentMetadataComponent < Blacklight::Component
renders_many :fields, (lambda do |component: nil, **kwargs|
component.new(**kwargs)
end)
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/document_title_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class DocumentTitleComponent < ::ViewComponent::Base
class DocumentTitleComponent < Blacklight::Component
renders_many :before_title
renders_many :after_title
renders_many :actions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class FacetFieldCheckboxesComponent < ::ViewComponent::Base
class FacetFieldCheckboxesComponent < Blacklight::Component
def initialize(facet_field:, layout: nil)
@facet_field = facet_field
@layout = layout == false ? FacetFieldNoLayoutComponent : Blacklight::FacetFieldComponent
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/facet_field_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class FacetFieldComponent < ::ViewComponent::Base
class FacetFieldComponent < Blacklight::Component
renders_one :label
renders_one :body

Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/facet_field_filter_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class FacetFieldFilterComponent < ::ViewComponent::Base
class FacetFieldFilterComponent < Blacklight::Component
def initialize(facet_field:)
@facet_field = facet_field
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class FacetFieldInclusiveConstraintComponent < ::ViewComponent::Base
class FacetFieldInclusiveConstraintComponent < Blacklight::Component
with_collection_parameter :facet_field

def initialize(facet_field:, values: nil)
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/facet_field_list_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class FacetFieldListComponent < ::ViewComponent::Base
class FacetFieldListComponent < Blacklight::Component
extend Deprecation
self.deprecation_horizon = 'blacklight 9.0'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class FacetFieldNoLayoutComponent < ::ViewComponent::Base
class FacetFieldNoLayoutComponent < Blacklight::Component
renders_one :label
renders_one :body

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class FacetFieldPaginationComponent < ::ViewComponent::Base
class FacetFieldPaginationComponent < Blacklight::Component
def initialize(facet_field:)
@facet_field = facet_field
end
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/facet_item_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class FacetItemComponent < ::ViewComponent::Base
class FacetItemComponent < Blacklight::Component
with_collection_parameter :facet_item

def initialize(facet_item:, wrapping_element: 'li', suppress_link: false)
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/facet_item_pivot_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Blacklight
# Render facet items and any subtree
class FacetItemPivotComponent < ::ViewComponent::Base
class FacetItemPivotComponent < Blacklight::Component
# Somewhat arbitrary number; the only important thing is that
# it is bigger than the number of leaf nodes in any collapsing
# pivot facet on the page.
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/hidden_search_state_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Blacklight
# 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.
class HiddenSearchStateComponent < ::ViewComponent::Base
class HiddenSearchStateComponent < Blacklight::Component
# @param [Hash] params
def initialize(params:)
@params = params.except(:page, :utf8)
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/metadata_field_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class MetadataFieldComponent < ::ViewComponent::Base
class MetadataFieldComponent < Blacklight::Component
with_collection_parameter :field

# @param field [Blacklight::FieldPresenter]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class MetadataFieldLayoutComponent < ::ViewComponent::Base
class MetadataFieldLayoutComponent < Blacklight::Component
with_collection_parameter :field
renders_one :label
renders_many :values, (lambda do |value: nil, &block|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
module Response
# Render a group of facet fields
class FacetGroupComponent < ::ViewComponent::Base
class FacetGroupComponent < Blacklight::Component
extend Deprecation

renders_one :body
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/response/pagination_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
module Response
# Render a pagination widget for search results
class PaginationComponent < ::ViewComponent::Base
class PaginationComponent < Blacklight::Component
# @param [Blacklight::Response] response
# @param [Hash] html html options for the pagination container
def initialize(response:, html: {}, **pagination_args)
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/search_bar_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class SearchBarComponent < ::ViewComponent::Base
class SearchBarComponent < Blacklight::Component
renders_one :append
renders_one :prepend
renders_one :search_button
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/search_button_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class SearchButtonComponent < ::ViewComponent::Base
class SearchButtonComponent < Blacklight::Component
def initialize(text:, id:)
@text = text
@id = id
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/search_context_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class SearchContextComponent < ::ViewComponent::Base
class SearchContextComponent < Blacklight::Component
with_collection_parameter :search_context

def initialize(search_context:, search_session:)
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/start_over_button_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Blacklight
class StartOverButtonComponent < ::ViewComponent::Base
class StartOverButtonComponent < Blacklight::Component
def call
link_to t('blacklight.search.start_over'), start_over_path, class: 'catalog_startOverLink btn btn-primary'
end
Expand Down
1 change: 1 addition & 0 deletions lib/blacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

module Blacklight
autoload :AbstractRepository, 'blacklight/abstract_repository'
autoload :Component, 'blacklight/component'
autoload :Configuration, 'blacklight/configuration'
autoload :Exceptions, 'blacklight/exceptions'
autoload :Parameters, 'blacklight/parameters'
Expand Down
6 changes: 6 additions & 0 deletions lib/blacklight/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

module Blacklight
class Component < ViewComponent::Base
end
end

0 comments on commit 60cb79b

Please sign in to comment.