Skip to content

Commit

Permalink
Merge 8c12eab into 881c06d
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Mar 23, 2015
2 parents 881c06d + 8c12eab commit 8c71164
Show file tree
Hide file tree
Showing 21 changed files with 195 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ matrix:
env: "RAILS_VERSION=4.1.9"
- rvm: 2.1.5
env: "RAILS_VERSION=4.2.0"
- rvm: 2.1.5
env: "RAILS_VERSION=4.2.1"
- rvm: jruby
env: "RAILS_VERSION=4.2.0 JRUBY_OPTS=\"-J-Xms512m -J-Xmx1024m\""
- rvm: 1.9.3
Expand Down
12 changes: 5 additions & 7 deletions app/helpers/blacklight/configuration_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,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

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

##
Expand All @@ -109,7 +107,7 @@ def facet_field_label field
# @param [Symbol] any number of additional keys
# @param [Symbol] ...
def field_label *i18n_keys
first, *rest = i18n_keys
first, *rest = i18n_keys.compact

t(first, default: rest)
end
Expand Down
7 changes: 6 additions & 1 deletion app/helpers/blacklight/url_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ def session_tracking_params document, counter
return {}
end

{ :data => {:'context-href' => track_solr_document_path(document, per_page: params.fetch(:per_page, search_session['per_page']), counter: counter, search_id: current_search_session.try(:id))}}
{ :data => {:'context-href' => session_tracking_path(document, per_page: params.fetch(:per_page, search_session['per_page']), counter: counter, search_id: current_search_session.try(:id))}}
end
protected :session_tracking_params

##
# Get the URL for tracking search sessions across pages using polymorphic routing
def session_tracking_path document, params = {}
polymorphic_path([:track, document], params)
end

#
# link based helpers ->
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
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"
13 changes: 10 additions & 3 deletions lib/blacklight.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- encoding : utf-8 -*-
require 'kaminari'
require 'deprecation'
require 'blacklight/utils'

module Blacklight
autoload :Configurable, 'blacklight/configurable'
autoload :Configuration, 'blacklight/configuration'
Expand Down Expand Up @@ -28,8 +30,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 @@ -144,7 +145,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
2 changes: 1 addition & 1 deletion lib/blacklight/abstract_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def connection_config
end

def logger
@logger ||= Rails.logger if defined? Rails
@logger ||= Blacklight.logger
end
end
end
2 changes: 1 addition & 1 deletion lib/blacklight/catalog/search_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def setup_next_and_previous_documents
@next_document = documents.last
end
rescue Blacklight::Exceptions::InvalidRequest => e
Rails.logger.warn "Unable to setup next and previous documents: #{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 @@ -5,7 +5,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

Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/configuration/search_field.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Blacklight
class Configuration::SearchField < Blacklight::Configuration::Field
def normalize! blacklight_config = nil
self.if ||= self.include_in_simple_select
self.if = self.include_in_simple_select if self.if.nil?

super
self.qt ||= blacklight_config.default_solr_params[:qt] if blacklight_config && blacklight_config.default_solr_params
Expand Down
30 changes: 24 additions & 6 deletions lib/blacklight/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Blacklight::Document
include Blacklight::Document::Extensions
end

attr_reader :response
attr_reader :response, :_source
alias_method :solr_response, :response

def initialize(source_doc={}, response=nil)
Expand All @@ -52,11 +52,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 and _source.respond_to? m
_source.send(m, *args, &b)
else
super
end
end

def respond_to_missing? *args
(_source && _source.respond_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 @@ -81,7 +93,7 @@ def has?(k, *values)
end

def key? k
@_source.key? k
_source.key? k
end

# helper
Expand Down Expand Up @@ -112,7 +124,7 @@ def to_param
end

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

def to_partial_path
Expand All @@ -135,6 +147,12 @@ def highlight_field k
nil
end

##
# Implementations that support More-Like-This should override this method
# to return an array of documents that are like this one.
def more_like_this
[]
end

# Certain class-level methods needed for the document-specific
# extendability architecture
Expand All @@ -153,4 +171,4 @@ def base_class
self
end
end
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 @@ -45,8 +45,8 @@ def send_and_receive(path, solr_params = {})

solr_response = blacklight_config.response_model.new(res, solr_params, document_model: blacklight_config.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
3 changes: 3 additions & 0 deletions lib/generators/blacklight/templates/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"
4 changes: 3 additions & 1 deletion lib/generators/blacklight/user_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def inject_blacklight_user_behavior
file_path = "app/models/#{model_name.underscore}.rb"
if File.exists?(file_path)
inject_into_class file_path, model_name.classify do
"\n attr_accessible :email, :password, :password_confirmation if Rails::VERSION::MAJOR < 4\n" +
"\n if Blacklight::Utils.needs_attr_accessible?\n" +
"\n attr_accessible :email, :password, :password_confirmation" +
"\n end\n" +
"# Connects this user object to Blacklights Bookmarks. " +
"\n include Blacklight::User\n"
end
Expand Down
7 changes: 7 additions & 0 deletions spec/helpers/configuration_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@

label = helper.field_label :key_a, :key_b, "default text"
end

it "should compact nil keys (fixes rails/rails#19419)" do
allow(helper).to receive(:t).with(:key_a, default: [:key_b])

label = helper.field_label :key_a, nil, :key_b

end
end

describe "#default_per_page" do
Expand Down
Loading

0 comments on commit 8c71164

Please sign in to comment.