blacklight-marc 6.0.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -2
  3. data/.solr_wrapper.yaml +5 -0
  4. data/.travis.yml +9 -11
  5. data/Gemfile +30 -14
  6. data/README.md +29 -8
  7. data/Rakefile +8 -20
  8. data/app/assets/stylesheets/blacklight_marc.scss +4 -6
  9. data/app/helpers/blacklight_marc_helper.rb +5 -4
  10. data/app/models/concerns/blacklight/solr/document/marc.rb +13 -12
  11. data/app/models/concerns/blacklight/solr/document/marc_export.rb +53 -50
  12. data/app/views/bookmarks/_endnote.html.erb +1 -1
  13. data/app/views/bookmarks/_refworks.html.erb +1 -1
  14. data/app/views/catalog/_marc_view.html.erb +4 -4
  15. data/app/views/catalog/endnote.endnote.erb +1 -1
  16. data/app/views/catalog/librarian_view.html.erb +7 -4
  17. data/blacklight-marc.gemspec +12 -12
  18. data/config/routes.rb +1 -1
  19. data/lib/blacklight/marc/catalog.rb +9 -15
  20. data/lib/blacklight/marc/engine.rb +2 -0
  21. data/lib/blacklight/marc/indexer.rb +9 -39
  22. data/lib/blacklight/marc/indexer/formats.rb +13 -15
  23. data/lib/blacklight/marc/routes.rb +2 -39
  24. data/lib/blacklight/marc/routes/marc_viewable.rb +20 -0
  25. data/lib/blacklight/marc/version.rb +1 -1
  26. data/lib/generators/blacklight/marc/install_generator.rb +16 -9
  27. data/lib/generators/blacklight/marc/templates/app/models/marc_indexer.rb +59 -59
  28. data/lib/generators/blacklight/marc/templates/config/translation_maps/callnumber_map.properties +149 -11
  29. data/lib/railties/solr_marc.rake +33 -33
  30. data/solr/conf/_rest_managed.json +3 -0
  31. data/solr/conf/admin-extra.html +31 -0
  32. data/solr/conf/elevate.xml +36 -0
  33. data/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
  34. data/solr/conf/protwords.txt +21 -0
  35. data/solr/conf/schema.xml +388 -0
  36. data/solr/conf/scripts.conf +24 -0
  37. data/solr/conf/solrconfig.xml +195 -0
  38. data/solr/conf/spellings.txt +2 -0
  39. data/solr/conf/stopwords.txt +58 -0
  40. data/solr/conf/stopwords_en.txt +58 -0
  41. data/solr/conf/synonyms.txt +31 -0
  42. data/solr/conf/xslt/example.xsl +132 -0
  43. data/solr/conf/xslt/example_atom.xsl +67 -0
  44. data/solr/conf/xslt/example_rss.xsl +66 -0
  45. data/solr/conf/xslt/luke.xsl +337 -0
  46. data/spec/controllers/catalog_controller_spec.rb +11 -6
  47. data/spec/features/bookmarks_spec.rb +2 -1
  48. data/spec/features/search_formats_spec.rb +3 -3
  49. data/spec/integration/solr_document_spec.rb +19 -19
  50. data/spec/lib/blacklight_solr_document_marc_spec.rb +7 -7
  51. data/spec/lib/indexer/dewey_spec.rb +4 -4
  52. data/spec/lib/indexer/formats_spec.rb +9 -1
  53. data/spec/lib/marc_export_spec.rb +46 -46
  54. data/spec/lib/tasks/solr_marc_task_spec.rb +7 -7
  55. data/spec/lib/traject_indexer_spec.rb +6 -2
  56. data/spec/routing/routes_spec.rb +0 -6
  57. data/spec/spec_helper.rb +2 -2
  58. data/spec/test_app_templates/Gemfile.extra +2 -0
  59. data/spec/test_app_templates/lib/generators/test_app_generator.rb +15 -14
  60. data/spec/views/bookmarks/_endnote.html.erb_spec.rb +16 -6
  61. data/spec/views/bookmarks/_refworks.html.erb_spec.rb +17 -7
  62. data/spec/views/catalog/index.atom.builder_spec.rb +12 -17
  63. data/test_support/config/translation_maps/test_formats.properties +3 -1
  64. metadata +85 -60
  65. data/app/helpers/blacklight_bookmarks_helper.rb +0 -3
  66. data/config/jetty.yml +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3a674be3c4819a0ea53a8c949f68dc305adc2715
