Skip to content

Commit

Permalink
Merge 2fb7636 into 751c0f2
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Mar 23, 2015
2 parents 751c0f2 + 2fb7636 commit 96965ee
Show file tree
Hide file tree
Showing 27 changed files with 256 additions and 81 deletions.
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ gemspec path: File.expand_path('..', __FILE__)
gem 'simplecov', '~> 0.7.1', require: false
gem 'coveralls', require: false

gem 'engine_cart', '~> 0.4'

group :test do
gem "blacklight-marc", "~> 5.0", github: "projectblacklight/blacklight_marc"
gem "blacklight-marc", "5.5.0"
gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
end

Expand Down
3 changes: 1 addition & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ Bundler::GemHelper.install_tasks

load "tasks/blacklight.rake"

task :default => [:ci]
task :clean => ['blacklight:clean']
task :default => [:ci]
6 changes: 4 additions & 2 deletions app/helpers/blacklight/blacklight_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,10 @@ def field_value_separator
# @param [Hash] the query parameters to check
# @return [Symbol]
def document_index_view_type query_params=params
if query_params[:view] and blacklight_config.view.keys.include? query_params[:view].to_sym
query_params[:view].to_sym
view_param = query_params[:view]
view_param ||= session[:preferred_view]
if view_param and document_index_views.keys.include? view_param.to_sym
view_param.to_sym
else
default_document_index_view_type
end
Expand Down
10 changes: 4 additions & 6 deletions app/helpers/blacklight/configuration_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,11 @@ def document_show_field_label document, field
# Look up the label for the facet field
def facet_field_label field
field_config = blacklight_config.facet_fields[field]
defaults = [:"blacklight.search.fields.facet.#{field}", :"blacklight.search.fields.#{field}"]
defaults << field_config.label if field_config
defaults << field.to_s.humanize

solr_field_label(
:"blacklight.search.fields.facet.#{field}",
:"blacklight.search.fields.#{field}",
(field_config.label if field_config),
field.to_s.humanize
)
solr_field_label *defaults
end

##
Expand Down
5 changes: 4 additions & 1 deletion app/models/bookmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ class Bookmark < ActiveRecord::Base
belongs_to :document, polymorphic: true

validates_presence_of :user_id, :scope=>:document_id
attr_accessible :id, :document_id, :document_type, :title if Rails::VERSION::MAJOR < 4

if Blacklight::Utils.needs_attr_accessible?
attr_accessible :id, :document_id, :document_type, :title
end

def document
document_type.new document_type.unique_key => document_id
Expand Down
9 changes: 6 additions & 3 deletions app/models/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ class Search < ActiveRecord::Base

serialize :query_params

if Rails::VERSION::MAJOR < 4
if Blacklight::Utils.needs_attr_accessible?
attr_accessible :query_params

scope :none, where(:id => nil).where("id IS NOT ?", nil)
end

unless respond_to?(:none)
# polyfill
scope :none, where(id: nil).where("id IS NOT ?", nil)
end

# A Search instance is considered a saved search if it has a user_id.
Expand Down
56 changes: 48 additions & 8 deletions app/views/catalog/_home_text.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,49 @@
<h4><%= t('blacklight.welcome') %></h4>
<p>&nbsp;</p>
<p>To modify this text to your specifications, copy this file located in the blacklight plugin directory:<br/>
&nbsp;&nbsp;&nbsp;<%= Blacklight.root %>/app/views/catalog/_home_text.html.erb</p>
<p>to your top level rails app:<br/>
&nbsp;&nbsp;&nbsp;<%= Rails.root %>/app/views/catalog/_home_text.html.erb</p>
<p>Note that you will need to create the 'catalog' directory under views.</p>
<% #Creates a bit space in the page -%>
<div class="page-header row">
<h1 class="col-md-8"><%= t('blacklight.welcome') %></h1>
<ul class="nav nav-pills col-md-4">
<li><a href="https://github.com/projectblacklight/blacklight/">Github</a></li>
<li><a href="https://github.com/projectblacklight/blacklight/wiki">Wiki</a></li>
<li><a href="https://github.com/projectblacklight/blacklight/releases/tag/v<%= Blacklight::VERSION %>">Release Notes</a></li>
</ul>


</div>

<div id="getting-started">
<h2>Here&rsquo;s how to get started:</h2>

