Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the component configuration additive
Hopefully this makes it easier to understand how to customize the components. This is done by having all the component configuration generated onto the template CatalogController rather than having it included in a mixin automatically. For backwards compatibility people will have to mix in: ``` include Blacklight::DefaultComponentConfiguration ``` or add to CatalogController: ``` configure_blacklight do |config| config.add_results_document_tool(:bookmark, partial: 'bookmark_control', if: :render_bookmarks_control?) config.add_results_collection_tool(:sort_widget) config.add_results_collection_tool(:per_page_widget) config.add_results_collection_tool(:view_type_group) config.add_show_tools_partial(:bookmark, partial: 'bookmark_control', if: :render_bookmarks_control?) config.add_show_tools_partial(:email, callback: :email_action, validator: :validate_email_params) config.add_show_tools_partial(:sms, if: :render_sms_action?, callback: :sms_action, validator: :validate_sms_params) config.add_show_tools_partial(:citation) config.add_nav_action(:bookmark, partial: 'blacklight/nav/bookmark', if: :render_bookmarks_control?) config.add_nav_action(:search_history, partial: 'blacklight/nav/search_history') end ```
- Loading branch information
Showing
10 changed files
with
210 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
# Dynamically creates methods on the given controller (typically CatalogController) | ||
# for handling configured show tools | ||
class ActionBuilder | ||
def initialize(klass, name, opts) | ||
@klass = klass | ||
@name = name | ||
@opts = opts | ||
end | ||
|
||
attr_reader :klass, :name, :opts | ||
|
||
# Define a simple action handler for the tool as long as the method | ||
# doesn't already exist or the `:define_method` option is not `false` | ||
def build | ||
return if skip? | ||
callback = opts.fetch(:callback, nil).inspect | ||
validator = opts.fetch(:validator, nil).inspect | ||
klass.class_eval <<EORUBY, __FILE__, __LINE__ + 1 | ||
def #{name} | ||
@response, @documents = action_documents | ||
if request.post? && #{callback} && | ||
(#{validator}.blank? || send(#{validator})) | ||
send(#{callback}, @documents) | ||
flash[:success] ||= I18n.t("blacklight.#{name}.success", default: nil) | ||
respond_to do |format| | ||
format.html do | ||
return render "#{name}_success" if request.xhr? | ||
redirect_to action_success_redirect_path | ||
end | ||
end | ||
else | ||
respond_to do |format| | ||
format.html do | ||
return render layout: false if request.xhr? | ||
# Otherwise draw the full page | ||
end | ||
end | ||
end | ||
end | ||
EORUBY | ||
end | ||
# rubocop:enable Metrics/LineLength | ||
|
||
private | ||
|
||
def skip? | ||
klass.method_defined?(name) || opts[:define_method] == false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.