blacklight 3.1.2 → 3.2.0pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/.gitignore +5 -2
  2. data/README.md +7 -2
  3. data/VERSION +1 -1
  4. data/app/assets/images/favicon.ico +0 -0
  5. data/app/assets/javascripts/blacklight/blacklight.js +23 -1
  6. data/app/assets/stylesheets/blacklight/_catalog.css.scss +369 -0
  7. data/app/assets/stylesheets/blacklight/_facets.css.scss +117 -0
  8. data/app/assets/stylesheets/blacklight/_folder.css.scss +38 -0
  9. data/app/assets/stylesheets/blacklight/_formatting.css.scss +164 -0
  10. data/app/assets/stylesheets/blacklight/_header.css.scss +36 -0
  11. data/app/assets/stylesheets/blacklight/_layout.css.scss +79 -0
  12. data/app/assets/stylesheets/blacklight/_print.css.scss +54 -0
  13. data/app/assets/stylesheets/blacklight/_search_history.css.scss +44 -0
  14. data/app/assets/stylesheets/blacklight/_susy_framework.css.scss +228 -0
  15. data/app/assets/stylesheets/blacklight/blacklight.css.scss +27 -0
  16. data/app/assets/stylesheets/blacklight/blacklight_defaults.css.scss +48 -0
  17. data/app/controllers/bookmarks_controller.rb +2 -1
  18. data/app/controllers/folder_controller.rb +4 -0
  19. data/app/controllers/saved_searches_controller.rb +4 -0
  20. data/app/controllers/search_history_controller.rb +4 -0
  21. data/app/helpers/blacklight/blacklight_helper_behavior.rb +64 -104
  22. data/app/helpers/blacklight/catalog_helper_behavior.rb +4 -4
  23. data/app/helpers/blacklight/facets_helper_behavior.rb +52 -5
  24. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +14 -59
  25. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +56 -0
  26. data/app/helpers/search_history_constraints_helper.rb +3 -0
  27. data/app/models/record_mailer.rb +1 -2
  28. data/app/views/_flash_msg.html.erb +4 -5
  29. data/app/views/_user_util_links.html.erb +3 -1
  30. data/app/views/bookmarks/index.html.erb +2 -2
  31. data/app/views/catalog/_bookmark_control.html.erb +6 -6
  32. data/app/views/catalog/_facet_layout.html.erb +4 -0
  33. data/app/views/catalog/_facet_limit.html.erb +20 -33
  34. data/app/views/catalog/_facets.html.erb +1 -5
  35. data/app/views/catalog/_folder_control.html.erb +5 -5
  36. data/app/views/catalog/_index_default.html.erb +1 -1
  37. data/app/views/catalog/_search_form.html.erb +4 -3
  38. data/app/views/catalog/_show_default.html.erb +1 -1
  39. data/app/views/catalog/_show_tools.html.erb +6 -6
  40. data/app/views/catalog/_sort_and_per_page.html.erb +1 -1
  41. data/app/views/catalog/index.atom.builder +2 -2
  42. data/app/views/catalog/index.rss.builder +1 -1
  43. data/app/views/catalog/opensearch.xml.builder +10 -0
  44. data/app/views/catalog/show.html.erb +1 -1
  45. data/app/views/folder/_tools.html.erb +4 -4
  46. data/app/views/layouts/blacklight.html.erb +25 -37
  47. data/app/views/record_mailer/email_record.text.erb +1 -1
  48. data/app/views/record_mailer/sms_record.text.erb +2 -2
  49. data/app/views/search_history/index.html.erb +1 -1
  50. data/blacklight.gemspec +11 -9
  51. data/lib/{generators/blacklight/templates/SolrMarc.jar → SolrMarc.jar} +0 -0
  52. data/lib/blacklight.rb +5 -3
  53. data/lib/blacklight/catalog.rb +3 -4
  54. data/lib/blacklight/configurable.rb +54 -39
  55. data/lib/blacklight/configuration.rb +126 -0
  56. data/lib/blacklight/configuration/fields.rb +142 -0
  57. data/lib/blacklight/configuration/search_field.rb +12 -0
  58. data/lib/blacklight/configuration/solr_field.rb +12 -0
  59. data/lib/blacklight/configuration/sort_field.rb +17 -0
  60. data/lib/blacklight/controller.rb +16 -14
  61. data/lib/blacklight/engine.rb +1 -1
  62. data/lib/blacklight/global_configurable.rb +46 -0
  63. data/lib/blacklight/search_fields.rb +21 -54
  64. data/lib/blacklight/solr/document.rb +13 -3
  65. data/lib/blacklight/solr_helper.rb +88 -52
  66. data/lib/blacklight/utils.rb +18 -0
  67. data/lib/generators/blacklight/assets_generator.rb +14 -20
  68. data/lib/generators/blacklight/blacklight_generator.rb +14 -6
  69. data/lib/generators/blacklight/jetty_generator.rb +1 -1
  70. data/lib/generators/blacklight/templates/assets/standard.css.scss +51 -0
  71. data/lib/generators/blacklight/templates/catalog_controller.rb +148 -0
  72. data/lib/generators/blacklight/templates/config/blacklight_config.rb +2 -239
  73. data/lib/generators/blacklight/templates/config/sass.rb +5 -0
  74. data/lib/generators/blacklight/templates/solr_conf/schema.xml +514 -164
  75. data/lib/generators/blacklight/templates/solr_conf/solrconfig.xml +1591 -323
  76. data/lib/generators/blacklight/templates/solr_document.rb +2 -0
  77. data/lib/railties/all_tests.rake +36 -3
  78. data/lib/railties/blacklight_cucumber.rake +6 -4
  79. data/lib/railties/blacklight_rspec.rake +5 -4
  80. data/test_support/bin/run-tests.sh +2 -13
  81. data/test_support/bin/test.sh +30 -23
  82. data/test_support/features/did_you_mean.feature +14 -13
  83. data/test_support/features/step_definitions/saved_searches_steps.rb +1 -1
  84. data/test_support/features/step_definitions/search_steps.rb +4 -4
  85. data/test_support/spec/controllers/application_controller_spec.rb +3 -13
  86. data/test_support/spec/controllers/catalog_controller_spec.rb +102 -24
  87. data/test_support/spec/controllers/folder_controller_spec.rb +7 -1
  88. data/test_support/spec/helpers/blacklight_helper_spec.rb +45 -34
  89. data/test_support/spec/helpers/facets_helper_spec.rb +68 -0
  90. data/test_support/spec/helpers/html_head_helper_spec.rb +37 -0
  91. data/test_support/spec/helpers/{render_constraints_helper_spec.rb → search_history_constraints_helper_spec.rb} +26 -7
  92. data/test_support/spec/lib/blacklight_configurable_spec.rb +92 -0
  93. data/test_support/spec/lib/blacklight_configuration_spec.rb +295 -0
  94. data/test_support/spec/lib/{configurable_spec.rb → global_configurable_spec.rb} +2 -2
  95. data/test_support/spec/lib/search_fields_spec.rb +26 -29
  96. data/test_support/spec/{helpers → lib}/solr_helper_spec.rb +268 -287
  97. data/test_support/spec/lib/tasks/solr_marc_task_spec.rb +1 -1
  98. data/test_support/spec/lib/utils_spec.rb +58 -0
  99. data/test_support/spec/models/solr_docment_spec.rb +4 -8
  100. data/test_support/spec/views/catalog/_facets.html.erb_spec.rb +27 -170
  101. data/test_support/spec/views/catalog/_index_default.erb_spec.rb +38 -20
  102. data/test_support/spec/views/catalog/_show_default.erb_spec.rb +38 -19
  103. data/test_support/spec/views/catalog/index.atom.builder_spec.rb +19 -1
  104. metadata +148 -145
  105. data/app/assets/stylesheets/blacklight/blacklight.css +0 -493
  106. data/app/assets/stylesheets/yui.css +0 -31
  107. data/app/views/catalog/opensearch.xml.erb +0 -11
  108. data/doc/Atom-Responses.md +0 -90
  109. data/doc/CUSTOMIZING.md +0 -121
  110. data/doc/Extending-blacklight-with-the-document-extension-framework.md +0 -1
  111. data/doc/Extending-or-Modifying-Blacklight-Search-Behavior.md +0 -131
  112. data/doc/Features.md +0 -147
  113. data/doc/Integration-with-Rails-Footnotes.md +0 -20
  114. data/doc/Pagination.md +0 -38
  115. data/doc/Quickstart.md +0 -97
  116. data/doc/Upgrading-Guide.md +0 -98
  117. data/doc/User-Authentication.md +0 -54
  118. data/doc/Using-a-custom-solr-uniquekey-field.md +0 -36
  119. data/lib/blacklight/comma_link_renderer.rb +0 -28
  120. data/lib/railties/jetty_solr_server.rb +0 -108
  121. data/test_support/spec/views/catalog/show.html.erb_spec.rb +0 -101
