Skip to content

Commit

Permalink
index_tool_partial should be inheritable
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 18, 2014
1 parent f46ade2 commit 35000a0
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/helpers/blacklight/blacklight_helper_behavior.rb
Expand Up @@ -104,7 +104,7 @@ def render_index_doc_actions(document, options={})
wrapping_class = options.delete(:wrapping_class) || "index-document-functions"

content = []
index_tool_partials.select { |config| evaluate_if_unless_configuration config, @document }.each do |config|
index_tool_partials.select { |_, config| evaluate_if_unless_configuration config, @document }.each do |_, config|
content << render(config.partial, { document: document }.merge(options))
end

Expand Down
4 changes: 0 additions & 4 deletions lib/blacklight/bookmarks.rb
Expand Up @@ -10,16 +10,12 @@ module Blacklight::Bookmarks
include Blacklight::Configurable
include Blacklight::SolrHelper
include Blacklight::TokenBasedUser
include Blacklight::Catalog::IndexTools

copy_blacklight_config_from(CatalogController)

before_filter :verify_user

self.document_actions[:sms].if = false if self.document_actions[:sms]

# provided by Blacklight::Catalog::IndexTools
add_index_tools_partial('catalog/bookmark_control', if: :render_bookmarks_control?)
end

def action_documents
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/catalog.rb
Expand Up @@ -34,7 +34,7 @@ module Blacklight::Catalog
add_document_action(:librarian_view, if: Proc.new { |ctx, config, doc| ctx.respond_to? :librarian_view_catalog_path and doc.respond_to?(:to_marc) })

# provided by Blacklight::Catalog::IndexTools
add_index_tools_partial('catalog/bookmark_control', if: :render_bookmarks_control?)
add_index_tools_partial(:bookmark, partial: 'bookmark_control', if: :render_bookmarks_control?)

end

Expand Down
13 changes: 9 additions & 4 deletions lib/blacklight/catalog/index_tools.rb
Expand Up @@ -2,6 +2,7 @@ module Blacklight
module Catalog::IndexTools
extend ActiveSupport::Concern
included do
class_attribute :inheritable_tool_partials
helper_method :index_tool_partials
end

Expand All @@ -11,7 +12,7 @@ def index_tool_partials

module ClassMethods
def index_tool_partials
@index_tool_partials ||= []
@index_tool_partials ||= (inheritable_tool_partials || Hash.new).deep_dup
end

##
Expand All @@ -21,13 +22,17 @@ def index_tool_partials
# The proc will receive the action configuration and the document or documents for the action.
# @option opts [Symbol,Proc] :unless render this action unless the method identified by the symbol or the proc evaluates to true
# The proc will receive the action configuration and the document or documents for the action.
def add_index_tools_partial partial, opts = {}
config = Blacklight::Configuration::ToolConfig.new({partial: partial}.merge(opts))
def add_index_tools_partial name, opts = {}
config = Blacklight::Configuration::ToolConfig.new opts
config.name = name

if block_given?
yield config
end
index_tool_partials << config

index_tool_partials[name] = config

self.inheritable_tool_partials = index_tool_partials
end
end
end
Expand Down
19 changes: 19 additions & 0 deletions spec/controllers/alternate_controller_spec.rb
@@ -0,0 +1,19 @@
require 'spec_helper'

describe AlternateController do
describe "add_index_tools_partial" do
it "should inherit tools from CatalogController" do
expect(AlternateController.index_tool_partials).to have_key(:bookmark)
end

context "when deleting partials from the AlternateController" do
before do
AlternateController.index_tool_partials.delete(:bookmark)
end
it "should not affect the CatalogController" do
expect(AlternateController.index_tool_partials).to be_empty
expect(CatalogController.index_tool_partials).to have_key(:bookmark)
end
end
end
end
1 change: 0 additions & 1 deletion spec/features/alternate_controller_spec.rb
Expand Up @@ -31,6 +31,5 @@
expect(page).to have_selector ".document-thumbnail"
expect(page).to have_selector ".document-thumbnail a[data-context-href]"
expect(page).to have_selector ".document-thumbnail a img"

end
end
2 changes: 1 addition & 1 deletion spec/helpers/blacklight_helper_spec.rb
Expand Up @@ -112,7 +112,7 @@ def mock_document_app_helper_url *args

describe "with a config" do
let :index_tool_partials do
[Blacklight::Configuration::ToolConfig.new(partial: 'catalog/bookmark_control', if: :render_bookmarks_control?)]
{ bookmark: Blacklight::Configuration::ToolConfig.new(partial: 'catalog/bookmark_control', if: :render_bookmarks_control?) }
end

before do
Expand Down
2 changes: 1 addition & 1 deletion spec/views/catalog/_index_header_default.html.erb_spec.rb
Expand Up @@ -10,7 +10,7 @@
end

let :index_tool_partials do
[Blacklight::Configuration::ToolConfig.new(partial: 'catalog/bookmark_control', if: :render_bookmarks_control?)]
{ bookmark: Blacklight::Configuration::ToolConfig.new(partial: 'catalog/bookmark_control', if: :render_bookmarks_control?) }
end

it "should render the document header" do
Expand Down

0 comments on commit 35000a0

Please sign in to comment.