<ol>
<li>To modify this text, you need to <a href="http://guides.rubyonrails.org/engines.html#improving-engine-functionality">override the Blacklight-provided view</a>.
You can copy this file, located in the blacklight gem: <br />
<%= Blacklight.root %>/app/views/catalog/_home_text.html.erb <br />
to your own application: <br />
<%= Rails.root %>/app/views/catalog/_home_text.html.erb
</li>
<li><a href="https://github.com/projectblacklight/blacklight/wiki/Indexing-your-data-into-solr">Index your own data</a> into Solr</li>
<li><a href="https://github.com/projectblacklight/blacklight/wiki#blacklight-configuration">Configure Blacklight</a> to match your data and user-experience needs</li>
<li><a href="https://github.com/projectblacklight/blacklight/wiki#support">Get in touch</a> with your comments, questions, and ideas</li>
</ol>
</div>

<%# This is the same panel shown in the Rails welcome template %>
<div id="about">
<h3><a href="/rails/info/properties">About your application&rsquo;s environment</a></h3>
<div id="about-content" class="well" style="display: none"></div>
</div>

<script>
$(function() {
$('#about a').on('click', function(e) {
e.preventDefault();

if ($('#about-content').html() == "") {
$('#about-content').load($(this).attr("href"), function() {
$('#about-content').show();
});
} else {
$('#about-content').toggle();
}
});
});
</script>
2 changes: 1 addition & 1 deletion app/views/catalog/_sms_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

</div>
<% @documents.each do |doc| %>
<%=hidden_field_tag "id[]", doc.get(:id)%>
<%=hidden_field_tag "id[]", doc.id %>
<% end %>
</div>
<div class="modal-footer">
Expand Down
2 changes: 1 addition & 1 deletion blacklight.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec-collection_matchers", ">= 1.0"
s.add_development_dependency "capybara"
s.add_development_dependency "poltergeist"
s.add_development_dependency 'engine_cart', ">= 0.1.0"
s.add_development_dependency 'engine_cart', ">= 0.6.0"
s.add_development_dependency "equivalent-xml"
end
3 changes: 3 additions & 0 deletions config/jetty.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
development:
startup_wait: 15
jetty_port: 8983
java_version: ">= 1.7"
test:
startup_wait: 60
jetty_port: <%= ENV['TEST_JETTY_PORT'] || 8888 %>
<%= ENV['TEST_JETTY_PATH'] ? "jetty_home: " + ENV['TEST_JETTY_PATH'] : '' %>
java_version: ">= 1.7"
production:
startup_wait: 15
jetty_port: 8983
java_version: ">= 1.7"
14 changes: 11 additions & 3 deletions lib/blacklight.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# -*- encoding : utf-8 -*-
require 'kaminari'
require 'rsolr'
require 'deprecation'
require 'blacklight/utils'

module Blacklight

autoload :Configurable, 'blacklight/configurable'
Expand All @@ -25,8 +28,7 @@ module Blacklight
autoload :DocumentPresenter, 'blacklight/document_presenter'

autoload :Routes, 'blacklight/routes'

autoload :OpenStructWithHashAccess, 'blacklight/utils'

autoload :SolrResponse, 'blacklight/solr_response'
autoload :Facet, 'blacklight/facet'

Expand Down Expand Up @@ -92,7 +94,13 @@ def self.solr_yml
end

def self.logger
::Rails.logger
@logger ||= begin
::Rails.logger if defined? Rails and Rails.respond_to? :logger
end
end

def self.logger= logger
@logger = logger
end

#############
Expand Down
21 changes: 16 additions & 5 deletions lib/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def index
(@response, @document_list) = get_search_results

respond_to do |format|
format.html { preferred_view }
format.html { store_preferred_view }
format.rss { render :layout => false }
format.atom { render :layout => false }
format.json do
Expand All @@ -45,7 +45,8 @@ def index
end
end

# get single document from the solr index
# get a single document from the index
# to add responses for formats other than html or json see _Blacklight::Document::Export_
def show
@response, @document = get_solr_response_for_doc_id params[:id]

Expand Down Expand Up @@ -134,13 +135,23 @@ def has_search_parameters?
# do not specifiy the view, set the view parameter to the value stored in the
# session. This enables a user with a session to do subsequent searches and have
# them default to the last used view.
def preferred_view
def store_preferred_view
session[:preferred_view] = params[:view] if params[:view]
params[:view] ||= session[:preferred_view]
end

alias_method :preferred_view, :store_preferred_view
deprecation_deprecate :preferred_view

##
# Render additional response formats, as provided by the blacklight configuration
# Render additional response formats for the index action, as provided by the
# blacklight configuration
#
# example:
#
# config.index.respond_to.txt = Proc.new { render text: "A list of docs." }
#
# Make sure your format has a well known mime-type or is registered in
# config/initializers/mime_types.rb
def additional_response_formats format
blacklight_config.index.respond_to.each do |key, config|
format.send key do
Expand Down
2 changes: 2 additions & 0 deletions lib/blacklight/catalog/search_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def setup_next_and_previous_documents
@previous_document = documents.first
@next_document = documents.last
end
rescue Blacklight::Exceptions::InvalidRequest => e
logger.warn "Unable to setup next and previous documents: #{e}"
end