@@ -0,0 +1,142 @@
1
+ module Blacklight
2
+ class Configuration
3
+
4
+ # This mixin provides Blacklight::Configuration with generic
5
+ # solr fields configuration
6
+ module Fields
7
+ extend ActiveSupport::Concern
8
+
9
+ module ClassMethods
10
+
11
+ # Add a configuration block for a collection of solr fields
12
+ def define_field_access(key)
13
+ key = key.to_s if respond_to? :to_s
14
+
15
+ self.default_values[key.pluralize.to_sym] = ActiveSupport::OrderedHash.new
16
+
17
+ unless self.const_defined? key.camelcase
18
+ class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
19
+ class #{key.camelcase} < SolrField; end
20
+ END_EVAL
21
+ end
22
+
23
+ class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
24
+ def add_#{key}(*args, &block)
25
+ add_solr_field("#{key}", *args, &block)
26
+ end
27
+ END_EVAL
28
+ end
29
+ end
30
+
31
+ module InstanceMethods
32
+ # Add a solr field configuration to the given configuration key
33
+ #
34
+ # The recommended and strongly encouraged format is a field name, configuration pair, e.g.:
35
+ # add_solr_field :index_field, 'format', :label => 'Format'
36
+ #
37
+ # Alternative formats include:
38
+ #
39
+ # * a field name and block format:
40
+ #
41
+ # add_solr_field :index_field, 'format' do |field|
42
+ # field.label = 'Format'
43
+ # end
44
+ #
45
+ # * a plain block:
46
+ #
47
+ # add_solr_field :index_field do |field|
48
+ # field.field = 'format'
49
+ # field.label = 'Format'
50
+ # end
51
+ #
52
+ # * a configuration hash:
53
+ #
54
+ # add_solr_field :index_field, :field => 'format', :label => 'Format'
55
+ #
56
+ # * a Field instance:
57
+ #
58
+ # add_solr_field :index_field, IndexField.new(:field => 'format', :label => 'Format')
59
+ #
60
+ # * an array of hashes:
61
+ #
62
+ # add_solr_field :index_field, [{:field => 'format', :label => 'Format'}, IndexField.new(:field => 'date', :label => 'Date')]
63
+ #
64
+ #
65
+ # @param String config_key
66
+ # @param Array *args
67
+ # @para
68
+ #
69
+ def add_solr_field config_key, *args, &block
70
+ field_config = case args.first
71
+ when String
72
+ field_config_from_key_and_hash(config_key, *args)
73
+ when Symbol
74
+ args.first = args.first.to_s
75
+ field_config_from_key_and_hash(config_key, *args)
76
+ when Array
77
+ field_config_from_array(config_key, *args)
78
+ else
79
+ field_config_from_field_or_hash(config_key, *args)
80
+ end
81
+
82
+ return if field_config.is_a? Array
83
+
84
+ if block_given?
85
+ yield field_config
86
+ end
87
+
88
+ field_config.normalize!(self)
89
+ field_config.validate!
90
+
91
+ self[config_key.pluralize][ field_config.field ] = field_config
92
+ end
93
+
94
+ protected
95
+ # Add a solr field by a solr field name and hash
96
+ def field_config_from_key_and_hash config_key, solr_field, field_or_hash = {}
97
+ field_config = field_config_from_field_or_hash(config_key, field_or_hash)
98
+ field_config.field = solr_field
99
+
100
+ field_config
101
+ end
102
+
103
+ # Add multiple solr fields using a hash or Field instance
104
+ def field_config_from_array config_key, array_of_fields_or_hashes
105
+ array_of_fields_or_hashes.map do |field_or_hash|
106
+ add_solr_field(config_key, field_or_hash)
107
+ end
108
+ end
109
+
110
+ # Add a solr field using a hash or Field instance
111
+ def field_config_from_field_or_hash config_key, field_or_hash = {}
112
+ hash_arg_to_config(field_or_hash, field_class_from_key(config_key))
113
+ end
114
+
115
+ # for our add_* methods, takes the optional hash param,
116
+ # and makes it into a specific config OpenStruct, like
117
+ # FacetField or SearchField. Or if the param already was
118
+ # one, that's cool. Or if the param is nil, make
119
+ # an empty one. Second argument is an actual class object.
120
+ def hash_arg_to_config(hash_arg, klass)
121
+ case hash_arg
122
+ when Hash
123
+ klass.new(hash_arg)
124
+ when NilClass
125
+ klass.new
126
+ else
127
+ # this assumes it already is an element of klass, or acts like one,
128
+ # if not something bad will happen later, that's your problem.
129
+ hash_arg
130
+ end
131
+ end
132
+
133
+ private
134
+ # convert a config key to the appropriate Field class
135
+ def field_class_from_key key
136
+ "Blacklight::Configuration::#{key.camelcase}".constantize
137
+ end
138
+
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,12 @@
1
+ module Blacklight
2
+ class Configuration::SearchField < Configuration::SolrField
3
+ def normalize! blacklight_config
4
+ # Some normalization, calculate display_label from key,
5
+ # and make sure we have a qt from defaults.
6
+ self.key = self.field
7
+ self.label ||= self.key.try(:titlecase)
8
+ self.qt ||= blacklight_config.default_solr_params[:qt] if blacklight_config.default_solr_params
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,12 @@
1
+ module Blacklight
2
+ class Configuration::SolrField < OpenStructWithHashAccess
3
+ def normalize! blacklight_config
4
+ self.label ||= self.field.try(:titleize)
5
+ end
6
+
7
+ def validate!
8
+ raise ArgumentError.new("Must supply a solr field name") if self.field.nil?
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,17 @@
1
+ module Blacklight
2
+ class Configuration::SortField < Configuration::SolrField
3
+ def normalize! blacklight_config
4
+ self.sort ||= self.field
5
+
6
+ self.field ||= self.key
7
+ self.field ||= self.label.try(:parameterize)
8
+ self.field ||= self.sort
9
+
10
+ self.key ||= self.field
11
+ end
12
+
13
+ def validate!
14
+ raise ArgumentError.new("Must supply a solr sort string") if self.sort.nil?
15
+ end
16
+ end
17
+ end
@@ -5,6 +5,8 @@
5
5
  module Blacklight::Controller