4
- data.tar.gz: b2b7608c6e893f43fce519908d35f257a759a14f
2
+ SHA256:
3
+ metadata.gz: 982fc53944ac08a10b9fee904da008efa6c7a80a4c17a6abd7230a6d530afb09
4
+ data.tar.gz: 2df11802581af3d7f66ce71a174e3e1866f88b48a8587146e8273532ea74181e
5
5
  SHA512:
6
- metadata.gz: 506c0334c905f179256b15044a46c0bf6a8cc0b71d49af5fc482a8e24b0cf9fbc402612486b3a3a01fc926ee6a20ad4acd1e32b79c06d69e0fe4e0333bd6cb90
7
- data.tar.gz: 00399aeb90e6f0098849378eb99155f1b9f07d476e0970af1b39f9ca654c5e636d080033347f82f9509bf4d2d360738d002fab3e40b36d126cee5b06bd7774bf
6
+ metadata.gz: 85d9056f0e7962ea4b0c2b5353456c2a0334f1833073224f92e3bbbb5ec13b8baf6074724f371423b7d784e6a811963bf0a6f2f3e43a37f8151575a85c6307ce
7
+ data.tar.gz: 8666db8e8109679087f4c774a1b7eb4a70a4d91075668f08115b11d527827c8225da37b98d904c27b7464bf5d9e2534594745bdd940ef15b6b6b76b65ce25d6f
data/.gitignore CHANGED
@@ -17,6 +17,5 @@ test/version_tmp
17
17
  tmp
18
18
  lib/solrmarc.log
19
19
  lib/solrmarc.log.*
20
- spec/internal
20
+ .internal_test_app
21
21
  jetty
22
- .internal_test_app
@@ -0,0 +1,5 @@
1
+ # Place any default configuration for solr_wrapper here
2
+ # port: 8983
3
+ collection:
4
+ dir: solr/conf/
5
+ name: blacklight-core
@@ -4,26 +4,24 @@ sudo: false
4
4
  notifications:
5
5
  email: false
6
6
 
7
- rvm:
8
- - 2.2.3
9
-
10
7
  matrix:
11
8
  include:
12
- - rvm: 2.2.2
13
- env: "RAILS_VERSION=4.1.13"
14
- - rvm: 2.1.6
15
- env: "RAILS_VERSION=4.2.4"
9
+ - rvm: 2.7.1
10
+ env: "RAILS_VERSION=6.0.3.2"
11
+ - rvm: 2.6.6
12
+ env: "RAILS_VERSION=6.0.3.2"
13
+ - rvm: 2.6.6
14
+ env: "RAILS_VERSION=5.2.4.3"
16
15
 
17
16
  before_install:
18
17
  - gem install bundler
19
18
 
20
- env:
21
- - "RAILS_VERSION=4.2.4"
22
-
23
19
  notifications:
24
20
  irc: "irc.freenode.org#blacklight"
25
21
  email:
26
22
  - blacklight-commits@googlegroups.com
27
23
 
28
24
  global_env:
29
- - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
25
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
26
+
27
+ jdk: openjdk11
data/Gemfile CHANGED
@@ -1,16 +1,18 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ git_source(:github) do |repo_name|
4
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
5
+ "https://github.com/#{repo_name}.git"
6
+ end
7
+
3
8
  # Please see blacklight_marc.gemspec for dependency information.
4
9
  gemspec path: File.expand_path('..', __FILE__)
5
10
 
6
- gem 'simplecov', '~> 0.10', require: false
7
- gem 'coveralls', require: false
8
-
9
11
  # BEGIN ENGINE_CART BLOCK
10
- # engine_cart: 0.8.0
11
- # engine_cart stanza: 0.8.0
12
+ # engine_cart: 1.0.1
13
+ # engine_cart stanza: 0.10.0
12
14
  # the below comes from engine_cart, a gem used to test this Rails engine gem in the context of a Rails app.
13
- file = File.expand_path("Gemfile", ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path(".internal_test_app", File.dirname(__FILE__)))
15
+ file = File.expand_path('Gemfile', ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path('.internal_test_app', File.dirname(__FILE__)))
14
16
  if File.exist?(file)
15
17
  begin
16
18
  eval_gemfile file
@@ -21,15 +23,29 @@ if File.exist?(file)
21
23
  else
