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,10 @@
1
+ xml.instruct! :xml, :version=>'1.0'
2
+ xml.OpenSearchDescription(:xmlns=>'http://a9.com/-/spec/opensearch/1.1/') {
3
+ xml.ShortName application_name
4
+ xml.Description "#{application_name} Search"
5
+ xml.Image "#{asset_url('favicon.ico')}", :height=>16, :width=>16, :type=>'image/x-icon'
6
+ xml.Contact
7
+ xml.Url :type=>'text/html', :method=>'get', :template=>"#{url_for :controller=>'catalog', :only_path => false}?q={searchTerms}"
8
+ xml.Url :type=>'application/rss+xml', :method=>'get', :template=>"#{url_for :controller=>'catalog', :only_path => false}.rss?q={searchTerms}"
9
+ xml.Url :type=>'application/x-suggestions+json', :method=>'get', :template=>"#{url_for :controller=>'catalog',:action => 'opensearch', :format=> 'json', :only_path => false}?q={searchTerms}"
10
+ }
@@ -15,7 +15,7 @@
15
15
 
16
16
  <%# this should be in a partial -%>
17
17
  <div id="document" class="<%= render_document_class %>">
18
- <div id="doc_<%= @document[:id] %>">
18
+ <div id="doc_<%= @document.id.to_s.parameterize %>">
19
19
 
20
20
  <% # bookmark/folder functions -%>
21
21
  <%= render_show_doc_actions @document %>
@@ -1,17 +1,17 @@
1
1
  <ul class="folderTools">
2
2
  <li class="cite">
3
- <%= link_to "Cite", citation_catalog_path(:id => @documents.collect{|doc| doc.get(:id)}), {:id => 'citeLink', :name => 'citation'} %>
3
+ <%= link_to "Cite", citation_catalog_path(:id => @documents.collect{|doc| doc.id}), {:id => 'citeLink', :name => 'citation'} %>
4
4
  </li>
5
5
  <li class="refworks">
6
6
  <%= render :partial => 'catalog/refworks_form', :locals => {:documents=>@documents} %>
7
7
  </li>
8
8
  <li class="endnote">
9
- <%= link_to "Export to EndNote", endnote_catalog_path(:id => @documents.collect {|doc| doc.get(:id)}, :format => 'endnote')%>
9
+ <%= link_to "Export to EndNote", endnote_catalog_path(:id => @documents.collect {|doc| doc.id}, :format => 'endnote')%>
10
10
  </li>
11
11
  <li class="email">
12
- <%= link_to "Email", email_catalog_path(:id => @documents.collect {|doc| doc.get(:id)}), :class=>"lightboxLink", :id => "emailLink" %>
12
+ <%= link_to "Email", email_catalog_path(:id => @documents.collect {|doc| doc.id}), :class=>"lightboxLink", :id => "emailLink" %>
13
13
  </li>
14
- <% if current_user %>
14
+ <% if has_user_authentication_provider? and current_user %>
15
15
  <li>
16
16
  <%= render :partial=>'catalog/bookmark_form', :locals=>{:documents=>@documents} %>
17
17
  </li>
@@ -1,49 +1,37 @@
1
-
2
1
  <html xmlns="http://www.w3.org/1999/xhtml">
3
-
4
2
  <head>
5
-
6
3
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
-
8
4
  <title><%= h(@page_title || application_name) %></title>
9
- <link href="<%= opensearch_catalog_path %>" title="<%= application_name%>" type="application/opensearchdescription+xml" rel="search"/>
10
-
5
+ <link href="<%= opensearch_catalog_path(:format => 'xml', :only_path => false) %>" title="<%= application_name%>" type="application/opensearchdescription+xml" rel="search"/>
6
+ <%= favicon_link_tag asset_path('favicon.ico') %>
7
+ <%= stylesheet_link_tag "application" %>
8
+ <%= javascript_include_tag "application" %>
9
+ <%= csrf_meta_tags %>
11
10
  <%= raw(render_head_content) %>
12
-
13
-
14
11
  </head>