6
6
 
7
7
  def self.included(base)
8
+ base.send :include, Blacklight::SearchFields
9
+
8
10
  base.send :before_filter, :default_html_head # add JS/stylesheet stuff
9
11
  # now in application.rb file under config.filter_parameters
10
12
  # filter_parameter_logging :password, :password_confirmation
@@ -22,9 +24,9 @@ module Blacklight::Controller
22
24
  base.send :helper_method, :extra_head_content
23
25
  base.send :helper_method, :stylesheet_links
24
26
  base.send :helper_method, :javascript_includes
27
+ base.send :helper_method, :has_user_authentication_provider?
25
28
  end
26
29
 
27
-
28
30
  # test for exception notifier plugin
29
31
  def error
30
32
  raise RuntimeError, "Generating a test error..."
@@ -40,14 +42,7 @@ module Blacklight::Controller
40
42
  # http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
41
43
  # for how to turn off a filter in a sub-class and such.
42
44
  def default_html_head
43
- if use_asset_pipeline?
44
- stylesheet_links << ["application"]
45
- javascript_includes << ["application"]
46
- else
47
- stylesheet_links << ['yui', 'jquery/ui-lightness/jquery-ui-1.8.1.custom.css', 'blacklight/blacklight', {:media=>'all'}]
48
-
49
- javascript_includes << ['jquery-1.4.2.min.js', 'jquery-ui-1.8.1.custom.min.js', 'blacklight/blacklight' ]
50
- end
45
+
51
46
  end