22
24
  Bundler.ui.warn "[EngineCart] Unable to find test application dependencies in #{file}, using placeholder dependencies"
23
25
 
24
- gem 'rails', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION']
26
+ if ENV['RAILS_VERSION']
27
+ if ENV['RAILS_VERSION'] == 'edge'
28
+ gem 'rails', github: 'rails/rails'
29
+ ENV['ENGINE_CART_RAILS_OPTIONS'] = '--edge --skip-turbolinks'
30
+ else
31
+ gem 'rails', ENV['RAILS_VERSION']
32
+ end
33
+ end
25
34
 
26
- if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^4.2/
27
- gem 'bootstrap-sass', '>= 3.3.5.1'
28
- gem 'responders', "~> 2.0"
29
- gem 'sass-rails', ">= 5.0"
30
- else
31
- gem 'bootstrap-sass', '< 3.3.5' # 3.3.5 requires sass 3.3, incompatible with sass-rails 4.x
32
- gem 'sass-rails', "< 5.0"
35
+ case ENV['RAILS_VERSION']
36
+ when /^6.0/
37
+ gem 'sass-rails', '>= 6'
38
+ gem 'webpacker', '~> 4.0'
39
+ when /^5.[12]/
40
+ gem 'sass-rails', '~> 5.0'
41
+ when /^4.2/
42
+ gem 'responders', '~> 2.0'
43
+ gem 'sass-rails', '>= 5.0'
44
+ gem 'coffee-rails', '~> 4.1.0'
45
+ when /^4.[01]/
46
+ gem 'sass-rails', '< 5.0'
33
47
  end
34
48
  end
35
49
  # END ENGINE_CART BLOCK