15
- <% if params[:q].to_s.empty? and params[:f].to_s.empty? and params[:id].nil? %>
16
- <body onload="$('input#q').focus();" class="<%= render_body_class %>">
17
- <% else %>
18
- <body class="<%= render_body_class.html_safe %>">
19
- <% end %>
20
- <div id="doc4" class="yui-t2">
21
-
22
- <div id="hd">
23
- <div class="yui-g">
24
- <div class="yui-u first">
25
- <h1 class="site_title"><%= link_to application_name, "/" %><%= (params[:controller] == "catalog" and !params[:id]) ? "<span id='results_text'>Search Results</span>".html_safe : "" %></h1>
26
- </div>
27
- <div class="yui-u user_util_links">
28
- <%= render :partial=>'/user_util_links' %>
29
- </div>
12
+ <% onload_text = "$('input#q').focus();" if params[:q].to_s.empty? and params[:f].to_s.empty? and params[:id].nil? %>
13
+ <body onload="<%= onload_text %>" class="<%= render_body_class.html_safe %>">
14
+ <div id="page">
15
+ <div id="hd">
16
+ <div id="logo">
17
+ <h1 class="site_title"><%= link_to application_name, "/" %><%= (params[:controller] == "catalog" and !params[:id]) ? "<span id='results_text'>Search Results</span>".html_safe : "" %></h1>
18
+ </div>
19
+ <div id="user_util_links">
20
+ <%= render :partial=>'/user_util_links' %>
30
21
  </div>
31
22
  </div>
32
-
33
- <div id="bd">
34
-
35
- <div id="yui-main">
36
- <div class="yui-b">
23
+ <div id="bd">
24
+ <div id="main">
25
+ <div id="main_container">
37
26
  <%= render :partial=>'/flash_msg' %>
38
27
  <%= yield %>
39
28
  </div>
40
29
  </div>
41
-
42
- <div class="yui-b sidebar"><%= sidebar_items.join('').html_safe %></div>
43
-
44
- </div>
45
- <div id="ft"><%= raw(@footer) %></div>
46
- </div>
47
- </body>
48
-
49
- </html>
30
+ <div id="sidebar"><%= sidebar_items.join('').html_safe %></div>
31
+ </div>
32
+ <div id="ft">
33
+ <%= raw(@footer) %>
34
+ </div>
35
+ </div>
36
+ </body>
37
+ </html>
@@ -1,5 +1,5 @@
1
1
  <% @documents.each do |document| %>
2
2
  <%= document.to_email_text %>
3
- URL: <%= catalog_path(document[:id], {:only_path => false}.merge(@url_gen_params)) %>
3
+ URL: <%= catalog_path(document, {:only_path => false}.merge(@url_gen_params)) %>
4
4
  <% end %>
5
5
  Message: <%= @message %>
@@ -1,4 +1,4 @@
1
1
  <% @documents.each do |document| %>
2
2
  <%= document.to_sms_text %>
3
- Link: <%= catalog_path(document[:id], {:only_path => false}.merge(@url_gen_params) ) %>
4
- <% end %>
3
+ Link: <%= catalog_path(document, {:only_path => false}.merge(@url_gen_params) ) %>
4
+ <% end %>
@@ -10,7 +10,7 @@
10
10
  <%- @searches.each_with_index do |search,index| -%>
11
11
  <%= content_tag :tr, :id => "document_#{index + 1}" do %>
12
12
  <td class="query"><%= link_to_previous_search(search.query_params) %></td>
13
- <td class="actions"><%- if current_user && search.saved? -%>
13
+ <td class="actions"><%- if has_user_authentication_provider? && current_user && search.saved? -%>
14
14
  <%= button_to "forget", forget_search_path(search.id) %>
15
15
  <%- else -%>
16
16
  <%= button_to "save", save_search_path(search.id), :method => :put %>
data/blacklight.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Jonathan Rochkind", "Matt Mitchell", "Chris Beer", "Jessie Keck", "Jason Ronallo", "Vernon Chapman", "Mark A. Matienzo", "Dan Funk"]
9
9
  s.email = ["blacklight-development@googlegroups.com"]
10
10
  s.homepage = "http://projectblacklight.org/"
11
- s.summary = "A next-geration Library Catalag for Universities"
11
+ s.summary = "A next-generation Library Catalag for Universities"
12
12
  s.description = %q{Blacklight is a free and open source ruby-on-rails based discovery interface (a.k.a. “next-generation catalog”) especially optimized for heterogeneous collections. You can use it as a library catalog, as a front end for a digital repository, or as a single-search interface to aggregate digital content that would otherwise be siloed.}