52
47
 
53
48
 
@@ -117,6 +112,16 @@ module Blacklight::Controller
117
112
  flash.discard if request.xhr?
118
113
  end
119
114
 
115
+ ##
116
+ #
117
+ #
118
+ def has_user_authentication_provider?
119
+ respond_to? :current_user
120
+ end
121
+
122
+ def require_user_authentication_provider
123
+ raise ActionController::RoutingError.new('Not Found') unless has_user_authentication_provider?
124
+ end
120
125
  ##
121
126
  # To handle failed authorization attempts, redirect the user to the
122
127
  # login form and persist the current request uri as a parameter
@@ -126,13 +131,10 @@ module Blacklight::Controller
126
131
  # (e.g. protected page -> logout -> returned to protected page -> home)
127
132
  redirect_to root_url and flash.discard and return if request.referer and request.referer.ends_with? request.fullpath
128
133
 
134
+ redirect_to root_url and return unless has_user_authentication_provider?
135
+
129
136
  redirect_to new_user_session_url(:referer => request.fullpath)
130
137
  end
131
138
 
132
- private
133
- # Detect if the Rails asset pipeline is enabled
134
- def use_asset_pipeline?
135
- Rails.application.config.respond_to?(:assets) and Rails.application.config.assets.enabled
136
- end
137
139
  end