end
2 changes: 1 addition & 1 deletion lib/blacklight/configuration/facet_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def normalize! blacklight_config = nil

self.collapse = true if self.collapse.nil?
self.show = true if self.show.nil?
self.if ||= self.show
self.if = self.show if self.if.nil?

super
end
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/configuration/search_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def normalize! blacklight_config = nil
self.field ||= self.key
self.label ||= self.key.try(:titlecase)
self.qt ||= blacklight_config.default_solr_params[:qt] if blacklight_config && blacklight_config.default_solr_params
self.if ||= self.include_in_simple_select
self.if = self.include_in_simple_select if self.if.nil?
super
end

Expand Down
4 changes: 3 additions & 1 deletion lib/blacklight/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class Routes
# klass.default_route_sets += [:widget_routing]
# end
# def widget_routing(primary_resource)
# get "#{primary_resource}/widget", "#{primary_resource}#widget"
# add_routes do |options|
# get "#{primary_resource}/widget", "#{primary_resource}#widget"
# end
# end
# end
# Blacklight::Routes.send(:include, MyWidget::Routes)
Expand Down
32 changes: 24 additions & 8 deletions lib/blacklight/solr/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Blacklight::Solr::Document
include Blacklight::Solr::Document::Extensions
end

attr_reader :solr_response
attr_reader :solr_response, :_source

def initialize(source_doc={}, solr_response=nil)
@_source = source_doc.with_indifferent_access
Expand All @@ -54,11 +54,23 @@ def persisted?
# If a method is missing, it gets sent to @_source
# with all of the original params and block
def method_missing(m, *args, &b)
@_source.send(m, *args, &b)
if _source_responds_to?(m)
_source.send(m, *args, &b)
else
super
end
end

def respond_to_missing? *args
_source_responds_to?(*args) || super
end

def [] *args
@_source.send :[], *args
_source.send :[], *args
end

def _read_attribute(attr)
self[attr]
end

# Helper method to check if value/multi-values exist for a given key.
Expand All @@ -83,8 +95,9 @@ def has?(k, *values)
end

def key? k
@_source.key? k
_source.key? k
end
alias_method :has_key?, :key?

def has_highlight_field? k
return false if @solr_response['highlighting'].blank? or @solr_response['highlighting'][self.id].blank?
Expand Down Expand Up @@ -126,7 +139,7 @@ def to_param
end

def as_json(options = nil)
@_source.as_json(options)
_source.as_json(options)
end

def to_partial_path
Expand Down Expand Up @@ -203,7 +216,10 @@ def field_semantics
@field_semantics ||= {}
end
end



private

def _source_responds_to? *args
_source && self != _source && _source.respond_to?(*args)
end

end
4 changes: 2 additions & 2 deletions lib/blacklight/solr_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def send_and_receive(path, solr_params = {})

solr_response = blacklight_config.solr_response_model.new(res, solr_params, solr_document_model: blacklight_config.solr_document_model)

Rails.logger.debug("Solr query: #{solr_params.inspect}")
Rails.logger.debug("Solr response: #{solr_response.inspect}") if defined?(::BLACKLIGHT_VERBOSE_LOGGING) and ::BLACKLIGHT_VERBOSE_LOGGING
Blacklight.logger.debug("Solr query: #{solr_params.inspect}")
Blacklight.logger.debug("Solr response: #{solr_response.inspect}") if defined?(::BLACKLIGHT_VERBOSE_LOGGING) and ::BLACKLIGHT_VERBOSE_LOGGING
solr_response
end
rescue Errno::ECONNREFUSED => e
Expand Down
23 changes: 23 additions & 0 deletions lib/blacklight/utils.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
require 'ostruct'
module Blacklight

module Utils
def self.needs_attr_accessible?
if rails_3?
!strong_parameters_enabled?
else
protected_attributes_enabled?
end
end

def self.rails_3?
Rails::VERSION::MAJOR == 3
end

def self.strong_parameters_enabled?
defined?(ActionController::StrongParameters)
end

def self.protected_attributes_enabled?
defined?(ActiveModel::MassAssignmentSecurity)
end
end

##
# An OpenStruct that responds to common Hash methods
class OpenStructWithHashAccess < OpenStruct
Expand Down
Loading

0 comments on commit 96965ee

Please sign in to comment.