13
13
 
14
14
  s.rubyforge_project = "blacklight"
@@ -20,12 +20,14 @@ Gem::Specification.new do |s|
20
20
 
21
21
  # PRODUCTION GEM REQUIREMENTS
22
22
  # ---------------------------------------
23
- s.add_dependency "rails", "~> 3.0"
24
- s.add_dependency "nokogiri", "~>1.5" # XML Parser
25
- s.add_dependency "unicode" # provides C-form normalization of unicode characters, as required by refworks.
26
- s.add_dependency "marc", "~> 0.4.3" # Marc record parser
27
- s.add_dependency "rsolr", '1.0.2' # Library for interacting with rSolr.
28
- s.add_dependency "rsolr-ext", '1.0.3' # extension to the above for some rails-ish behaviors - currently embedded in our solr document ojbect.
29
- s.add_dependency "kaminari" # the pagination (page 1,2,3, etc..) of our search results
30
-
23
+ s.add_dependency "rails", "~> 3.1.1"
24
+ s.add_dependency "nokogiri", "~>1.5" # XML Parser
25
+ s.add_dependency "unicode" # provides C-form normalization of unicode characters, as required by refworks.
26
+ s.add_dependency "marc", "~> 0.4.3" # Marc record parser
27
+ s.add_dependency "rsolr", "~> 1.0.6" # Library for interacting with rSolr.
28
+ s.add_dependency "rsolr-ext", '~> 1.0.3' # extension to the above for some rails-ish behaviors - currently embedded in our solr document ojbect.
29
+ s.add_dependency "kaminari" # the pagination (page 1,2,3, etc..) of our search results
30
+ s.add_dependency "sass-rails", "~> 3.1.1"
31
+ s.add_development_dependency "jettywrapper", ">= 1.2.0"
32
+ s.add_dependency "compass", ">= 0.12.alpha.2"
31
33
  end
data/lib/blacklight.rb CHANGED
@@ -8,6 +8,8 @@ require 'rsolr-ext'
8
8
  module Blacklight
9
9
 
10
10
  autoload :Configurable, 'blacklight/configurable'
11
+ autoload :Configuration, 'blacklight/configuration'
12
+ autoload :GlobalConfigurable, 'blacklight/global_configurable'
11
13
  autoload :SearchFields, 'blacklight/search_fields'
12
14
 
13
15
  autoload :Solr, 'blacklight/solr'
@@ -19,14 +21,14 @@ module Blacklight
19
21
 
20
22
  autoload :User, 'blacklight/user'
21
23
 
22
- autoload :CommaLinkRenderer, 'blacklight/comma_link_renderer'
23
-
24
24
  autoload :Controller, 'blacklight/controller'
25
25
  autoload :Catalog, 'blacklight/catalog'
26
26
 
27
27
  autoload :Routes, 'blacklight/routes'
28
28
 
29
- extend Configurable
29
+ autoload :OpenStructWithHashAccess, 'blacklight/utils'
30
+
31
+ extend GlobalConfigurable
30
32
  extend SearchFields
31
33
 
32
34
  require 'blacklight/version'
@@ -1,6 +1,8 @@
1
1
  # -*- encoding : utf-8 -*-
2
- module Blacklight::Catalog
2
+ module Blacklight::Catalog
3
3
  extend ActiveSupport::Concern
4
+
5
+ include Blacklight::Configurable
4
6
  include Blacklight::SolrHelper
5
7
 
6
8
  SearchHistoryWindow = 12 # how many searches to save in session history
@@ -26,14 +28,11 @@ module Blacklight::Catalog
26
28
  # get search results from the solr index
27
29
  def index
28
30
 
29
- delete_or_assign_search_session_params
30
-
31
31
  extra_head_content << view_context.auto_discovery_link_tag(:rss, url_for(params.merge(:format => 'rss')), :title => "RSS for results")
32
32
  extra_head_content << view_context.auto_discovery_link_tag(:atom, url_for(params.merge(:format => 'atom')), :title => "Atom for results")
33
33
 
