blacklight 3.5.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.5.0
1
+ 3.6.0
@@ -23,7 +23,7 @@ class BookmarksController < ApplicationController
23
23
  success = bookmark.save
24
24
 
25
25
  unless request.xhr?
26
- if bookmark.save
26
+ if success
27
27
  flash[:notice] = I18n.t('blacklight.bookmarks.add.success')
28
28
  else
29
29
  flash[:error] = I18n.t('blacklight.bookmarks.add.failure')
@@ -260,10 +260,11 @@ module Blacklight::BlacklightHelperBehavior
260
260
 
261
261
  def render_document_index_label doc, opts
262
262
  label = nil
263
- label ||= doc.get(opts[:label]) if opts[:label].instance_of? Symbol
263
+ label ||= doc.get(opts[:label], :sep => nil) if opts[:label].instance_of? Symbol
264
264
  label ||= opts[:label].call(doc, opts) if opts[:label].instance_of? Proc
265
265
  label ||= opts[:label] if opts[:label].is_a? String
266
266
  label ||= doc.id
267
+ render_field_value label
267
268
  end
268
269
 
269
270
  # link_to_document(doc, :label=>'VIEW', :counter => 3)
@@ -18,7 +18,10 @@ module Blacklight::CatalogHelperBehavior
18
18
  # kaminari paginate, passed on through.
19
19
  # will output HTML pagination controls.
20
20
  def paginate_rsolr_response(response, options = {}, &block)
21
- paginate paginate_params(response), options, &block
21
+ per_page = response.rows
22
+ per_page = 1 if per_page < 1
23
+ current_page = (response.start / per_page).ceil + 1
24
+ paginate Kaminari.paginate_array(response.docs, :total_count => response.total).page(current_page).per(per_page), options, &block
22
25
  end
23
26
 
24
27
  #
@@ -23,7 +23,7 @@
23
23
  <tr>
24
24
  <td><%= link_to h(bm.title), polymorphic_path(bm.document) %></td>
25
25
  <td><%= button_to t('blacklight.bookmarks.delete'), {:controller => "bookmarks", :action => "destroy", :id => CGI.escape(bm.document_id)},
26
- :method => :delete, :confirm => t('blacklight.bookmarks.remove.action_confirm') %></td>
26
+ :method => :delete, :data => { :confirm => t('blacklight.bookmarks.remove.action_confirm') } %></td>
27
27
  </tr>
28
28
  <% end %>
29
29
  </table>
@@ -24,7 +24,7 @@
24
24
  t('blacklight.search.filters.remove.label_value', :label => (options[:escape_label] ? h(label) : label), :value => (options[:escape_value] ? h(value) : value))
25
25
  end
26
26
  %>
