Skip to content

Commit

Permalink
Merge pull request #2979 from projectblacklight/component-template-ov…
Browse files Browse the repository at this point in the history
…erride

Component template override
  • Loading branch information
dkinzer committed Feb 2, 2023
2 parents 4f610ca + ca2995a commit 3e4a46f
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/components/blacklight/response/sort_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Blacklight
module Response
class SortComponent < ViewComponent::Base
class SortComponent < Blacklight::Component
def initialize(search_state:, param: 'sort', choices: {}, id: 'sort-dropdown', classes: [], selected: nil)
@param = param
@choices = choices
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/response/spellcheck_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
module Response
# Render spellcheck results for a search query
class SpellcheckComponent < ViewComponent::Base
class SpellcheckComponent < Blacklight::Component
# @param [Blacklight::Response] response
# @param [Array<String>] options explicit spellcheck options to render
def initialize(response:, options: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
module Response
# Render spellcheck results for a search query
class ViewTypeButtonComponent < ViewComponent::Base
class ViewTypeButtonComponent < Blacklight::Component
with_collection_parameter :view
# @param [Blacklight::Configuration::View] view
def initialize(view:, key: nil, selected: false, search_state: nil, classes: 'btn btn-outline-secondary btn-icon')
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/response/view_type_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
module Response
# Render spellcheck results for a search query
class ViewTypeComponent < ViewComponent::Base
class ViewTypeComponent < Blacklight::Component
renders_many :views, 'Blacklight::Response::ViewTypeButtonComponent'

# @param [Blacklight::Response] response
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/system/dropdown_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Blacklight
module System
class DropdownComponent < ViewComponent::Base
class DropdownComponent < Blacklight::Component
renders_one :button, (lambda do |classes:, label:|
button_tag class: classes, aria: { expanded: false }, data: { toggle: 'dropdown', 'bs-toggle': 'dropdown' } do
safe_join([label, content_tag(:span, '', class: 'caret')])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Blacklight
module System
class FlashMessageComponent < ViewComponent::Base
class FlashMessageComponent < Blacklight::Component
renders_one :message

with_collection_parameter :message
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/system/modal_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Blacklight
module System
class ModalComponent < ViewComponent::Base
class ModalComponent < Blacklight::Component
renders_one :prefix
renders_one :header
renders_one :title
Expand Down
8 changes: 8 additions & 0 deletions spec/features/component_template_override_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

RSpec.describe 'Generated test application template at default path' do
it 'unobtrusively overrides default top navbar component template' do
visit root_path
expect(page).to have_css 'nav[data-template-override="top_navbar_component"]'
end
end
8 changes: 8 additions & 0 deletions spec/test_app_templates/lib/generators/test_app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ def add_local_assets_for_propshaft

run "yarn add #{Blacklight::Engine.root}"
end

def add_component_template_override
src_template = File.join(Blacklight::Engine.root, 'app', 'components', 'blacklight', 'top_navbar_component.html.erb')
target_template = File.join('app', 'components', 'blacklight', 'top_navbar_component.html.erb')
create_file(target_template) do
File.read(src_template).gsub('role="navigation"', 'role="navigation" data-template-override="top_navbar_component"')
end
end
end

0 comments on commit 3e4a46f

Please sign in to comment.