34
34
  (@response, @document_list) = get_search_results
35
35
  @filters = params[:f] || []
36
- search_session[:total] = @response.total unless @response.nil?
37
36
 
38
37
  respond_to do |format|
39
38
  format.html { save_current_search_params }
@@ -1,47 +1,62 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Blacklight::Configurable
3
-
4
- # The config environment name used by the #config method
5
- #
6
- # Example:
7
- # class MyThing
8
- # extend Blacklight::Configurable
9
- # end
10
- #
11
- # Now MyThing.config will be the result of:
12
- # MyThing.configure(:production) {|config|}
13
- #
14
- # You set shared attributes by leaving the first argument blank or passing the :shared value:
15
- # MyThing.configure {|config|}
16
- # or
17
- # MyThing.cofigure(:shared) {|config|}
18
-
19
- # sets the @configs variable to a new Hash with empty Hash for :shared key and @config to nil
20
- def reset_configs!
21
- @config = nil
22
- @configs = {:shared=>{}}
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ helper_method :blacklight_config if respond_to? :helper_method
23
7
  end
24
8
 
25
- # A hash of all environment configs
26
- # The key is the environment name, the value a Hash
27
- def configs
28
- @configs ? @configs : (reset_configs! and @configs)
9
+ #instance methods for blacklight_config, default to class
10
+ # version unless set specifically on instance
11
+ def blacklight_config
12
+ @blacklight_config || self.class.blacklight_config
29
13
  end
30
-
31
- # The main config accessor. It merges the current configs[::Rails.env]
32
- # with configs[:shared] and lazy-loads @config to the result.
33
- def config
34
- @config ||= configs[:shared].merge(configs[::Rails.env] ||= {})
14
+ attr_writer :blacklight_config
15
+
16
+ module ClassMethods
17
+ def copy_blacklight_config_from(other_class)
18
+ self.blacklight_config = other_class.blacklight_config.inheritable_copy
19
+ end
20
+
21
+ # lazy load a deep_copy of superclass if present, else
22
+ # a default_configuration, which will be legacy load or new empty config.
23
+ # note the @blacklight_config variable is a ruby 'instance method on class
24
+ # object' that won't be automatically available to subclasses, that's why
25
+ # we lazy load to 'inherit' how we want.
26
+ def blacklight_config
27
+ unless (defined? @blacklight_config)
28
+ if superclass.respond_to?(:blacklight_config)
29
+ @blacklight_config = superclass.blacklight_config.deep_copy
30
+ else
31
+ @blacklight_config = default_configuration
32
+ end
33
+ end
34
+
35
+ return @blacklight_config
36
+ end
37
+ attr_writer :blacklight_config
38
+
39
+ #simply a convenience method for blacklight_config.configure
40
+ def configure_blacklight(*args, &block)
41
+ blacklight_config.configure(*args, &block)
42
+ end
43
+
44
+ ##
45
+ # The default configuration object, by default it reads from Blacklight.config for backwards
46
+ # compatibility with Blacklight <= 3.1
47
+ def default_configuration
48
+ Blacklight::Configurable.default_configuration
49
+ end
35
50
  end
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]
51
+
52
+ def self.default_configuration
53
+ @default_configuration ||= Blacklight::Configuration.from_legacy_configuration(Blacklight.config) if Blacklight.respond_to?(:config) and not Blacklight.config.empty?
54
+ @default_configuration ||= Blacklight::Configuration.new
55
+
56
+ @default_configuration
57
+ end
58
+
59
+ def self.default_configuration= config
60
+ @default_configuration = config
45
61
  end
46
-
47
62
  end
