blacklight 3.0pre1
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/.gitignore +17 -0
- data/.gitmodules +6 -0
- data/.yardopts +4 -0
- data/Gemfile +4 -0
- data/LICENSE +14 -0
- data/README.rdoc +168 -0
- data/Rakefile +9 -0
- data/app/controllers/bookmarks_controller.rb +98 -0
- data/app/controllers/feedback_controller.rb +37 -0
- data/app/controllers/folder_controller.rb +49 -0
- data/app/controllers/saved_searches_controller.rb +45 -0
- data/app/controllers/search_history_controller.rb +25 -0
- data/app/helpers/blacklight_helper.rb +606 -0
- data/app/helpers/bookmarks_helper.rb +3 -0
- data/app/helpers/catalog_helper.rb +65 -0
- data/app/helpers/feedback_helper.rb +2 -0
- data/app/helpers/hash_as_hidden_fields.rb +57 -0
- data/app/helpers/render_constraints_helper.rb +120 -0
- data/app/helpers/saved_searches_helper.rb +2 -0
- data/app/helpers/search_history_helper.rb +2 -0
- data/app/models/bookmark.rb +6 -0
- data/app/models/record_mailer.rb +43 -0
- data/app/models/search.rb +19 -0
- data/app/views/_flash_msg.html.erb +6 -0
- data/app/views/_user_util_links.html.erb +13 -0
- data/app/views/bookmarks/index.html.erb +33 -0
- data/app/views/catalog/_bookmark_control.html.erb +25 -0
- data/app/views/catalog/_bookmark_form.html.erb +8 -0
- data/app/views/catalog/_citation.html.erb +15 -0
- data/app/views/catalog/_constraints.html.erb +7 -0
- data/app/views/catalog/_constraints_element.html.erb +33 -0
- data/app/views/catalog/_did_you_mean.html.erb +10 -0
- data/app/views/catalog/_document_list.html.erb +30 -0
- data/app/views/catalog/_email_form.html.erb +11 -0
- data/app/views/catalog/_facet_limit.html.erb +33 -0
- data/app/views/catalog/_facet_pagination.html.erb +28 -0
- data/app/views/catalog/_facets.html.erb +9 -0
- data/app/views/catalog/_folder_control.html.erb +12 -0
- data/app/views/catalog/_home.html.erb +6 -0
- data/app/views/catalog/_home_text.html.erb +6 -0
- data/app/views/catalog/_index_partials/_default.erb +11 -0
- data/app/views/catalog/_marc_view.html.erb +33 -0
- data/app/views/catalog/_opensearch_response_metadata.html.erb +3 -0
- data/app/views/catalog/_previous_next_doc.html.erb +6 -0
- data/app/views/catalog/_refworks_form.html.erb +7 -0
- data/app/views/catalog/_results_pagination.html.erb +11 -0
- data/app/views/catalog/_search_form.html.erb +14 -0
- data/app/views/catalog/_show_partials/_default.html.erb +9 -0
- data/app/views/catalog/_show_sidebar.html.erb +1 -0
- data/app/views/catalog/_show_tools.html.erb +46 -0
- data/app/views/catalog/_sms_form.html.erb +23 -0
- data/app/views/catalog/_solr_request.html.erb +5 -0
- data/app/views/catalog/_sort_and_per_page.html.erb +20 -0
- data/app/views/catalog/_unapi_microformat.html.erb +1 -0
- data/app/views/catalog/citation.html.erb +1 -0
- data/app/views/catalog/email.erb +1 -0
- data/app/views/catalog/endnote.endnote.erb +1 -0
- data/app/views/catalog/facet.html.erb +28 -0
- data/app/views/catalog/index.atom.builder +108 -0
- data/app/views/catalog/index.html.erb +37 -0
- data/app/views/catalog/index.rss.builder +19 -0
- data/app/views/catalog/librarian_view.html.erb +3 -0
- data/app/views/catalog/opensearch.json.erb +0 -0
- data/app/views/catalog/opensearch.xml.erb +11 -0
- data/app/views/catalog/send_email_record.erb +0 -0
- data/app/views/catalog/show.endnote.erb +1 -0
- data/app/views/catalog/show.html.erb +42 -0
- data/app/views/catalog/show.refworks.erb +1 -0
- data/app/views/catalog/sms.erb +1 -0
- data/app/views/catalog/unapi.xml.builder +6 -0
- data/app/views/feedback/complete.html.erb +3 -0
- data/app/views/feedback/show.html.erb +20 -0
- data/app/views/folder/_tools.html.erb +23 -0
- data/app/views/folder/index.html.erb +44 -0
- data/app/views/layouts/blacklight.html.erb +49 -0
- data/app/views/record_mailer/email_record.erb +6 -0
- data/app/views/record_mailer/sms_record.erb +4 -0
- data/app/views/saved_searches/index.html.erb +27 -0
- data/app/views/search_history/index.html.erb +23 -0
- data/blacklight.gemspec +50 -0
- data/config.ru +4 -0
- data/config/routes.rb +54 -0
- data/db/seeds.rb +7 -0
- data/features/generators.feature +77 -0
- data/features/support/aruba.rb +9 -0
- data/install.rb +0 -0
- data/install/solr.yml +8 -0
- data/lib/blacklight.rb +121 -0
- data/lib/blacklight/catalog.rb +311 -0
- data/lib/blacklight/comma_link_renderer.rb +27 -0
- data/lib/blacklight/configurable.rb +46 -0
- data/lib/blacklight/controller.rb +121 -0
- data/lib/blacklight/engine.rb +32 -0
- data/lib/blacklight/exceptions.rb +13 -0
- data/lib/blacklight/marc.rb +46 -0
- data/lib/blacklight/marc/citation.rb +251 -0
- data/lib/blacklight/search_fields.rb +107 -0
- data/lib/blacklight/solr.rb +7 -0
- data/lib/blacklight/solr/document.rb +239 -0
- data/lib/blacklight/solr/document/dublin_core.rb +40 -0
- data/lib/blacklight/solr/document/email.rb +15 -0
- data/lib/blacklight/solr/document/marc.rb +84 -0
- data/lib/blacklight/solr/document/marc_export.rb +430 -0
- data/lib/blacklight/solr/document/sms.rb +13 -0
- data/lib/blacklight/solr/facet_paginator.rb +93 -0
- data/lib/blacklight/solr_helper.rb +413 -0
- data/lib/blacklight/user.rb +55 -0
- data/lib/blacklight/version.rb +3 -0
- data/lib/colorize.rb +196 -0
- data/lib/generators/blacklight/blacklight_generator.rb +134 -0
- data/lib/generators/blacklight/templates/SolrMarc.jar +0 -0
- data/lib/generators/blacklight/templates/catalog_controller.rb +8 -0
- data/lib/generators/blacklight/templates/config/SolrMarc/config-test.properties +37 -0
- data/lib/generators/blacklight/templates/config/SolrMarc/config.properties +37 -0
- data/lib/generators/blacklight/templates/config/SolrMarc/index.properties +97 -0
- data/lib/generators/blacklight/templates/config/SolrMarc/index_scripts/dewey.bsh +47 -0
- data/lib/generators/blacklight/templates/config/SolrMarc/index_scripts/format.bsh +126 -0
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/README_MAPS +1 -0
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/callnumber_map.properties +407 -0
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/composition_era_map.properties +56 -0
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/country_map.properties +379 -0
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/format_map.properties +50 -0
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/instrument_map.properties +101 -0
- data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/language_map.properties +490 -0
- data/lib/generators/blacklight/templates/config/blacklight_config.rb +245 -0
- data/lib/generators/blacklight/templates/config/solr.yml +6 -0
- data/lib/generators/blacklight/templates/migrations/add_user_types_to_bookmarks_searches.rb +11 -0
- data/lib/generators/blacklight/templates/migrations/create_bookmarks.rb +17 -0
- data/lib/generators/blacklight/templates/migrations/create_searches.rb +15 -0
- data/lib/generators/blacklight/templates/migrations/remove_editable_fields_from_bookmarks.rb +11 -0
- data/lib/generators/blacklight/templates/public/images/blacklight/bg.png +0 -0
- data/lib/generators/blacklight/templates/public/images/blacklight/border.png +0 -0
- data/lib/generators/blacklight/templates/public/images/blacklight/bul_sq_gry.gif +0 -0
- data/lib/generators/blacklight/templates/public/images/blacklight/checkmark.gif +0 -0
- data/lib/generators/blacklight/templates/public/images/blacklight/logo.png +0 -0
- data/lib/generators/blacklight/templates/public/images/blacklight/magnifying_glass.gif +0 -0
- data/lib/generators/blacklight/templates/public/images/blacklight/remove.gif +0 -0
- data/lib/generators/blacklight/templates/public/images/blacklight/separator.gif +0 -0
- data/lib/generators/blacklight/templates/public/images/blacklight/start_over.gif +0 -0
- data/lib/generators/blacklight/templates/public/javascripts/blacklight.js +485 -0
- data/lib/generators/blacklight/templates/public/javascripts/jquery-1.4.2.min.js +154 -0
- data/lib/generators/blacklight/templates/public/javascripts/jquery-ui-1.8.1.custom.min.js +756 -0
- data/lib/generators/blacklight/templates/public/stylesheets/blacklight.css +487 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/images/ui-bg_gloss-wave_35_558fd0_500x100.png +0 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/images/ui-icons_2e4f81_256x240.png +0 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
- data/lib/generators/blacklight/templates/public/stylesheets/jquery/ui-lightness/jquery-ui-1.8.1.custom.css +486 -0
- data/lib/generators/blacklight/templates/public/stylesheets/yui.css +31 -0
- data/lib/generators/blacklight/templates/solr_document.rb +30 -0
- data/lib/railties/blacklight.rake +66 -0
- data/lib/railties/cucumber.rake +53 -0
- data/lib/railties/rspec.rake +188 -0
- data/lib/railties/solr_marc.rake +148 -0
- data/lib/railties/test_solr_server.rb +130 -0
- data/spec/helpers/catalog_helper_spec.rb +111 -0
- data/spec/views/catalog/_sms_form.html.erb_spec.rb +19 -0
- data/tasks/blacklight_tasks.rake +4 -0
- data/uninstall.rb +1 -0
- metadata +431 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'will_paginate/view_helpers/link_renderer'
|
|
2
|
+
|
|
3
|
+
# Custom link renderer for WillPaginate
|
|
4
|
+
# Inserts commas into large page numbers
|
|
5
|
+
# example: 443719 becomes 443,719
|
|
6
|
+
#
|
|
7
|
+
# Note: To use this class, please call:
|
|
8
|
+
# <%= will_paginate(@users, :renderer => CommaLinkRenderer) %>
|
|
9
|
+
|
|
10
|
+
module Blacklight
|
|
11
|
+
|
|
12
|
+
class CommaLinkRenderer < WillPaginate::ViewHelpers::LinkRenderer
|
|
13
|
+
|
|
14
|
+
protected
|
|
15
|
+
# Just overriding the page_number method, so that large numbers are
|
|
16
|
+
# contain appropriate commas.
|
|
17
|
+
def page_number(page)
|
|
18
|
+
unless page == current_page
|
|
19
|
+
text = @template.number_with_delimiter(page)
|
|
20
|
+
link(text, page, :rel => rel_value(page))
|
|
21
|
+
else
|
|
22
|
+
tag(:em, page)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module Blacklight::Configurable
|
|
2
|
+
|
|
3
|
+
# The config environment name used by the #config method
|
|
4
|
+
#
|
|
5
|
+
# Example:
|
|
6
|
+
# class MyThing
|
|
7
|
+
# extend Blacklight::Configurable
|
|
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
|
+
|
|
36
|
+
# Accepts a value for the environment to configure and a block
|
|
37
|
+
# A hash is yielded to the block
|
|
38
|
+
# If the "env" != :shared,
|
|
39
|
+
# the hash is created by deep cloning the :shared environment config.
|
|
40
|
+
# This makes it possible to create defaults in the :shared config
|
|
41
|
+
def configure(env = :shared, &blk)
|
|
42
|
+
configs[env] = {}
|
|
43
|
+
yield configs[env]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Filters added to this controller apply to all controllers in the hosting application
|
|
3
|
+
# as this module is mixed-in to the application controller in the hosting app on installation.
|
|
4
|
+
module Blacklight::Controller
|
|
5
|
+
|
|
6
|
+
def self.included(base)
|
|
7
|
+
base.send :before_filter, :default_html_head # add JS/stylesheet stuff
|
|
8
|
+
# now in application.rb file under config.filter_parameters
|
|
9
|
+
# filter_parameter_logging :password, :password_confirmation
|
|
10
|
+
base.send :helper_method, :current_user_session, :current_user
|
|
11
|
+
base.send :after_filter, :discard_flash_if_xhr
|
|
12
|
+
|
|
13
|
+
# handle basic authorization exception with #access_denied
|
|
14
|
+
base.send :rescue_from, Blacklight::Exceptions::AccessDenied, :with => :access_denied
|
|
15
|
+
|
|
16
|
+
base.send :helper_method, [:request_is_for_user_resource?]#, :user_logged_in?]
|
|
17
|
+
|
|
18
|
+
base.send :layout, :choose_layout
|
|
19
|
+
|
|
20
|
+
# extra head content
|
|
21
|
+
base.send :helper_method, :extra_head_content
|
|
22
|
+
base.send :helper_method, :stylesheet_links
|
|
23
|
+
base.send :helper_method, :javascript_includes
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# test for exception notifier plugin
|
|
28
|
+
def error
|
|
29
|
+
raise RuntimeError, "Generating a test error..."
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
#############
|
|
33
|
+
# Display-related methods.
|
|
34
|
+
#############
|
|
35
|
+
|
|
36
|
+
# before filter to set up our default html HEAD content. Sub-class
|
|
37
|
+
# controllers can over-ride this method, or instead turn off the before_filter
|
|
38
|
+
# if they like. See:
|
|
39
|
+
# http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
|
|
40
|
+
# for how to turn off a filter in a sub-class and such.
|
|
41
|
+
def default_html_head
|
|
42
|
+
stylesheet_links << ['yui', 'jquery/ui-lightness/jquery-ui-1.8.1.custom.css', 'blacklight', {:plugin=>:blacklight, :media=>'all'}]
|
|
43
|
+
|
|
44
|
+
javascript_includes << ['jquery-1.4.2.min.js', 'jquery-ui-1.8.1.custom.min.js', 'blacklight', { :plugin=>:blacklight } ]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# An array of strings to be added to HTML HEAD section of view.
|
|
49
|
+
# See ApplicationHelper#render_head_content for details.
|
|
50
|
+
def extra_head_content
|
|
51
|
+
@extra_head_content ||= []
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# Array, where each element is an array of arguments to
|
|
56
|
+
# Rails stylesheet_link_tag helper. See
|
|
57
|
+
# ApplicationHelper#render_head_content for details.
|
|
58
|
+
def stylesheet_links
|
|
59
|
+
@stylesheet_links ||= []
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Array, where each element is an array of arguments to
|
|
63
|
+
# Rails javascript_include_tag helper. See
|
|
64
|
+
# ApplicationHelper#render_head_content for details.
|
|
65
|
+
def javascript_includes
|
|
66
|
+
@javascript_includes ||= []
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
protected
|
|
70
|
+
|
|
71
|
+
# Returns a list of Searches from the ids in the user's history.
|
|
72
|
+
def searches_from_history
|
|
73
|
+
session[:history].blank? ? [] : Search.find(session[:history]) rescue []
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
#
|
|
77
|
+
# Controller and view helper for determining if the current url is a request for a user resource
|
|
78
|
+
#
|
|
79
|
+
def request_is_for_user_resource?
|
|
80
|
+
request.env['PATH_INFO'] =~ /\/?users\/?/
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
#
|
|
84
|
+
# If a param[:no_layout] is set OR
|
|
85
|
+
# request.env['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest'
|
|
86
|
+
# don't use a layout, otherwise use the "application.html.erb" layout
|
|
87
|
+
#
|
|
88
|
+
def choose_layout
|
|
89
|
+
'blacklight' unless request.xml_http_request? || ! params[:no_layout].blank?
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def current_user_session
|
|
93
|
+
puts "DEPRICATED: Please use Devise, Authlogic or other authentication system."
|
|
94
|
+
user_session # method provided by devise
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Should be provided by devise
|
|
98
|
+
# def current_user
|
|
99
|
+
# end
|
|
100
|
+
|
|
101
|
+
##
|
|
102
|
+
# We discard flash messages generated by the xhr requests to avoid
|
|
103
|
+
# confusing UX.
|
|
104
|
+
def discard_flash_if_xhr
|
|
105
|
+
flash.discard if request.xhr?
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
##
|
|
109
|
+
# To handle failed authorization attempts, redirect the user to the
|
|
110
|
+
# login form and persist the current request uri as a parameter
|
|
111
|
+
def access_denied
|
|
112
|
+
# send the user home if the access was previously denied by the same
|
|
113
|
+
# request to avoid sending the user back to the login page
|
|
114
|
+
# (e.g. protected page -> logout -> returned to protected page -> home)
|
|
115
|
+
redirect_to root_url and flash.discard and return if request.referer and request.referer.ends_with? request.fullpath
|
|
116
|
+
|
|
117
|
+
redirect_to new_user_session_url(:referer => request.fullpath)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
end
|
|
121
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# lib/blacklight/engine.rb
|
|
2
|
+
require "blacklight"
|
|
3
|
+
require "rails"
|
|
4
|
+
|
|
5
|
+
module Blackight
|
|
6
|
+
class Engine < Rails::Engine
|
|
7
|
+
|
|
8
|
+
# BlacklightHelper is needed by all helpers, so we inject it
|
|
9
|
+
# into action view base here.
|
|
10
|
+
initializer 'blacklight.helpers' do |app|
|
|
11
|
+
ActionView::Base.send :include, BlacklightHelper
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Go ahead and innitialize Blacklight at the very end of the rails
|
|
15
|
+
# innitilization process.
|
|
16
|
+
# See: http://www.cowboycoded.com/2010/08/02/hooking-in-your-rails-3-engine-or-railtie-initializer-in-the-right-place/
|
|
17
|
+
initializer 'blacklight.init', :after=> :disable_dependency_loading do |app|
|
|
18
|
+
# Note, check for configuration files before calling init,
|
|
19
|
+
# otherwise we can't generate these files with the Generator
|
|
20
|
+
# and we can't tell at this point if we are begin run as a generator
|
|
21
|
+
# or not (at least, I didn't see a way)
|
|
22
|
+
Blacklight.init if File.exists?(Blacklight.solr_file)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# This makes our rake tasks visible.
|
|
26
|
+
rake_tasks do
|
|
27
|
+
load "railties/blacklight.rake"
|
|
28
|
+
load "railties/solr_marc.rake"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
## This module and the ::Document class in it is DEPRECATED, and will go away.
|
|
3
|
+
# It has been replaced by
|
|
4
|
+
# code using the new document extension framework. See
|
|
5
|
+
# Blacklight::Solr::Document::Marc and Blacklight::Solr::Document::MarcExport
|
|
6
|
+
# This code should not really be changed, or used anymore. It is frozen
|
|
7
|
+
# and deprecated until removed.
|
|
8
|
+
module Blacklight::Marc
|
|
9
|
+
|
|
10
|
+
autoload :Citation, 'blacklight/marc/citation.rb'
|
|
11
|
+
|
|
12
|
+
class UnsupportedMarcFormatType < RuntimeError; end
|
|
13
|
+
|
|
14
|
+
class Document
|
|
15
|
+
|
|
16
|
+
attr_reader :marc
|
|
17
|
+
|
|
18
|
+
include Citation
|
|
19
|
+
|
|
20
|
+
def initialize(marc_data, marc_type)
|
|
21
|
+
case marc_type.to_s
|
|
22
|
+
when 'marcxml'
|
|
23
|
+
reader = MARC::XMLReader.new(StringIO.new(marc_data)).to_a
|
|
24
|
+
@marc = reader[0]
|
|
25
|
+
when 'marc21'
|
|
26
|
+
reader = MARC::Record.new_from_marc(marc_data)
|
|
27
|
+
@marc = reader
|
|
28
|
+
else
|
|
29
|
+
raise UnsupportedMarcFormatType.new("Only marcxml and marc21 are supported.")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def marc_xml
|
|
34
|
+
@marc.to_xml.to_s
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def to_xml
|
|
38
|
+
if @marc
|
|
39
|
+
self.marc_xml
|
|
40
|
+
else
|
|
41
|
+
"<not-implemented/>"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
## This module is DEPRECATED, and will go away. It has been replaced by
|
|
2
|
+
# code using the new document extension framework. See
|
|
3
|
+
# Blacklight::Solr::Document::Marc and Blacklight::Solr::Document::MarcExport
|
|
4
|
+
# This code should not really be changed, or used anymore. It is frozen
|
|
5
|
+
# and deprecated until removed.
|
|
6
|
+
module Blacklight::Marc::Citation
|
|
7
|
+
|
|
8
|
+
def to_apa
|
|
9
|
+
return nil if self.marc.blank?
|
|
10
|
+
apa_citation(self.marc)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def to_mla
|
|
14
|
+
return nil if self.marc.blank?
|
|
15
|
+
mla_citation(self.marc)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def to_zotero(format)
|
|
19
|
+
return nil if self.marc.blank?
|
|
20
|
+
z3988_span(self.marc, format)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
protected
|
|
24
|
+
|
|
25
|
+
def mla_citation(record)
|
|
26
|
+
text = ''
|
|
27
|
+
authors_final = []
|
|
28
|
+
|
|
29
|
+
#setup formatted author list
|
|
30
|
+
authors = get_author_list(record)
|
|
31
|
+
|
|
32
|
+
if authors.length < 4
|
|
33
|
+
authors.each do |l|
|
|
34
|
+
if l == authors.first #first
|
|
35
|
+
authors_final.push(l)
|
|
36
|
+
elsif l == authors.last #last
|
|
37
|
+
authors_final.push(", and " + name_reverse(l) + ".")
|
|
38
|
+
else #all others
|
|
39
|
+
authors_final.push(", " + name_reverse(l))
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
text += authors_final.join
|
|
43
|
+
unless text.blank?
|
|
44
|
+
if text[-1,1] != "."
|
|
45
|
+
text += ". "
|
|
46
|
+
else
|
|
47
|
+
text += " "
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
else
|
|
51
|
+
text += authors.first + ", et al. "
|
|
52
|
+
end
|
|
53
|
+
# setup title
|
|
54
|
+
title = setup_title_info(record)
|
|
55
|
+
if !title.nil?
|
|
56
|
+
text += "<i>" + mla_citation_title(title) + "</i> "
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Edition
|
|
60
|
+
edition_data = setup_edition(record)
|
|
61
|
+
text += edition_data + " " unless edition_data.nil?
|
|
62
|
+
|
|
63
|
+
# Publication
|
|
64
|
+
text += setup_pub_info(record) + ", " unless setup_pub_info(record).nil?
|
|
65
|
+
|
|
66
|
+
# Get Pub Date
|
|
67
|
+
text += setup_pub_date(record) unless setup_pub_date(record).nil?
|
|
68
|
+
if text[-1,1] != "."
|
|
69
|
+
text += "." unless text.nil? or text.blank?
|
|
70
|
+
end
|
|
71
|
+
text
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def apa_citation(record)
|
|
75
|
+
text = ''
|
|
76
|
+
authors_list = []
|
|
77
|
+
authors_list_final = []
|
|
78
|
+
|
|
79
|
+
#setup formatted author list
|
|
80
|
+
authors = get_author_list(record)
|
|
81
|
+
authors.each do |l|
|
|
82
|
+
authors_list.push(abbreviate_name(l)) unless l.nil?
|
|
83
|
+
end
|
|
84
|
+
authors_list.each do |l|
|
|
85
|
+
if l == authors_list.first #first
|
|
86
|
+
authors_list_final.push(l.strip)
|
|
87
|
+
elsif l == authors_list.last #last
|
|
88
|
+
authors_list_final.push(", & " + l.strip)
|
|
89
|
+
else #all others
|
|
90
|
+
authors_list_final.push(", " + l.strip)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
text += authors_list_final.join
|
|
94
|
+
unless text.blank?
|
|
95
|
+
if text[-1,1] != "."
|
|
96
|
+
text += ". "
|
|
97
|
+
else
|
|
98
|
+
text += " "
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
# Get Pub Date
|
|
102
|
+
text += "(" + setup_pub_date(record) + "). " unless setup_pub_date(record).nil?
|
|
103
|
+
|
|
104
|
+
# setup title info
|
|
105
|
+
title = setup_title_info(record)
|
|
106
|
+
text += "<i>" + title + "</i> " unless title.nil?
|
|
107
|
+
|
|
108
|
+
# Edition
|
|
109
|
+
edition_data = setup_edition(record)
|
|
110
|
+
text += edition_data + " " unless edition_data.nil?
|
|
111
|
+
|
|
112
|
+
# Publisher info
|
|
113
|
+
text += setup_pub_info(record) unless setup_pub_info(record).nil?
|
|
114
|
+
unless text.blank?
|
|
115
|
+
if text[-1,1] != "."
|
|
116
|
+
text += "."
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
text
|
|
120
|
+
end
|
|
121
|
+
def setup_pub_date(record)
|
|
122
|
+
if !record.find{|f| f.tag == '260'}.nil?
|
|
123
|
+
pub_date = record.find{|f| f.tag == '260'}
|
|
124
|
+
if pub_date.find{|s| s.code == 'c'}
|
|
125
|
+
date_value = pub_date.find{|s| s.code == 'c'}.value.gsub(/[^0-9]/, "") unless pub_date.find{|s| s.code == 'c'}.value.gsub(/[^0-9]/, "").blank?
|
|
126
|
+
end
|
|
127
|
+
return nil unless !date_value.nil?
|
|
128
|
+
end
|
|
129
|
+
date_value
|
|
130
|
+
end
|
|
131
|
+
def setup_pub_info(record)
|
|
132
|
+
text = ''
|
|
133
|
+
pub_info_field = record.find{|f| f.tag == '260'}
|
|
134
|
+
if !pub_info_field.nil?
|
|
135
|
+
a_pub_info = pub_info_field.find{|s| s.code == 'a'}
|
|
136
|
+
b_pub_info = pub_info_field.find{|s| s.code == 'b'}
|
|
137
|
+
a_pub_info = clean_end_punctuation(a_pub_info.value.strip) unless a_pub_info.nil?
|
|
138
|
+
b_pub_info = b_pub_info.value.strip unless b_pub_info.nil?
|
|
139
|
+
text += a_pub_info.strip unless a_pub_info.nil?
|
|
140
|
+
if !a_pub_info.nil? and !b_pub_info.nil?
|
|
141
|
+
text += ": "
|
|
142
|
+
end
|
|
143
|
+
text += b_pub_info.strip unless b_pub_info.nil?
|
|
144
|
+
end
|
|
145
|
+
return nil if text.strip.blank?
|
|
146
|
+
clean_end_punctuation(text.strip)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def mla_citation_title(text)
|
|
150
|
+
no_upcase = ["a","an","and","but","by","for","it","of","the","to","with"]
|
|
151
|
+
new_text = []
|
|
152
|
+
word_parts = text.split(" ")
|
|
153
|
+
word_parts.each do |w|
|
|
154
|
+
if !no_upcase.include? w
|
|
155
|
+
new_text.push(w.capitalize)
|
|
156
|
+
else
|
|
157
|
+
new_text.push(w)
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
new_text.join(" ")
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def setup_title_info(record)
|
|
164
|
+
text = ''
|
|
165
|
+
title_info_field = record.find{|f| f.tag == '245'}
|
|
166
|
+
if !title_info_field.nil?
|
|
167
|
+
a_title_info = title_info_field.find{|s| s.code == 'a'}
|
|
168
|
+
b_title_info = title_info_field.find{|s| s.code == 'b'}
|
|
169
|
+
a_title_info = clean_end_punctuation(a_title_info.value.strip) unless a_title_info.nil?
|
|
170
|
+
b_title_info = clean_end_punctuation(b_title_info.value.strip) unless b_title_info.nil?
|
|
171
|
+
text += a_title_info unless a_title_info.nil?
|
|
172
|
+
if !a_title_info.nil? and !b_title_info.nil?
|
|
173
|
+
text += ": "
|
|
174
|
+
end
|
|
175
|
+
text += b_title_info unless b_title_info.nil?
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
return nil if text.strip.blank?
|
|
179
|
+
clean_end_punctuation(text.strip) + "."
|
|
180
|
+
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def clean_end_punctuation(text)
|
|
184
|
+
if [".",",",":",";","/"].include? text[-1,1]
|
|
185
|
+
return text[0,text.length-1]
|
|
186
|
+
end
|
|
187
|
+
text
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def setup_edition(record)
|
|
191
|
+
edition_field = record.find{|f| f.tag == '250'}
|
|
192
|
+
edition_code = edition_field.find{|s| s.code == 'a'} unless edition_field.nil?
|
|
193
|
+
edition_data = edition_code.value unless edition_code.nil?
|
|
194
|
+
if edition_data.nil? or edition_data == '1st ed.'
|
|
195
|
+
return nil
|
|
196
|
+
else
|
|
197
|
+
return edition_data
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def get_author_list(record)
|
|
202
|
+
author_list = []
|
|
203
|
+
authors_primary = record.find{|f| f.tag == '100'}
|
|
204
|
+
author_primary = authors_primary.find{|s| s.code == 'a'}.value unless authors_primary.nil?
|
|
205
|
+
author_list.push(clean_end_punctuation(author_primary)) unless author_primary.nil?
|
|
206
|
+
authors_secondary = record.find_all{|f| ('700') === f.tag}
|
|
207
|
+
if !authors_secondary.nil?
|
|
208
|
+
authors_secondary.each do |l|
|
|
209
|
+
author_list.push(clean_end_punctuation(l.find{|s| s.code == 'a'}.value)) unless l.find{|s| s.code == 'a'}.value.nil?
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
author_list.uniq!
|
|
214
|
+
author_list
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def abbreviate_name(name)
|
|
218
|
+
name_parts = name.split(", ")
|
|
219
|
+
first_name_parts = name_parts.last.split(" ")
|
|
220
|
+
temp_name = name_parts.first + ", " + first_name_parts.first[0,1] + "."
|
|
221
|
+
first_name_parts.shift
|
|
222
|
+
temp_name += " " + first_name_parts.join(" ") unless first_name_parts.empty?
|
|
223
|
+
temp_name
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def name_reverse(name)
|
|
227
|
+
name = clean_end_punctuation(name)
|
|
228
|
+
temp_name = name.split(", ")
|
|
229
|
+
return temp_name.last + " " + temp_name.first
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Genrates a Z39.88 span element to pass the COinS metadata to Zotero
|
|
233
|
+
def z3988_span(record,format)
|
|
234
|
+
title = record.find{|field| field.tag == '245'}
|
|
235
|
+
author = record.find{|field| field.tag == '100'}
|
|
236
|
+
publisher_info = record.find{|field| field.tag == '260'}
|
|
237
|
+
edition = record.find{|field| field.tag == '250'}
|
|
238
|
+
isbn = record.find{|field| field.tag == '020'}
|
|
239
|
+
issn = record.find{|field| field.tag == '022'}
|
|
240
|
+
format.is_a?(Array) ? format = format[0].downcase.strip : format = format.downcase.strip
|
|
241
|
+
text = "<span class='Z3988' "
|
|
242
|
+
if format == 'book'
|
|
243
|
+
text << "title='ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator&rft.genre=book&rft.btitle=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&rft.title=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&rft.au=#{(author.nil? or author['a'].nil?) ? "" : CGI::escape(author['a'])}&rft.date=#{(publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c'])}&rft.pub=#{(publisher_info.nil? or publisher_info['a'].nil?) ? "" : CGI::escape(publisher_info['a'])}&rft.edition=#{(edition.nil? or edition['a'].nil?) ? "" : CGI::escape(edition['a'])}&rft.isbn=#{(isbn.nil? or isbn['a'].nil?) ? "" : isbn['a']}'"
|
|
244
|
+
elsif format.include?('journal') # checking using include because institutions may use formats like Journal or Journal/Magazine
|
|
245
|
+
text << "title='ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator&rft.genre=article&rft.title=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&rft.atitle=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&rft.date=#{(publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c'])}&rft.issn=#{(issn.nil? or issn['a'].nil?) ? "" : issn['a']}'"
|
|
246
|
+
else
|
|
247
|
+
text << "title='ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator&rft.title=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&rft.creator=#{(author.nil? or author['a'].nil?) ? "" : CGI::escape(author['a'])}&rft.date=#{(publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c'])}&rft.pub=#{(publisher_info.nil? or publisher_info['a'].nil?) ? "" : CGI::escape(publisher_info['a'])}&rft.format=#{CGI::escape(format)}'"
|
|
248
|
+
end
|
|
249
|
+
text << "></span>"
|
|
250
|
+
end
|
|
251
|
+
end
|