138
140
 
@@ -3,7 +3,7 @@
3
3
  require "blacklight"
4
4
  require "rails"
5
5
 
6
- module Blackight
6
+ module Blacklight
7
7
  class Engine < Rails::Engine
8
8
 
9
9
  # BlacklightHelper is needed by all helpers, so we inject it
@@ -0,0 +1,46 @@
1
+ module Blacklight::GlobalConfigurable
2
+
3
+ # The config environment name used by the #config method
4
+ #
5
+ # Example:
6
+ # class MyThing
7
+ # extend Blacklight::GlobalConfigurable
8
+ # end
9
+ #
10
+ # Now MyThing.config will be the result of:
11
+ # MyThing.configure(:production) {|config|}
12
+ #
13
+ # You set shared attributes by leaving the first argument blank or passing the :shared value:
14
+ # MyThing.configure {|config|}
15
+ # or
16
+ # MyThing.cofigure(:shared) {|config|}
17
+
18
+ # sets the @configs variable to a new Hash with empty Hash for :shared key and @config to nil
19
+ def reset_configs!
20
+ @config = nil
21
+ @configs = {:shared=>{}}
22
+ end
23
+
24
+ # A hash of all environment configs
25
+ # The key is the environment name, the value a Hash
26
+ def configs
27
+ @configs ? @configs : (reset_configs! and @configs)
28
+ end
29
+
30
+ # The main config accessor. It merges the current configs[::Rails.env]
31
+ # with configs[:shared] and lazy-loads @config to the result.
32
+ def config
33
+ @config ||= configs[:shared].merge(configs[::Rails.env] ||= {})
34
+ end
35
+ alias_method :blacklight_config, :config
36
+
37
+ # Accepts a value for the environment to configure and a block
38
+ # A hash is yielded to the block
39
+ # If the "env" != :shared,
40
+ # the hash is created by deep cloning the :shared environment config.
41
+ # This makes it possible to create defaults in the :shared config
42
+ def configure(env = :shared, &blk)
43
+ configs[env] = {}
44
+ yield configs[env]
45
+ end
46
+ end
@@ -2,16 +2,16 @@
2
2
  ##