50
+
51
+ eval_gemfile File.expand_path("spec/test_app_templates/Gemfile.extra", File.dirname(__FILE__))
data/README.md CHANGED
@@ -1,9 +1,15 @@
1
- [![Build Status](https://travis-ci.org/projectblacklight/blacklight_marc.png?branch=master)](https://travis-ci.org/projectblacklight/blacklight_marc)
1
+ [![Build Status](https://travis-ci.org/projectblacklight/blacklight-marc.png?branch=master)](https://travis-ci.org/projectblacklight/blacklight-marc)
2
2
 
3
3
  # Blacklight::Marc
4
4
 
5
5
  MARC-specific enhancements for [Blacklight](https://github.com/projectblacklight/blacklight)
6
6
 
7
+ ## Features
8
+ * Rake task `solr:marc:index` to import .mrc files using Traject and app/models/marc_indexer
9
+ * "Librarian View" at `catalog/:id/librarian_view`
10
+ * Export records to refworks and endnote
11
+ * Blacklight::Solr::Document mixins for exporting and transforming MARC data from a stored Solr field
12
+
7
13
  ## Installation
8
14
 
9
15
  Add this line to your application's Gemfile:
@@ -16,8 +22,29 @@ And then execute:
16
22
 
17
23
  After running the blacklight generator, run the blacklight_marc generator:
18
24
 
19
- $ rails generate blacklight_marc:marc
25
+ $ rails generate blacklight:marc:install
26
+
27
+
28
+ ## How does it work?
29
+ This generator injects an include into CatalogController (parent class of BookmarksController):
30
+
31
+ ```ruby
32
+ include Blacklight::Marc::Catalog
33
+ ```
34
+
35
+ and the following code is generated into SolrDocument:
20
36
 
37
+ ```ruby
38
+ use_extension( Blacklight::Solr::Document::Marc) do |document|
39
+ document.key?( :marc_display )
40
+ end
41
+ ```
42
+
43
+ This means, the extension will be applied on the instance if the backing hash
44
+ has a field called `marc_display`.
45
+
46
+
47
+ ## Indexing
21
48
  The generator will create a model called MarcIndexer. This model can be customized by modifying
22
49
  the field configurations in its initializer as a Traject 2 indexer; new indexing behaviors can
23
50
  be added to it via mixins or inline methods. Two example mixins are provided:
@@ -35,12 +62,6 @@ MarcIndexer
35
62
  end
36
63
  end
37
64
  ```
38
- ## Features
39
- * Rake task `solr:marc:index` to import .mrc files using Traject and app/models/marc_indexer
40
- * Librarian view at `catalog/:id/librarian_view`
41
- * Export records to refworks and endnote
42
- * Blacklight::Solr::Document mixins for exporting and transforming MARC data from a stored Solr field
43
-
44
65
 
45
66
  ## Documentation, Information and Support
46
67
 
data/Rakefile CHANGED
@@ -1,41 +1,29 @@
1
1
  require "bundler/gem_tasks"
2
- ZIP_URL = "https://github.com/projectblacklight/blacklight-jetty/archive/v4.10.4.zip"
3
-
4
- require 'jettywrapper'
5
2
  require 'rspec/core/rake_task'
6
3
  require 'engine_cart/rake_task'
7
4
 
8
- EngineCart.fingerprint_proc = EngineCart.rails_fingerprint_proc
9
-
10
5
  RSpec::Core::RakeTask.new(:spec)
11
6
 
12
7
  task :default => [:ci]
13
8
 
14
- task :ci => ['blacklight_marc:clean', 'blacklight_marc:generate'] do
15
- jetty_params = Jettywrapper.load_config('test')
16
- error = Jettywrapper.wrap(jetty_params) do
17
- Rake::Task["blacklight_marc:fixtures"].invoke
18
- Rake::Task['spec'].invoke
9
+ task :ci => ['engine_cart:generate'] do
10
+ require 'solr_wrapper'
11
+ SolrWrapper.wrap(port: '8983') do |solr|
12
+ solr.with_collection(name: 'blacklight-core', dir: File.join(File.expand_path(File.dirname(__FILE__)), "solr", "conf")) do
13
+ Rake::Task["blacklight_marc:fixtures"].invoke
14
+ Rake::Task['spec'].invoke
15
+ end
19
16
  end
20
- raise "test failures: #{error}" if error
21
17
  end
22
18
 
23
19
 
24
20
  namespace :blacklight_marc do
25
21
 
26
22
  desc "Load fixtures"
27
- task :fixtures => [:generate] do
23
+ task :fixtures => ['engine_cart:generate'] do
28
24
  within_test_app do
29
25
  system "bundle exec rake solr:marc:index_test_data RAILS_ENV=test"
30
26
  abort "Error running fixtures" unless $?.success?
31
27
  end
32
28
  end
33
-
34
- desc "Clean out the test rails app"
35
- task :clean => ['jetty:clean'] do
36
- end
37
-
38
- desc "Create the test rails app"
39
- task :generate => ['engine_cart:generate'] do
40
- end
41
29
  end
@@ -12,6 +12,9 @@ $marc_item_separator: 1px solid $text-muted !default;
12
12
  #marc_view
13
13
  {
14
14
  text-align:left;
15
+ /* https://meyerweb.com/eric/thoughts/2010/02/12/fixed-monospace-sizing/ */
16
+ font-family: "Courier New", monospace, serif;
17
+ font-size: 1em;
15
18
 
16
19
  .field
17
20
  {
@@ -22,7 +25,7 @@ $marc_item_separator: 1px solid $text-muted !default;
22
25
  .ind1, .ind2
23
26
  {
24
27
  display:inline;
25
- padding:0 $padding-xs-horizontal;
28
+ padding: 0 ($spacer / 2);
26
29
  }
27
30
 
28
31
  .subfields
@@ -35,8 +38,3 @@ $marc_item_separator: 1px solid $text-muted !default;
35
38
  float:left;
36
39
  }
37
40
  }
38
-
39
- /* refworks uses a form; we need to give it some additional padding to make it look like a link */
40
- #refworks-form .btn {
41
- padding: $nav-link-padding;
42
- }
@@ -1,18 +1,18 @@
1
1
  module BlacklightMarcHelper
2
2
 
3
3
  # This method should move to BlacklightMarc in Blacklight 6.x
4
- def refworks_export_url params = {}
4
+ def refworks_export_url params = {}, *_
5
5
  "http://www.refworks.com/express/expressimport.asp?vendor=#{CGI.escape(params[:vendor] || application_name)}&filter=#{CGI.escape(params[:filter] || "MARC Format")}&encoding=65001" + (("&url=#{CGI.escape(params[:url])}" if params[:url]) || "")
6
6
  end
7
7
 
8
- def refworks_solr_document_path opts = {}
8
+ def refworks_solr_document_path opts = {}, *_
9
9
  if opts[:id]
10
10
  refworks_export_url(url: solr_document_url(opts[:id], format: :refworks_marc_txt))
11
11
  end
12
12
  end
13
13
 
14
14
  # For exporting a single endnote document. (endnote_catalog_path is defined by blacklight-marc and it is used for multiple document export)
15
- def single_endnote_catalog_path opts = {}
15
+ def single_endnote_catalog_path opts = {}, *_
16
16
  solr_document_path(opts.merge(format: 'endnote'))
17
17
  end
18
18
 
@@ -33,7 +33,8 @@ module BlacklightMarcHelper
33
33
  val = ''
34
34
  documents.each do |doc|
35
35
  if doc.exports_as? :endnote
36
- val += doc.export_as(:endnote) + "\n"
36
+ endnote = doc.export_as(:endnote)
37
+ val += "#{endnote}\n" if endnote
37
38
  end
38
39
  end
39
40
  val
@@ -6,7 +6,7 @@
6
6
  # then provides various transformations/exports of that Marc via the included
7
7
  # Blacklight::Solr::Document::MarcExport module.
8
8
  #
9
- # This extension would normally be registered using
9
+ # This extension would normally be registered using
10
10
  # Blacklight::Solr::Document#use_extension. eg:
11
11
  #
12
12
  # SolrDocument.use_extension( Blacklight::Solr::Document::Marc ) { |document| my_logic_for_document_has_marc?( document ) }
@@ -20,15 +20,15 @@ require 'marc'
20
20
 
21
21
  module Blacklight::Solr::Document::Marc
22
22
 
23
- include Blacklight::Solr::Document::MarcExport # All our export_as stuff based on to_marc.
24
-
23
+ include Blacklight::Solr::Document::MarcExport # All our export_as stuff based on to_marc.
24
+
25
25
  class UnsupportedMarcFormatType < RuntimeError; end
26
-
26
+
27
27
  def self.extended(document)
28
- # Register our exportable formats, we inherit these from MarcExport
28
+ # Register our exportable formats, we inherit these from MarcExport
29
29
  Blacklight::Solr::Document::MarcExport.register_export_formats( document )
30
30
  end
31
-
31
+
32
32
  # ruby-marc object
33
33
  def to_marc
34
34
  @_ruby_marc_obj ||= load_marc
@@ -50,29 +50,30 @@ module Blacklight::Solr::Document::Marc
50
50
  return MARC::Record.new_from_hash( JSON.parse( fetch(_marc_source_field) ) )
51
51
  else
52
52
  raise UnsupportedMarcFormatType.new("Only marcxml, marc21, and json are supported, this documents format is #{_marc_format_type} and the current extension parameters are #{self.class.extension_parameters.inspect}")
53
- end
53
+ end
54
54
  rescue Exception => e
55
55
  raise e if e.is_a? UnsupportedMarcFormatType
56
56
 
57
57
  Rails.logger.error("Blacklight failed to parse MARC record. Exception was: #{e}")
58
+ nil
58
59
  end
59
-
60
+
60
61
  def marc_record_from_marcxml
61
62
  MARC::XMLReader.new(StringIO.new( fetch(_marc_source_field) )).to_a.first
62
63
  end
63
-
64
+
64
65
  def _marc_helper
65
66
  @_marc_helper ||= (
66
67
  Blacklight::Marc::Document.new fetch(_marc_source_field), _marc_format_type )
67
68
  end
68
69
 
69
- def _marc_source_field
70
+ def _marc_source_field
70
71
  self.class.extension_parameters[:marc_source_field]
71
72
  end
72
73
 
73
74
  def _marc_format_type
74
75
  #TODO: Raise if not present
75
- self.class.extension_parameters[:marc_format_type]
76
+ self.class.extension_parameters[:marc_format_type]
76
77
  end
77
-
78
+
78
79
  end
@@ -4,13 +4,13 @@
4
4
  # it for your own custom Blacklight document Marc extension too -- just
5
5
  # include this module in any document extension (or any other class)
6
6
  # that provides a #to_marc returning a ruby-marc object. This module will add
7
- # in export_as translation methods for a variety of formats.
7
+ # in export_as translation methods for a variety of formats.
8
8
  module Blacklight::Solr::Document::MarcExport
9
-
9
+
10
10
  def self.register_export_formats(document)
11
11
  document.will_export_as(:xml)
12
12
  document.will_export_as(:marc, "application/marc")
13
- # marcxml content type:
13
+ # marcxml content type:
14
14
  # http://tools.ietf.org/html/draft-denenberg-mods-etc-media-types-00
15
15
  document.will_export_as(:marcxml, "application/marcxml+xml")
16
16
  document.will_export_as(:openurl_ctx_kev, "application/x-openurl-ctx-kev")
@@ -27,20 +27,20 @@ module Blacklight::Solr::Document::MarcExport
27
27
  to_marc.to_xml.to_s
28
28
  end
29
29
  alias_method :export_as_xml, :export_as_marcxml
30
-
31
-
30
+
31
+
32
32
  # TODO This exporting as formatted citation thing should be re-thought
33
33
  # redesigned at some point to be more general purpose, but this
34
34
  # is in-line with what we had before, but at least now attached
35
- # to the document extension where it belongs.
35
+ # to the document extension where it belongs.
36
36
  def export_as_apa_citation_txt
37
37
  apa_citation( to_marc )
38
38
  end
39
-
39
+
40
40
  def export_as_mla_citation_txt
41
41
  mla_citation( to_marc )
42
42
  end
43
-
43
+
44
44
  def export_as_chicago_citation_txt
45
45
  chicago_citation( to_marc )
46
46
  end
@@ -52,8 +52,8 @@ module Blacklight::Solr::Document::MarcExport
52
52
  # more sensibly. The "format" argument was in the old marc.marc.to_zotero
53
53
  # call, but didn't neccesarily do what it thought it did anyway. Left in
54
54
  # for now for backwards compatibilty, but should be replaced by
55
- # just ruby OpenURL.
56
- def export_as_openurl_ctx_kev(format = nil)
55
+ # just ruby OpenURL.
56
+ def export_as_openurl_ctx_kev(format = nil)
57
57
  title = to_marc.find{|field| field.tag == '245'}
58
58
  author = to_marc.find{|field| field.tag == '100'}
59
59
  corp_author = to_marc.find{|field| field.tag == '110'}
@@ -100,11 +100,13 @@ module Blacklight::Solr::Document::MarcExport
100
100
 
101
101
  # This format used to be called 'refworks', which wasn't really
102
102
  # accurate, sounds more like 'refworks tagged format'. Which this
103
- # is not, it's instead some weird under-documented Refworks
103
+ # is not, it's instead some weird under-documented Refworks
104
104
  # proprietary marc-ish in text/plain format. See
105
- # http://robotlibrarian.billdueber.com/sending-marcish-data-to-refworks/
105
+ # http://robotlibrarian.billdueber.com/2009/05/sending-marcish-data-to-refworks/
106
106
  def export_as_refworks_marc_txt
107
- fields = to_marc.find_all { |f| ('000'..'999') === f.tag }
107
+ marc_obj = to_marc
108
+ return unless marc_obj
109
+ fields = marc_obj.find_all { |f| ('000'..'999') === f.tag }
108
110
  text = "LEADER #{to_marc.leader}"
109
111
  fields.each do |field|
110
112
  unless ["940","999"].include?(field.tag)
@@ -125,9 +127,9 @@ module Blacklight::Solr::Document::MarcExport
125
127
  # it seems to want C form normalization, although RefWorks support
126
128
  # couldn't tell me that. -jrochkind
127
129
  text = ActiveSupport::Multibyte::Unicode.normalize(text, :c)
128
-
130
+
129
131
  return text
130
- end
132
+ end
131
133
 
132
134
  # Endnote Import Format. See the EndNote User Guide at:
133
135
  # http://www.endnote.com/support/enx3man-terms-win.asp
@@ -138,7 +140,7 @@ module Blacklight::Solr::Document::MarcExport
138
140
  # endnote import format; the %0 is likely to be entirely illegal, the
139
141
  # rest of the data is barely correct but messy. TODO, a new version of this,
140
142
  # or better yet just an export_as_ris instead, which will be more general
141
- # purpose.
143
+ # purpose.
142
144
  def export_as_endnote()
143
145
  end_note_format = {
144
146
  "%A" => "100.a",
@@ -154,10 +156,12 @@ module Blacklight::Solr::Document::MarcExport
154
156
  "%7" => "250.a"
155
157
  }
156
158
  marc_obj = to_marc
159
+ return unless marc_obj
160
+
157
161
  # TODO. This should be rewritten to guess
158
162
  # from actual Marc instead, probably.
159
163
  format_str = 'Generic'
160
-
164
+
161
165
  text = ''
162
166
  text << "%0 #{ format_str }\n"
163
167
  # If there is some reliable way of getting the language of a record we can add it here
@@ -170,7 +174,7 @@ module Blacklight::Solr::Document::MarcExport
170
174
  else
171
175
  second_value = []
172
176
  end
173
-
177
+
174
178
  if marc_obj[first_value[0].to_s]
175
179
  marc_obj.find_all{|f| (first_value[0].to_s) === f.tag}.each do |field|
176
180
  if field[first_value[1]].to_s or field[second_value[1]].to_s
@@ -190,11 +194,11 @@ module Blacklight::Solr::Document::MarcExport
190
194
  end
191
195
 
192
196
  protected
193
-
197
+
194
198
  # Main method for defining chicago style citation. If we don't end up converting to using a citation formatting service
195
199
  # we should make this receive a semantic document and not MARC so we can use this with other formats.
196
200
  def chicago_citation(marc)
197
- authors = get_all_authors(marc)
201
+ authors = get_all_authors(marc)
198
202
  author_text = ""
199
203
  unless authors[:primary_authors].blank?
200
204
  if authors[:primary_authors].length > 10
@@ -226,7 +230,7 @@ module Blacklight::Solr::Document::MarcExport
226
230
  author_text << "and #{name_reverse(author)}."
227
231
  else
228
232
  author_text << "#{name_reverse(author)}, "
229
- end
233
+ end
230
234
  end
231
235
  else
232
236
  author_text << authors[:primary_authors].first
@@ -242,7 +246,7 @@ module Blacklight::Solr::Document::MarcExport
242
246
  authors[:compilers].each do |compiler|
243
247
  temp_authors << [compiler, "comp."]
244
248
  end
245
-
249
+
246
250
  unless temp_authors.blank?
247
251
  if temp_authors.length > 10
248
252
  temp_authors.each_with_index do |author,index|
@@ -281,18 +285,18 @@ module Blacklight::Solr::Document::MarcExport
281
285
  section_title << "."
282
286
  end
283
287
  end
284
-
288
+
285
289
  if !authors[:primary_authors].blank? and (!authors[:translators].blank? or !authors[:editors].blank? or !authors[:compilers].blank?)
286
290
  additional_title << "Translated by #{authors[:translators].collect{|name| name_reverse(name)}.join(" and ")}. " unless authors[:translators].blank?
287
291
  additional_title << "Edited by #{authors[:editors].collect{|name| name_reverse(name)}.join(" and ")}. " unless authors[:editors].blank?
288
292
  additional_title << "Compiled by #{authors[:compilers].collect{|name| name_reverse(name)}.join(" and ")}. " unless authors[:compilers].blank?
289
293
  end
290
-
294
+
291
295
  edition = ""
292
296
  edition << setup_edition(marc) unless setup_edition(marc).nil?
293
-
297
+
294
298
  pub_info = ""
295
- if marc["260"] and (marc["260"]["a"] or marc["260"]["b"])
299
+ if marc["260"] and (marc["260"]["a"] or marc["260"]["b"])
296
300
  pub_info << clean_end_punctuation(marc["260"]["a"]).strip if marc["260"]["a"]
297
301
  pub_info << ": #{clean_end_punctuation(marc["260"]["b"]).strip}" if marc["260"]["b"]
298
302
  pub_info << ", #{setup_pub_date(marc)}" if marc["260"]["c"]
@@ -301,7 +305,7 @@ module Blacklight::Solr::Document::MarcExport
301
305
  elsif marc["502"] and (marc["502"]["b"] or marc["502"]["c"] or marc["502"]["d"]) #sometimes the dissertation note is encoded in pieces in the $b $c and $d sub fields instead of lumped into the $a
302
306
  pub_info << "#{marc["502"]["b"]}, #{marc["502"]["c"]}, #{clean_end_punctuation(marc["502"]["d"])}"
303
307
  end
304
-
308
+
305
309
  citation = ""
306
310
  citation << "#{author_text} " unless author_text.blank?
307
311
  citation << "<i>#{title}.</i> " unless title.blank?
@@ -311,13 +315,13 @@ module Blacklight::Solr::Document::MarcExport
311
315
  citation << "#{pub_info}." unless pub_info.blank?
312
316
  citation
313
317
  end
314
-
315
-
316
-
318
+
319
+
320
+
317
321
  def mla_citation(record)
318
322
  text = ''
319
323
  authors_final = []
320
-
324
+
321
325
  #setup formatted author list
322
326
  authors = get_author_list(record)
323
327
 
@@ -351,10 +355,10 @@ module Blacklight::Solr::Document::MarcExport
351
355
  # Edition
352
356
  edition_data = setup_edition(record)
353
357
  text += edition_data + " " unless edition_data.nil?
354
-
358
+
355
359
  # Publication
356
360
  text += setup_pub_info(record) + ", " unless setup_pub_info(record).nil?
357
-
361
+
358
362
  # Get Pub Date
359
363
  text += setup_pub_date(record) unless setup_pub_date(record).nil?
360
364
  if text[-1,1] != "."
@@ -367,7 +371,7 @@ module Blacklight::Solr::Document::MarcExport
367
371
  text = ''
368
372
  authors_list = []
369
373
  authors_list_final = []
370
-
374
+
371
375
  #setup formatted author list
372
376
  authors = get_author_list(record)
373
377
  authors.each do |l|
@@ -392,15 +396,15 @@ module Blacklight::Solr::Document::MarcExport
392
396
  end
393
397
  # Get Pub Date
394
398
  text += "(" + setup_pub_date(record) + "). " unless setup_pub_date(record).nil?
395
-
399
+
396
400
  # setup title info
397
401
  title = setup_title_info(record)
398
402
  text += "<i>" + title + "</i> " unless title.nil?
399
-
403
+
400
404
  # Edition
401
405
  edition_data = setup_edition(record)
402
406
  text += edition_data + " " unless edition_data.nil?
403
-
407
+
404
408
  # Publisher info
405
409
  text += setup_pub_info(record) unless setup_pub_info(record).nil?
406
410
  unless text.blank?
@@ -451,7 +455,7 @@ module Blacklight::Solr::Document::MarcExport
451
455
  end
452
456
  new_text.join(" ")
453
457
  end
454
-
458
+
455
459
  # This will replace the mla_citation_title method with a better understanding of how MLA and Chicago citation titles are formatted.
456
460
  # This method will take in a string and capitalize all of the non-prepositions.
457
461
  def citation_title(title_text)
@@ -482,18 +486,18 @@ module Blacklight::Solr::Document::MarcExport
482
486
  end
483
487
  text += b_title_info unless b_title_info.nil?
484
488
  end
485
-
489
+
486
490
  return nil if text.strip.blank?
487
491
  clean_end_punctuation(text.strip) + "."
488
-
492
+
489
493
  end
490
-
494
+
491
495
  def clean_end_punctuation(text)
492
496
  if [".",",",":",";","/"].include? text[-1,1]
493
497
  return text[0,text.length-1]
494
498
  end
495
499
  text
496
- end
500
+ end
497
501
 
498
502
  def setup_edition(record)
499
503
  edition_field = record.find{|f| f.tag == '250'}
@@ -503,9 +507,9 @@ module Blacklight::Solr::Document::MarcExport
503
507
  return nil
504
508
  else
505
509
  return edition_data
506
- end
510
+ end
507
511
  end
508
-
512
+
509
513
  def get_author_list(record)
510
514
  author_list = []
511
515
  authors_primary = record.find{|f| f.tag == '100'}
@@ -517,11 +521,11 @@ module Blacklight::Solr::Document::MarcExport
517
521
  author_list.push(clean_end_punctuation(l.find{|s| s.code == 'a'}.value)) unless l.find{|s| s.code == 'a'}.value.nil?
518
522
  end
519
523
  end
520
-
524
+
521
525
  author_list.uniq!
522
526
  author_list
523
527
  end
524
-
528
+
525
529
  # This is a replacement method for the get_author_list method. This new method will break authors out into primary authors, translators, editors, and compilers
526
530
  def get_all_authors(record)
527
531
  translator_code = "trl"; editor_code = "edt"; compiler_code = "com"
@@ -547,7 +551,7 @@ module Blacklight::Solr::Document::MarcExport
547
551
  end
548
552
  {:primary_authors => primary_authors, :translators => translators, :editors => editors, :compilers => compilers}
549
553
  end
550
-
554
+
551
555
  def abbreviate_name(name)
552
556
  name_parts = name.split(", ")
553
557
  first_name_parts = name_parts.last.split(" ")
@@ -562,6 +566,5 @@ module Blacklight::Solr::Document::MarcExport
562
566
  return name unless name =~ /,/
563
567
  temp_name = name.split(", ")
564
568
  return temp_name.last + " " + temp_name.first
565
- end
566
-
567
- end
569
+ end
570
+ end