Skip to content

Commit

Permalink
make it possible disable BlacklightHelper loading
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Feb 12, 2014
1 parent 12643e1 commit 7b35816
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/blacklight/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ class Engine < Rails::Engine
require 'bootstrap-sass'
require 'blacklight/rails/routes'

config.inject_blacklight_helpers = true

# BlacklightHelper is needed by all helpers, so we inject it
# into action view base here.
initializer 'blacklight.helpers' do |app|
Blacklight::Engine.add_blacklight_helper! if Blacklight::Engine.config.inject_blacklight_helpers
end

def self.add_blacklight_helper!
ActionView::Base.send :include, BlacklightHelper
end

Expand Down
10 changes: 7 additions & 3 deletions lib/blacklight/solr_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def get_solr_response_for_doc_id(id=nil, extra_controller_params={})
solr_params = solr_doc_params(id).merge(extra_controller_params)
solr_response = find((blacklight_config.document_solr_request_handler || blacklight_config.qt), solr_params)
raise Blacklight::Exceptions::InvalidSolrID.new if solr_response.docs.empty?
document = SolrDocument.new(solr_response.docs.first, solr_response)
document = wrap_solr_document_response(solr_response.docs.first, solr_response)
[solr_response, document]
end

Expand Down Expand Up @@ -475,7 +475,7 @@ def get_solr_response_for_field_values(field, values, extra_solr_params = {})
}.merge(extra_solr_params)

solr_response = find(blacklight_config.qt, self.solr_search_params().merge(solr_params) )
document_list = solr_response.docs.collect{|doc| SolrDocument.new(doc, solr_response) }
document_list = solr_response.docs.collect{|doc| wrap_solr_document_response(doc, solr_response) }
[solr_response,document_list]
end

Expand Down Expand Up @@ -570,7 +570,7 @@ def get_previous_and_next_documents_for_search(index, request_params, extra_cont
solr_params[:facet] = false
solr_response = find(blacklight_config.qt, solr_params)

document_list = solr_response.docs.collect{|doc| SolrDocument.new(doc, solr_response) }
document_list = solr_response.docs.collect{|doc| wrap_solr_document_response(doc, solr_response) }

# only get the previous doc if there is one
prev_doc = document_list.first if index > 0
Expand Down Expand Up @@ -644,4 +644,8 @@ def blacklight_solr
def blacklight_solr_config
Blacklight.solr_config
end

def wrap_solr_document_response doc, solr_response
SolrDocument.new doc, solr_response
end
end

3 comments on commit 7b35816

@jrochkind
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious about the use case for this? At first I thought it was about actual Rails helper methods, but it's not, it's about whether or not to wrap a solr response in a SolrDocument object I guess? Sometimes you don't want to?

@cbeer
Copy link
Member Author

@cbeer cbeer commented on 7b35816 Feb 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a bad commit and merged both. My immediate concern was the Rails helpers and class reloading problems I was having in a downstream app, but resolved that by injecting an actual helper into the app (which seems to help Rails understand what's going on).

The other thing in this commit was the wrapping solr documents, which I still think I need, but wasn't ready for shipping.. The use case there is using something like draper with those SolrDocuments to inject a little bit of controller context closer to the model.

@cbeer
Copy link
Member Author

@cbeer cbeer commented on 7b35816 Feb 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and, note that this is an orphaned commit, not in master or anything.

Please sign in to comment.