3
3
  # Module to deal with accessing (and setting some defaults) in an array of
4
4
  # hashes that describe Blacklight search fields. Requires the base class this
5
- # module is added to implements a #config method that returns a hash, where
6
- # config[:search_fields] will be an array of hashes describing search fields.
5
+ # module is added to implements a #blacklight_config method that returns a hash, where
6
+ # blacklight_config[:search_fields] will be an array of hashes describing search fields.
7
7
  #
8
- # = Search Field Configuration Hash =
8
+ # = Search Field blacklight_configuration Hash =
9
9
  # [:key]
10
10
  # "title", required, unique key used in search URLs to specify search_field
11
- # [:display_label]
11
+ # [:label]
12
12
  # "Title", # user-displayable label, optional, if not supplied :key.titlecase will be used
13
13
  # [:qt]
14
- # "search", # Solr qt param, request handler, usually can be left blank; defaults to Blacklight.config[:default_solr_params][:qt] if not specified.
14
+ # "search", # Solr qt param, request handler, usually can be left blank; defaults to blacklight_config[:default_solr_params][:qt] if not specified.
15
15
  # [:solr_parameters]
16
16
  # {:qf => "something"} # optional hash of additional parameters to pass to solr for searches on this field.
17
17
  # [:solr_local_parameters]
@@ -21,88 +21,55 @@
21
21
  #
22
22
  # Optionally you can supply a :key, which is what Blacklight will use
23
23
  # to identify this search field in HTTP query params. If no :key is
24
- # supplied, one will be computed from the :display_label. If that will
24
+ # supplied, one will be computed from the :label. If that will
25
25
  # result in a collision of keys, you should supply one explicitly.
26
26
  #
27
27
  ##
28
28
  module Blacklight::SearchFields
29
29
  extend ActiveSupport::Memoizable
30
+ extend ActiveSupport::Concern
30
31
 
31
- # Looks up search field config list from config[:search_fields], and
32
+ included do
33
+ helper Blacklight::SearchFields if respond_to? :helper
34
+ end
35
+
36
+ # Looks up search field config list from blacklight_config[:search_fields], and
32
37
  # 'normalizes' all field config hashes using normalize_config method.
33
38
  # Memoized for efficiency of normalization.
34
39
  def search_field_list
35
- normalized = config[:search_fields].collect {|obj| normalize_config(obj)}
36
-
37
- if (duplicates = normalized.collect{|h| h[:key]}.uniq!)
38
- raise "Duplicate keys found in search_field config: #{duplicates.inspect}"
39
- end
40
-
41
- normalized
40
+ blacklight_config.search_fields.values
42
41
  end
43
- memoize :search_field_list
44
42
 
45
43
  # Returns suitable argument to options_for_select method, to create
46
44
  # an html select based on #search_field_list. Skips search_fields
47
45
  # marked :include_in_simple_select => false
48
46
  def search_field_options_for_select
49
- search_field_list.collect do |field_def|
50
- [field_def[:display_label], field_def[:key]] unless field_def[:include_in_simple_select] == false
47
+ blacklight_config.search_fields.collect do |key, field_def|
48
+ [field_def.label, field_def.key] unless field_def.include_in_simple_select == false
51
49
  end.compact
52
50
  end
53
51
 
