Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component template override #2979

Merged
merged 2 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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