27
- <%= link_to(accessible_remove_label,
27
+ <%= link_to(accessible_remove_label.html_safe,
28
28
  options[:remove],
29
29
  :class=>'btnRemove imgReplace',
30
30
  :alt=>'remove'
@@ -1,4 +1,4 @@
1
- <% if @response.response[:numFound] <= spell_check_max and @response.spelling.words.size > 0 %>
1
+ <% if @response.total <= spell_check_max and @response.spelling.words.size > 0 %>
2
2
  <div id="spell">
3
3
  <h4 class="suggest"><i><%= t('blacklight.did_you_mean', :options => @response.spelling.words.map { |word| link_to_query(word) }.join(" #{t('blacklight.or')} ")).html_safe %></i></h4>
4
4
  </div>
@@ -1,18 +1,8 @@
1
1
  <% # container for a single doc -%>
2
2
  <div class="document <%= render_document_class document %>">
3
3
 
4
- <% # header bar for doc items in index view -%>
5
- <div class="documentHeader">
6
-
7
- <% # bookmark/folder functions for items/docs -%>
8
- <%= render_index_doc_actions document %>
9
-
10
- <% # main title container for doc partial view -%>
11
- <div class="yui-u">
12
- <h3 class="index_title"><%= t('blacklight.search.documents.counter', :counter => (document_counter + 1 + @response.params[:start].to_i)) %><%= link_to_document document, :label=>document_show_link_field, :counter => (document_counter + 1 + @response.params[:start].to_i) %></h3>
13
- </div>
14
- </div>
15
-
4
+ <%= render :partial => 'document_header', :locals => { :document => document, :document_counter => document_counter } %>
5
+
16
6
  <% # main container for doc partial view -%>
17
7
  <%= render_document_partial document, :index %>
18
8
 
@@ -0,0 +1,13 @@
1
+
2
+ <% # header bar for doc items in index view -%>
3
+ <div class="documentHeader">
4
+
5
+ <% # bookmark/folder functions for items/docs -%>
6
+ <%= render_index_doc_actions document %>
7
+
8
+ <% # main title container for doc partial view -%>
9
+ <div class="yui-u">
10
+ <h3 class="index_title"><%= t('blacklight.search.documents.counter', :counter => (document_counter + 1 + @response.params[:start].to_i)) %><%= link_to_document document, :label=>document_show_link_field, :counter => (document_counter + 1 + @response.params[:start].to_i) %></h3>
11
+ </div>
12
+ </div>
13
+
@@ -1,4 +1,10 @@
1
1
  <% # container for all documents in index view -%>
2
2
  <div id="documents">
3
- <%= render :partial => 'document', :collection => @document_list, :as => :document %>
3
+ <% if Rails.version > "3.2.0" %>
4
+ <%= render @document_list, :as => :document %>
5
+ <% else %>
6
+ <% @document_list.each_with_index do |document, document_counter| %>
7
+ <%= render :partial => document.to_partial_path, :locals => { :document => document, :document_counter => document_counter } %>
8
+ <% end %>
9
+ <% end %>
4
10
  </div>
@@ -1,5 +1,5 @@
1
1
  <div id="sortAndPerPage">
2
- <% unless @response.response['numFound'] < 2 %>
2
+ <% unless @response.total < 2 %>
3
3
  <%-# kind of hacky way to get this to work on catalog and folder controllers. May be able to simple do {:action=>"index"} but I'm not sure -%>
4
4
  <%= form_tag params[:controller] == "folder" ? folder_index_path : url_for(:action=>'index'), :method=>:get, :class=>'per_page' do %>
5
5
  <%= label_tag(:per_page, t('blacklight.search.per_page.label', :select => select_tag(:per_page, options_for_select(['10', '20', '50', '100'], h(params[:per_page])), :title => t('blacklight.search.per_page.title'))).html_safe) %>
@@ -10,7 +10,7 @@
10
10
 
11
11
  <%- else -%>
12
12
  <p>
13
- <%= link_to t('blacklight.saved_searches.clear.action_title'), clear_saved_searches_path, :method => :delete, :confirm => t('blacklight.saved_searches.clear.action_confirm') %>
13
+ <%= link_to t('blacklight.saved_searches.clear.action_title'), clear_saved_searches_path, :method => :delete, :data => { :confirm => t('blacklight.saved_searches.clear.action_confirm') } %>
14
14
  </p>
15
15
 
16
16
  <h2><%= t('blacklight.saved_searches.list_title') %></h2>
data/blacklight.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.add_dependency "marc", ">= 0.4.3", "< 1.1" # Marc record parser.
29
29
  s.add_dependency "rsolr", "~> 1.0.6" # Library for interacting with rSolr.
30
30
  s.add_dependency "rsolr-ext", '~> 1.0.3' # extension to the above for some rails-ish behaviors - currently embedded in our solr document ojbect.
31
- s.add_dependency "kaminari" # the pagination (page 1,2,3, etc..) of our search results
31
+ s.add_dependency "kaminari", "~> 0.13" # the pagination (page 1,2,3, etc..) of our search results
32
32
  s.add_dependency "sass-rails"
33
33
  s.add_development_dependency "jettywrapper", ">= 1.2.0"
34
34
  s.add_dependency "compass-rails", "~> 1.0.0"
data/lib/blacklight.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
- require 'blacklight/kaminari_relevant_pages_patch'
2
+ require 'kaminari'
3
3
  require 'rsolr'
4
4
  require 'rsolr-ext'
5
5
 
@@ -16,85 +16,28 @@ require 'rsolr-ext'
16
16
  # It also provides support for Document Extensions, which advertise supported
17
17
  # transformation formats.
18
18
  #
19
- # = Document Extensions
20
- # An Blacklight::Solr::Document extension is simply a ruby module which is mixed
21
- # in to individual Document instances. The intended use case is for documents
22
- # containing some particular format of source material, such as Marc. An
23
- # extension can be registered with your document class, along with a block
24
- # containing custom logic for which documents to apply the extension to.
25
- #
26
- # SolrDocument.use_extension(MyExtension) {|document| my_logic_on_document(document}
27
- #
28
- # MyExtension will be mixed-in (using ruby 'extend') only to those documents
29
- # where the block results in true.
30
- #
31
- # == Transformation conventions
32
- # The main use case for extensions is for transforming a Document to another
33
- # format. Either to another type of Ruby object, or to an exportable string in
34
- # a certain format.
35
- #
36
- # The convention for methods contained in extensions that transform to a ruby
37
- # object is "to_*". For instance, "to_marc" would return a Ruby Marc object.
38
- #
39
- # The convention for methods contained in extensions that transform to an
40
- # exportable file of some kind is "export_as_*". For instance,
41
- # "export_as_marc21" would return a String object containing valid marc21, and
42
- # "export_as_marcxml" would return a String object containing valid marcxml.
43
- #
44
- # The tokens used after "export_as" should normally be the format names as
45
- # registered with Rails Mime::Type.
46
- #
47
- # == Advertising export formats
48
- #
49
- # If an extension advertises what export formats it can provide, than those
50
- # formats will automatically be delivered by the Blacklight catalog/show
51
- # controller, and potentially automatically advertised in various places
52
- # that advertise available formats. (HTML link rel=alternate; Atom
53
- # link rel=alterate; etc).
54
- #
55
- # Export formats are 'registered' by calling the #will_export_as method
56
- # on a Document instance. An extension would usually do this in a
57
- # self.extended method, so it can be called on Documents that have
58
- # the given extension added to them. For instance:
59
- #
60
- # module DemoMarcExtension
61
- # def self.extended(document)
62
- # document.will_export_as(:marc21, "application/marc")
63
- # document.will_export_as(:marcxml, "application/marcxml+xml")
64
- # end
65
- #
66
- # def export_as_marc21 ; something ; end
67
- # def export_as_marcxml ; something ; end
68
- # end
69
- #
70
- # == Extension Parameters
71
- # Every class that includes Blacklight::Solr::Document gets a
72
- # #extension_parameters method for saving arbitrary parameters on class-wide
73
- # level that can be retrieved by extensions. These are arbitrary, just
74
- # conventions with a given extension. For instance:
75
- # SolrDocument.extension_parameters[:marc_source_field] = "solr_stored_field_name"
76
- #
19
+
77
20
  module Blacklight::Solr::Document
78
21
  autoload :Marc, 'blacklight/solr/document/marc'
79
22
  autoload :MarcExport, 'blacklight/solr/document/marc_export'
80
23
  autoload :DublinCore, 'blacklight/solr/document/dublin_core'
81
24
  autoload :Email, 'blacklight/solr/document/email'
82
25
  autoload :Sms, 'blacklight/solr/document/sms'
83
-
84
- def self.included(base)
85
- base.send :include, RSolr::Ext::Model
86
- base.send :include, InstanceMethods
87
- base.send :extend, ClassMethods
88
- base.send :extend, ActiveModel::Naming
89
-
90
- # after_initialize hook comes from RSolr::Ext::Model, I think.
91
- # We need to make sure all extensions get applied.
92
- base.after_initialize do
93
- apply_extensions
94
- end
26
+ autoload :Extensions, 'blacklight/solr/document/extensions'
27
+ autoload :Export, 'blacklight/solr/document/export'
28
+
29
+ extend ActiveSupport::Concern
30
+ include Blacklight::Solr::Document::Export
31
+
32
+ included do
33
+ extend ActiveModel::Naming
34
+ include RSolr::Ext::Model
35
+ include RSolrExtOverrides
36
+ include Blacklight::Solr::Document::Extensions
37
+
95
38
  end
96
39
 
97
- module InstanceMethods
40
+ module RSolrExtOverrides
98
41
  def id
99
42
  self[self.class.unique_key]
100
43
  end
@@ -104,107 +47,40 @@ module Blacklight::Solr::Document
104
47
  end
105
48
  end
106
49
 
50
+ def to_partial_path
51
+ 'catalog/document'
52
+ end
107
53
 
108
- # Needs to be called in initializer of class including this module, to
109
- # apply all registered extensions on a per-document basis
110
- def apply_extensions
111
- self.class.registered_extensions.each do | registration|
112
- self.extend( registration[:module_obj] ) if registration[:condition_proc].nil? || registration[:condition_proc].call( self )
113
- end
114
- end
115
-
116
- ##
117
- # Register exportable formats supported by the individual document.
118
- # Usually called by an extension in it's self.extended method, to
119
- # register the formats that extension can export.
120
- #
121
- # some_document.will_export_as(:some_format, "application/type") means
122
- # that the document (usually via an extension) has a method
123
- # "export_as_some_format" which returns a String of content that
124
- # is described by the mime content_type given.
125
- #
126
- # The format name should ideally _already_ be registered with
127
- # Rails Mime::Type, in your application initializer, representing
128
- # the content type given. However, this method will attempt to
129
- # register it using Mime::Type.register_alias if it's not previously
130
- # registered. This is a bit sketchy though.
131
- def will_export_as(short_name, content_type = nil)
132
- #Lookup in Rails Mime::Type, register if needed, otherwise take
133
- # content-type from registration if needed. This uses
134
- # some 'api' to Mime::Type that may or may not be entirely
135
- # public, the fact that a Mime::CONST is registered for every
136
- # type. But that's the only way to do the kind of check we need, sorry.
137
- if defined?(Mime) && Mime.const_defined?(short_name.to_s.upcase)
138
- mime_type = "Mime::#{short_name.to_s.upcase}".constantize
139
- content_type = mime_type.to_s unless content_type
140
- else
141
- # not registered, we need to register. Use register_alias to be least
142
- # likely to interfere with host app.
143
- Mime::Type.register_alias(content_type, short_name)
144
- end
145
-
146
- # if content_type is nil, look it up from Rails Mime::Type
147
- if content_type.nil?
148
- # Accurate lookup in Rails Mime::Type is kind of pain, it doesn't
149
- # really provide the right API.
150
- if defined?(type_const_name)
151
- content_type = type_const_name.constantize.to_s
152
- end
153
- end
154
- export_formats[short_name] = {:content_type => content_type}
155
- end
156
-
157
- # Collects formats that this doc can export as.
158
- # Returns a hash, keys are format short-names that can
159
- # be exported. Hash includes:
160
- # :content-type => mime-content-type
161
- # maybe more later
162
- # To see if a given export format is supported by this document,
163
- # simply call document.export_formats.keys.include?(:my_format)
164
- # Then call #export_as! to do the export.
165
- def export_formats
166
- @export_formats ||= {}
167
- end
168
-
169
- # Call with a format shortname, export_as(:marc), simply returns
170
- # #export_as_marc . Later we may expand the design to allow you
171
- # to register an arbitrary method name instead of insisting
172
- # on the convention, so clients should call this method so
173
- # they'll still keep working if we do that.
174
- def export_as(short_name)
175
- send("export_as_#{short_name.to_s}")
176
- end
177
-
178
- # Returns a hash keyed by semantic tokens (see ExtendableClassMethods#semantic_fields), value is an array of
179
- # strings. (Array to handle multi-value fields). If no value(s)
180
- # available, empty array is returned.
181
- #
182
- # Default implementation here uses ExtendableClassMethods#semantic_fields
183
- # to just take values from Solr stored fields.
184
- # Extensions can over-ride this method to provide better/different lookup,
185
- # but extensions should call super and modify hash returned, to avoid
186
- # unintentionally erasing values provided by other extensions.
187
- def to_semantic_values
188
- unless @semantic_value_hash
189
- @semantic_value_hash = Hash.new([]) # default to empty array
190
- self.class.field_semantics.each_pair do |key, solr_field|
191
- value = self[solr_field]
192
- # Make single and multi-values all arrays, so clients
193
- # don't have to know.
194
- unless value.nil?
195
- value = [value] unless value.kind_of?(Array)
196
- @semantic_value_hash[key] = value
197
- end
54
+
55
+ # Returns a hash keyed by semantic tokens (see ExtendableClassMethods#semantic_fields), value is an array of
56
+ # strings. (Array to handle multi-value fields). If no value(s)
57
+ # available, empty array is returned.
58
+ #
59
+ # Default implementation here uses ExtendableClassMethods#semantic_fields
60
+ # to just take values from Solr stored fields.
61
+ # Extensions can over-ride this method to provide better/different lookup,
62
+ # but extensions should call super and modify hash returned, to avoid
63
+ # unintentionally erasing values provided by other extensions.
64
+ def to_semantic_values
65
+ unless @semantic_value_hash
66
+ @semantic_value_hash = Hash.new([]) # default to empty array
67
+ self.class.field_semantics.each_pair do |key, solr_field|
68
+ value = self[solr_field]
69
+ # Make single and multi-values all arrays, so clients
70
+ # don't have to know.
71
+ unless value.nil?
72
+ value = [value] unless value.kind_of?(Array)
73
+ @semantic_value_hash[key] = value
198
74
  end
199
75
  end
200
- return @semantic_value_hash
201
76
  end
77
+ return @semantic_value_hash
78
+ end
79
+
202
80
 
203
-
204
81
  # Certain class-level methods needed for the document-specific
205
82
  # extendability architecture
206
83
  module ClassMethods
207
- attr_writer :registered_extensions
208
84
 
209
85
  attr_writer :unique_key
210
86
  def unique_key
@@ -222,28 +98,7 @@ module Blacklight::Solr::Document
222
98
  # Returns array of hashes of registered extensions. Each hash
223
99
  # has a :module_obj key and a :condition_proc key. Usually this
224
100
  # method is only used internally in #apply_extensions, but if you
225
- # want to zero out all previously registered extensions you can call:
226
- # SolrDocument.registered_extensions = nil
227
- def registered_extensions
228
- @registered_extensions ||= []
229
- end
230
-
231
- def extension_parameters
232
- @extension_parameters ||= {}
233
- end
234
-
235
- # Register an extension module with the class. A block taking one
236
- # parameter can be supplied; the block will be passed an instance of
237
- # a Document, and the extension will be applied only if the block
238
- # evaluates as true. If no condition is given, the extension will
239
- # be applied to every instance of the class.
240
- #
241
- # SolrDocument.use_extension( SomeExtensionModule ) { | document | should_apply_some_extension?(document) }
242
- # SolrDocument.use_extension( SomeExtensionModule) # will be applied to all docs
243
- def use_extension( module_obj, &condition )
244
- registered_extensions << {:module_obj => module_obj, :condition_proc => condition}
245
- end
246
-
101
+
247
102
  # Class-level method for accessing/setting semantic mappings
248
103
  # for solr stored fields. Can be set by local app, key is
249
104
  # a symbol for a semantic, value is a solr _stored_ field.
@@ -0,0 +1,103 @@
1
+ # == Transformation conventions
2
+ # The main use case for extensions is for transforming a Document to another
3
+ # format. Either to another type of Ruby object, or to an exportable string in
4
+ # a certain format.
5
+ #
6
+ # The convention for methods contained in extensions that transform to a ruby
7
+ # object is "to_*". For instance, "to_marc" would return a Ruby Marc object.
8
+ #
9
+ # The convention for methods contained in extensions that transform to an
10
+ # exportable file of some kind is "export_as_*". For instance,
11
+ # "export_as_marc21" would return a String object containing valid marc21, and
12
+ # "export_as_marcxml" would return a String object containing valid marcxml.
13
+ #
14
+ # The tokens used after "export_as" should normally be the format names as
15
+ # registered with Rails Mime::Type.
16
+ #
17
+ # == Advertising export formats
18
+ #
19
+ # If an extension advertises what export formats it can provide, than those
20
+ # formats will automatically be delivered by the Blacklight catalog/show
21
+ # controller, and potentially automatically advertised in various places
22
+ # that advertise available formats. (HTML link rel=alternate; Atom
23
+ # link rel=alterate; etc).
24
+ #
25
+ # Export formats are 'registered' by calling the #will_export_as method
26
+ # on a Document instance. An extension would usually do this in a
27
+ # self.extended method, so it can be called on Documents that have
28
+ # the given extension added to them. For instance:
29
+ #
30
+ # module DemoMarcExtension
31
+ # def self.extended(document)
32
+ # document.will_export_as(:marc21, "application/marc")
33
+ # document.will_export_as(:marcxml, "application/marcxml+xml")
34
+ # end
35
+ #
36
+ # def export_as_marc21 ; something ; end
37
+ # def export_as_marcxml ; something ; end
38
+ # end
39
+ #
40
+ module Blacklight::Solr::Document::Export
41
+
42
+ ##
43
+ # Register exportable formats supported by the individual document.
44
+ # Usually called by an extension in it's self.extended method, to
45
+ # register the formats that extension can export.
46
+ #
47
+ # some_document.will_export_as(:some_format, "application/type") means
48
+ # that the document (usually via an extension) has a method
49
+ # "export_as_some_format" which returns a String of content that
50
+ # is described by the mime content_type given.
51
+ #
52
+ # The format name should ideally _already_ be registered with
53
+ # Rails Mime::Type, in your application initializer, representing
54
+ # the content type given. However, this method will attempt to
55
+ # register it using Mime::Type.register_alias if it's not previously
56
+ # registered. This is a bit sketchy though.
57
+ def will_export_as(short_name, content_type = nil)
58
+ #Lookup in Rails Mime::Type, register if needed, otherwise take
59
+ # content-type from registration if needed. This uses
60
+ # some 'api' to Mime::Type that may or may not be entirely
61
+ # public, the fact that a Mime::CONST is registered for every
62
+ # type. But that's the only way to do the kind of check we need, sorry.
63
+ if defined?(Mime) && Mime.const_defined?(short_name.to_s.upcase)
64
+ mime_type = "Mime::#{short_name.to_s.upcase}".constantize
65
+ content_type = mime_type.to_s unless content_type
66
+ else
67
+ # not registered, we need to register. Use register_alias to be least
68
+ # likely to interfere with host app.
69
+ Mime::Type.register_alias(content_type, short_name)
70
+ end
71
+
72
+ # if content_type is nil, look it up from Rails Mime::Type
73
+ if content_type.nil?
74
+ # Accurate lookup in Rails Mime::Type is kind of pain, it doesn't
75
+ # really provide the right API.
76
+ if defined?(type_const_name)
77
+ content_type = type_const_name.constantize.to_s
78
+ end
79
+ end
80
+ export_formats[short_name] = {:content_type => content_type}
81
+ end
82
+
83
+ # Collects formats that this doc can export as.
84
+ # Returns a hash, keys are format short-names that can
85
+ # be exported. Hash includes:
86
+ # :content-type => mime-content-type
87
+ # maybe more later
88
+ # To see if a given export format is supported by this document,
89
+ # simply call document.export_formats.keys.include?(:my_format)
90
+ # Then call #export_as! to do the export.
91
+ def export_formats
92
+ @export_formats ||= {}
93
+ end
94
+
95
+ # Call with a format shortname, export_as(:marc), simply returns
96
+ # #export_as_marc . Later we may expand the design to allow you
97
+ # to register an arbitrary method name instead of insisting
98
+ # on the convention, so clients should call this method so
99
+ # they'll still keep working if we do that.
100
+ def export_as(short_name)
101
+ send("export_as_#{short_name.to_s}")
102
+ end
103
+ end
@@ -0,0 +1,64 @@
1
+ # = Document Extensions
2
+ # An Blacklight::Solr::Document extension is simply a ruby module which is mixed
3
+ # in to individual Document instances. The intended use case is for documents
4
+ # containing some particular format of source material, such as Marc. An
5
+ # extension can be registered with your document class, along with a block
6
+ # containing custom logic for which documents to apply the extension to.
7
+ #
8
+ # SolrDocument.use_extension(MyExtension) {|document| my_logic_on_document(document}
9
+ #
10
+ # MyExtension will be mixed-in (using ruby 'extend') only to those documents
11
+ # where the block results in true.
12
+ #
13
+ # == Extension Parameters
14
+ # Every class that includes Blacklight::Solr::Document::Extensions gets a
15
+ # #extension_parameters method for saving arbitrary parameters on class-wide
16
+ # level that can be retrieved by extensions. These are arbitrary, just
17
+ # conventions with a given extension. For instance:
18
+ # SolrDocument.extension_parameters[:marc_source_field] = "solr_stored_field_name"
19
+ #
20
+ module Blacklight::Solr::Document::Extensions
21
+ extend ActiveSupport::Concern
22
+
23
+ included do
24
+ # after_initialize hook comes from RSolr::Ext::Model, I think.
25
+ # We need to make sure all extensions get applied.
26
+ after_initialize do
27
+ apply_extensions
28
+ end
29
+ end
30
+
31
+ # Needs to be called in initializer of class including this module, to
32
+ # apply all registered extensions on a per-document basis
33
+ def apply_extensions
34
+ self.class.registered_extensions.each do | registration|
35
+ self.extend( registration[:module_obj] ) if registration[:condition_proc].nil? || registration[:condition_proc].call( self )
36
+ end
37
+ end
38
+
39
+ module ClassMethods
40
+ attr_writer :registered_extensions
41
+
42
+ # want to zero out all previously registered extensions you can call:
43
+ # SolrDocument.registered_extensions = nil
44
+ def registered_extensions
45
+ @registered_extensions ||= []
46
+ end
47
+
48
+ def extension_parameters
49
+ @extension_parameters ||= {}
50
+ end
51
+
52
+ # Register an extension module with the class. A block taking one
53
+ # parameter can be supplied; the block will be passed an instance of
54
+ # a Document, and the extension will be applied only if the block
55
+ # evaluates as true. If no condition is given, the extension will
56
+ # be applied to every instance of the class.
57
+ #
58
+ # SolrDocument.use_extension( SomeExtensionModule ) { | document | should_apply_some_extension?(document) }
59
+ # SolrDocument.use_extension( SomeExtensionModule) # will be applied to all docs
60
+ def use_extension( module_obj, &condition )
61
+ registered_extensions << {:module_obj => module_obj, :condition_proc => condition}
62
+ end
63
+ end
64
+ end
@@ -317,6 +317,7 @@ module Blacklight::SolrHelper
317
317
 
318
318
  solr_response = find(blacklight_config.solr_request_handler, self.solr_search_params(user_params).merge(extra_controller_params))
319
319
  document_list = solr_response.docs.collect {|doc| SolrDocument.new(doc, solr_response)}
320
+ Rails.logger.debug("Solr response: #{solr_response.inspect}")
320
321
  Rails.logger.debug("Solr fetch: #{self.class}#get_search_results (#{'%.1f' % ((Time.now.to_f - bench_start.to_f)*1000)}ms)")
321
322
 
322
323
  return [solr_response, document_list]
@@ -30,6 +30,8 @@ then
30
30
  exit 1
31
31
  fi
32
32
 
33
+ if [[ $# -gt 0 ]]
34
+ then
33
35
  # Make certain rvn will work correctly.
34
36
  # Load RVM into a shell session *as a function*
35
37
  if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
@@ -46,6 +48,7 @@ fi
46
48
 
47
49
  rvm use "$@" --create
48
50
  check_errs $? "rvm failed. please run 'rvm install $@', and then re-run these tests."
51
+ fi
49
52
 
50
53
  cd tmp/test_app
51
54
  bundle exec rake blacklight:hudson
@@ -38,6 +38,9 @@ rm -rf tmp/test_app
38
38
  mkdir -p tmp/test_app
39
39
  cd tmp
40
40
 
41
+
42
+ if [[ $# -gt 0 ]]
43
+ then
41
44
  # Make certain rvm will work correctly.
42
45
  # Load RVM into a shell session *as a function*
43
46
  if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
@@ -47,12 +50,13 @@ elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
47
50
  # Then try to load from a root install
48
51
  source "/usr/local/rvm/scripts/rvm"
49
52
  else
50
- printf "ERROR: An RVM installation was not found.\n"
53
+ echo "WARNING: An RVM installation was not found.\n"
51
54
  exit 1
52
55
  fi
53
56
 
54
57
  rvm use "$@" --create
55
58
  check_errs $? "rvm failed. please run 'rvm install $@', and then re-run these tests."
59
+ fi
56
60
 
57
61
  if ! gem query -n rails -v "$RAILS_VERSION" --installed > /dev/null; then
58
62
  gem install --no-rdoc --no-ri 'rails' -v "$RAILS_VERSION"
@@ -62,7 +66,7 @@ if ! gem query -n bundler -v ">=1.0" --installed > /dev/null; then
62
66
  gem install --no-rdoc --no-ri 'bundler'
63
67
  fi
64
68
 
65
- rails new test_app
69
+ rails "_${RAILS_VERSION}_" new test_app
66
70
 
67
71
  cd test_app
68
72
  rm public/index.html
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0
4
+ version: 3.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
- date: 2012-06-25 00:00:00.000000000 Z
20
+ date: 2012-09-10 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -126,17 +126,17 @@ dependencies:
126
126
  requirement: !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
- - - ! '>='
129
+ - - ~>
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: '0.13'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  none: false
136
136
  requirements:
137
- - - ! '>='
137
+ - - ~>
138
138
  - !ruby/object:Gem::Version
139
- version: '0'
139
+ version: '0.13'
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: sass-rails
142
142
  requirement: !ruby/object:Gem::Requirement
@@ -304,6 +304,7 @@ files:
304
304
  - app/views/catalog/_constraints_element.html.erb
305
305
  - app/views/catalog/_did_you_mean.html.erb
306
306
  - app/views/catalog/_document.html.erb
307
+ - app/views/catalog/_document_header.html.erb
307
308
  - app/views/catalog/_document_list.html.erb
308
309
  - app/views/catalog/_email_form.html.erb
309
310
  - app/views/catalog/_facet_layout.html.erb
@@ -357,12 +358,8 @@ files:
357
358
  - app/views/saved_searches/index.html.erb
358
359
  - app/views/search_history/index.html.erb
359
360
  - blacklight.gemspec
360
- - config.ru
361
361
  - config/locales/blacklight.en.yml
362
362
  - config/routes.rb
363
- - db/seeds.rb
364
- - install.rb
365
- - install/solr.yml
366
363
  - lib/SolrMarc.jar
367
364
  - lib/blacklight.rb
368
365
  - lib/blacklight/catalog.rb
@@ -375,13 +372,14 @@ files:
375
372
  - lib/blacklight/controller.rb
376
373
  - lib/blacklight/engine.rb
377
374
  - lib/blacklight/exceptions.rb
378
- - lib/blacklight/kaminari_relevant_pages_patch.rb
379
375
  - lib/blacklight/routes.rb
380
376
  - lib/blacklight/search_fields.rb
381
377
  - lib/blacklight/solr.rb
382
378
  - lib/blacklight/solr/document.rb
383
379
  - lib/blacklight/solr/document/dublin_core.rb
384
380
  - lib/blacklight/solr/document/email.rb
381
+ - lib/blacklight/solr/document/export.rb
382
+ - lib/blacklight/solr/document/extensions.rb
385
383
  - lib/blacklight/solr/document/marc.rb
386
384
  - lib/blacklight/solr/document/marc_export.rb
387
385
  - lib/blacklight/solr/document/sms.rb
@@ -390,7 +388,6 @@ files:
390
388
  - lib/blacklight/user.rb
391
389
  - lib/blacklight/utils.rb
392
390
  - lib/blacklight/version.rb
393
- - lib/colorize.rb
394
391
  - lib/generators/blacklight/assets_generator.rb
395
392
  - lib/generators/blacklight/blacklight_generator.rb
396
393
  - lib/generators/blacklight/jetty_generator.rb
@@ -424,7 +421,6 @@ files:
424
421
  - lib/railties/blacklight_cucumber.rake
425
422
  - lib/railties/blacklight_rspec.rake
426
423
  - lib/railties/solr_marc.rake
427
- - tasks/blacklight_tasks.rake
428
424
  - test_support/.rspec
429
425
  - test_support/alternate_controller.rb
430
426
  - test_support/bin/run-tests.sh
@@ -501,7 +497,6 @@ files:
501
497
  - test_support/spec/views/catalog/_index_default.erb_spec.rb
502
498
  - test_support/spec/views/catalog/_show_default.erb_spec.rb
503
499
  - test_support/spec/views/catalog/index.atom.builder_spec.rb
504
- - uninstall.rb
505
500
  homepage: http://projectblacklight.org/
506
501
  licenses: []
507
502
  post_install_message:
@@ -516,7 +511,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
516
511
  version: '0'
517
512
  segments:
518
513
  - 0
519
- hash: -2302454488615889589
514
+ hash: -1064158987751751615
520
515
  required_rubygems_version: !ruby/object:Gem::Requirement
521
516
  none: false
522
517
  requirements:
@@ -525,7 +520,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
525
520
  version: '0'
526
521
  segments:
527
522
  - 0
528
- hash: -2302454488615889589
523
+ hash: -1064158987751751615
529
524
  requirements: []
530
525
  rubyforge_project: blacklight
531
526
  rubygems_version: 1.8.24
data/config.ru DELETED
@@ -1,4 +0,0 @@
1
- # This file is used by Rack-based servers to start the application.
2
-
3
- require ::File.expand_path('../config/environment', __FILE__)
4
- run BlacklightApp::Application
data/db/seeds.rb DELETED
@@ -1,8 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- # This file should contain all the record creation needed to seed the database with its default values.
3
- # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
4
- #
5
- # Examples:
6
- #
7
- # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
8
- # Mayor.create(:name => 'Daley', :city => cities.first)
data/install.rb DELETED
@@ -1 +0,0 @@
1
- # -*- encoding : utf-8 -*-
data/install/solr.yml DELETED
@@ -1,8 +0,0 @@
1
- production:
2
- url: http://127.0.0.1:8983/solr
3
- development:
4
- url: http://127.0.0.1:8983/solr
5
- test: &TEST
6
- url: http://127.0.0.1:8983/solr
7
- cucumber:
8
- <<: *TEST
@@ -1,40 +0,0 @@
1
- module Blacklight
2
- module KaminariRelevantPagesPatch
3
- module Windows
4
- def relevant_pages options
5
- [left_window(options), inside_window(options), right_window(options)].map(&:to_a).flatten.uniq.sort.reject { |x| x < 1 or x > options[:num_pages] }
6
- end
7
-
8
- def all_pages options
9
- 1.upto(options[:num_pages])
10
- end
11
-
12
- protected
13
- def left_window options
14
- 1.upto(options[:left] + 1)
15
- end
16
-
17
- def right_window options
18
- (options[:num_pages] - options[:right]).upto(options[:num_pages])
19
- end
20
-
21
- def inside_window options
22
- (options[:current_page] - options[:window]).upto(options[:current_page] + options[:window])
23
- end
24
- end
25
-
26
- include Windows
27
- def each_relevant_page
28
- return to_enum(:each_relevant_page) unless block_given?
29
-
30
- relevant_pages(@window_options.merge(@options)).each do |i|
31
- yield Kaminari::Helpers::Paginator::PageProxy.new(@window_options.merge(@options), i, @last)
32
- end
33
- end
34
- end
35
- end
36
-
37
- require 'kaminari'
38
- if Gem.loaded_specs['kaminari'].version <= Gem::Version.create('0.12.4')
39
- Kaminari::Helpers::Paginator.send(:include, Blacklight::KaminariRelevantPagesPatch)
40
- end
data/lib/colorize.rb DELETED
@@ -1,197 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- # == colorize
3
- # http://colorize.rubyforge.org
4
- # http://fazibear.prv.pl
5
- #
6
-
7
- #
8
- # Colorize String class extension.
9
- #
10
- class String
11
-
12
- #
13
- # Colors Hash
14
- #
15
- COLORS = {
16
- :black => 0,
17
- :red => 1,
18
- :green => 2,
19
- :yellow => 3,
20
- :blue => 4,
21
- :magenta => 5,
22
- :cyan => 6,
23
- :white => 7,
24
- :default => 9,
25
-
26
- :light_black => 10,
27
- :light_red => 11,
28
- :light_green => 12,
29
- :light_yellow => 13,
30
- :light_blue => 14,
31
- :light_magenta => 15,
32
- :light_cyan => 16,
33
- :light_white => 17
34
- }
35
-
36
- #
37
- # Modes Hash
38
- #
39
- MODES = {
40
- :default => 0, # Turn off all attributes
41
- #:bright => 1, # Set bright mode
42
- :underline => 4, # Set underline mode
43
- :blink => 5, # Set blink mode
44
- :swap => 7, # Exchange foreground and background colors
45
- :hide => 8 # Hide text (foreground color would be the same as background)
46
- }
47
-
48
- protected
49
-
50
- #
51
- # Set color values in new string intance
52
- #
53
- def set_color_parameters( params )
54
- if (params.instance_of?(Hash))
55
- @color = params[:color]
56
- @background = params[:background]
57
- @mode = params[:mode]
58
- @uncolorized = params[:uncolorized]
59
- self
60
- else
61
- nil
62
- end
63
- end
64
-
65
- public
66
-
67
- #
68
- # Change color of string
69
- #
70
- # Examples:
71
- #
72
- # puts "This is blue".colorize( :blue )
73
- # puts "This is light blue".colorize( :light_blue )
74
- # puts "This is also blue".colorize( :color => :blue )
75
- # puts "This is light blue with red background".colorize( :color => :light_blue, :background => :red )
76
- # puts "This is light blue with red background".colorize( :light_blue ).colorize( :background => :red )
77
- # puts "This is blue text on red".blue.on_red
78
- # puts "This is red on blue".colorize( :red ).on_blue
79
- # puts "This is red on blue and underline".colorize( :red ).on_blue.underline
80
- # puts "This is blue text on red".blue.on_red.blink
81
- # puts "This is uncolorized".blue.on_red.uncolorize
82
- #
83
- def colorize( params )
84
- return self unless STDOUT.isatty
85
-
86
- begin
87
- require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/
88
- rescue LoadError
89
- raise 'You must gem install win32console to use colorize on Windows'
90
- end
91
-
92
- color_parameters = {}
93
-
94
- if (params.instance_of?(Hash))
95
- color_parameters[:color] = COLORS[params[:color]]
96
- color_parameters[:background] = COLORS[params[:background]]
97
- color_parameters[:mode] = MODES[params[:mode]]
98
- elsif (params.instance_of?(Symbol))
99
- color_parameters[:color] = COLORS[params]
100
- end
101
-
102
- color_parameters[:color] ||= @color ||= COLORS[:default]
103
- color_parameters[:background] ||= @background ||= COLORS[:default]
104
- color_parameters[:mode] ||= @mode ||= MODES[:default]
105
-
106
- color_parameters[:uncolorized] ||= @uncolorized ||= self.dup
107
-
108
- # calculate bright mode
109
- color_parameters[:color] += 50 if color_parameters[:color] > 10
110
-
111
- color_parameters[:background] += 50 if color_parameters[:background] > 10
112
-
113
- "\033[#{color_parameters[:mode]};#{color_parameters[:color]+30};#{color_parameters[:background]+40}m#{color_parameters[:uncolorized]}\033[0m".set_color_parameters( color_parameters )
114
- end
115
-
116
- #
117
- # Return uncolorized string
118
- #
119
- def uncolorize
120
- @uncolorized || self
121
- end
122
-
123
- #
124
- # Return true if sting is colorized
125
- #
126
- def colorized?
127
- !defined?(@uncolorized).nil?
128
- end
129
-
130
- #
131
- # Make some color and on_color methods
132
- #
133
- COLORS.each_key do | key |
134
- next if key == :default
135
-
136
- define_method key do
137
- self.colorize( :color => key )
138
- end
139
-
140
- define_method "on_#{key}" do
141
- self.colorize( :background => key )
142
- end
143
- end
144
-
145
- #
146
- # Methods for modes
147
- #
148
- MODES.each_key do | key |
149
- next if key == :default
150
-
151
- define_method key do
152
- self.colorize( :mode => key )
153
- end
154
- end
155
-
156
- class << self
157
-
158
- #
159
- # Return array of available modes used by colorize method
160
- #
161
- def modes
162
- keys = []
163
- MODES.each_key do | key |
164
- keys << key
165
- end
166
- keys
167
- end
168
-
169
- #
170
- # Return array of available colors used by colorize method
171
- #
172
- def colors
173
- keys = []
174
- COLORS.each_key do | key |
175
- keys << key
176
- end
177
- keys
178
- end
179
-
180
- #
181
- # Display color matrix with color names.
182
- #
183
- def color_matrix( txt = "[X]" )
184
- size = String.colors.length
185
- String.colors.each do | color |
186
- String.colors.each do | back |
187
- print txt.colorize( :color => color, :background => back )
188
- end
189
- puts " < #{color}"
190
- end
191
- String.colors.reverse.each_with_index do | back, index |
192
- puts "#{"|".rjust(txt.length)*(size-index)} < #{back}"
193
- end
194
- ""
195
- end
196
- end
197
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :blacklight do
3
- # # Task goes here
4
- # end
data/uninstall.rb DELETED
@@ -1,2 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- # Uninstall hook code here