54
- # Looks up a search field config hash from search_field_list having
52
+ # Looks up a search field blacklight_config hash from search_field_list having
55
53
  # a certain supplied :key.
56
54
  def search_field_def_for_key(key)
57
- return nil if key.blank?
58
- search_field_list.find {|c| c[:key] == key}
55
+ blacklight_config.search_fields[key]
59
56
  end
60
57
 
61
58
  # Returns default search field, used for simpler display in history, etc.
62
- # if not set in config, defaults to first field listed in #search_field_list
59
+ # if not set in blacklight_config, defaults to first field listed in #search_field_list
63
60
  def default_search_field
64
- config[:default_search_field] || search_field_list[0]
61
+ blacklight_config.default_search_field || search_field_list.first
65
62
  end
66
- memoize :default_search_field
67
63
 
68
64
  # Shortcut for commonly needed operation, look up display
69
65
  # label for the key specified. Returns "Keyword" if a label
70
66
  # can't be found.
71
67
  def label_for_search_field(key)
72
68
  field_def = search_field_def_for_key(key)
73
- if field_def && field_def[:display_label]
74
- field_def[:display_label]
69
+ if field_def && field_def.label
70
+ field_def.label
75
71
  else
76
72
  "Keyword"
77
73
  end
78
74
  end
79
-
80
- protected
81
- # Fill in missing default values in a search_field config hash.
82
- def normalize_config(field_hash)
83
-
84
-
85
- # Accept legacy two-element array, if it's not a Hash, assume it's legacy.
86
- # No great way to 'duck type' here.
87
- unless ( field_hash.kind_of?(Hash))
88
- # Consistent with legacy behavior where two fields can have the same label,
89
- # as long as they have different qt's, we base the unique :key on :qt.
90
- field_hash = {:display_label => field_hash[0], :key => field_hash[1], :qt => field_hash[1]}
91
- else
92
- # Make a copy of passed in Hash so we don't alter original.
93
- field_hash = field_hash.clone
94
- end
95
-
96
- raise Exception.new("Search field config is missing ':key' => #{field_hash.inspect}") unless field_hash[:key]
97
-
98
- # If no display_label was provided, turn the :key into one.
99
- field_hash[:display_label] ||= field_hash[:key].titlecase
100
-
101
- # If no :qt was provided, take from config default
102
- field_hash[:qt] ||= config[:default_solr_params][:qt] if config[:default_solr_params]
103
-
104
- field_hash
105
- end
106
-
107
-
108
75
  end
@@ -85,6 +85,7 @@ module Blacklight::Solr::Document
85
85
  base.send :include, RSolr::Ext::Model
86
86
  base.send :include, InstanceMethods
87
87
  base.send :extend, ClassMethods
88
+ base.send :extend, ActiveModel::Naming
88
89
 
89
90
  # after_initialize hook comes from RSolr::Ext::Model, I think.
90
91
  # We need to make sure all extensions get applied.
@@ -97,6 +98,10 @@ module Blacklight::Solr::Document
97
98
  def id
98
99
  self[self.class.unique_key]
99
100
  end
101
+
102
+ def to_param
103
+ URI.escape(CGI.escape(id), '.')
104
+ end
100
105
  end
101
106
 
102
107
 
@@ -201,9 +206,14 @@ module Blacklight::Solr::Document
201
206
  module ClassMethods
202
207
  attr_writer :registered_extensions
203
208
 
204
- def unique_key
205
- Blacklight.config[:unique_key] || 'id'
206
- end
209
+ attr_writer :unique_key
210
+ def unique_key
211
+ # XXX Blacklight.config[:unique_key] should be deprecated soon
212
+ @unique_key ||= Blacklight.config[:unique_key] if Blacklight.respond_to?(:config) and Blacklight.config[:unique_key]
213
+ @unique_key ||= 'id'
214
+
215
+ @unique_key
216
+ end
207
217
 
208
218
  def connection
209
219
  @connection ||= Blacklight.solr