@@ -0,0 +1,126 @@
1
+ module Blacklight
2
+ ##
3
+ # Blacklight::Configuration holds the configuration for a Blacklight::Controller, including
4
+ # fields to display, facets to show, sort options, and search fields.
5
+ class Configuration < OpenStructWithHashAccess
6
+
7
+ # Set up Blacklight::Configuration.default_values to contain
8
+ # the basic, required Blacklight fields
9
+ class << self; attr_accessor :default_values; end
10
+ @default_values = {
11
+ :default_solr_params => {},
12
+ :show => OpenStructWithHashAccess.new,
13
+ :index => OpenStructWithHashAccess.new,
14
+ :spell_max => 5,
15
+ :max_per_page => 100
16
+ }
17
+
18
+
19
+ # XXX this isn't very pretty, but it works.
20
+ require 'blacklight/configuration/fields'
21
+ require 'blacklight/configuration/solr_field'
22
+ require 'blacklight/configuration/search_field'
23
+ require 'blacklight/configuration/sort_field'
24
+ include Fields
25
+
26
+ # Create collections of solr fields
27
+ define_field_access :facet_field
28
+ define_field_access :index_field
29
+ define_field_access :show_field
30
+ define_field_access :search_field
31
+ define_field_access :sort_field
32
+
33
+ def initialize(*args)
34
+ super(*args)
35
+ initialize_default_values!
36
+ yield(self) if block_given?
37
+ self
38
+ end
39
+
40
+ ##
41
+ # Initialize default values from the class attribute
42
+ def initialize_default_values!
43
+ Marshal.load(Marshal.dump(self.class.default_values)).each do |k, v|
44
+ self[k] ||= v
45
+ end
46
+ end
47
+
48
+ # Returns default search field, used for simpler display in history, etc.
49
+ # if not set, defaults to first defined search field
50
+ def default_search_field
51
+ field = nil
52
+ field ||= search_fields.values.select { |field| field.default == true }.first
53
+ field ||= search_fields.values.first
54
+
55
+ field
56
+ end
57
+
58
+ # Returns default sort field, used for simpler display in history, etc.
59
+ # if not set, defaults to first defined sort field
60
+ def default_sort_field
61
+ field = nil
62
+ field ||= sort_fields.values.select { |field| field.default == true }.first
63
+ field ||= sort_fields.values.first
64
+
65
+ field
66
+ end
67
+
68
+ ##
69
+ # Provide a 'deep copy' of Blacklight::Configuration that can be modifyed without affecting
70
+ # the original Blacklight::Configuration instance.
71
+ #
72
+ def deep_copy
73
+ Marshal.load(Marshal.dump(self))
74
+ end
75
+ alias_method :inheritable_copy, :deep_copy
76
+
77
+ ##
78
+ # DSL helper
79
+ def configure
80
+ yield self if block_given?
81
+ self
82
+ end
83
+
84
+ ##
85
+ # Helper method for loading a legacy blacklight configuration into the new style Blacklight::Configuration
86
+ def self.from_legacy_configuration config
87
+ config = Marshal.load(Marshal.dump(config))
88
+
89
+ Blacklight::Configuration.new do |blacklight_config|
90
+ # SolrHelper#default_solr_parameters needs to iterate over the keys, so this can't be a Struct
91
+ blacklight_config.default_solr_params = config[:default_solr_params]
92
+
93
+ config[:facet][:field_names].each do |x|
94
+ blacklight_config.add_facet_field x, :limit => config[:facet][:limits][x], :label => config[:facet][:labels][x]
95
+ end if config[:facet] and config[:facet][:field_names]
96
+
97
+ config[:index_fields][:field_names].each do |x|
98
+ blacklight_config.add_index_field x, :label => config[:index_fields][:labels][x]
99
+ end if config[:index_fields]
100
+
101
+ config[:show_fields][:field_names].each do |x|
102
+ blacklight_config.add_show_field x, :label => config[:show_fields][:labels][x]
103
+ end if config[:show_fields]
104
+
105
+ config[:search_fields].each do |x|
106
+ unless x.is_a? Hash
107
+ x = { :label => x[0], :key => x[1], :qt => x[1]}
108
+ end
109
+
110
+ x[:label] ||= x.delete(:display_label)
111
+
112
+ blacklight_config.add_search_field x[:key], x
113
+ end if config[:search_fields]
114
+
115
+ config[:sort_fields].each do |field|
116
+ label, sort = field
117
+ blacklight_config.add_sort_field sort, :label => label
118
+ end if config[:sort_fields]
119
+
120
+ config.reject { |key, value| [:default_solr_params, :facet, :index_fields, :show_fields, :search_fields, :sort_fields].include? key }.each do |key,value|
121
+ blacklight_config.send("#{key}=", (Blacklight::OpenStructWithHashAccess.new(value) if value.is_a? Hash) || value)
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end