blacklight-marc 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +19 -0
  4. data/Gemfile +15 -0
  5. data/LICENSE +15 -0
  6. data/README.md +40 -0
  7. data/Rakefile +68 -0
  8. data/app/helpers/blacklight_marc_helper.rb +24 -0
  9. data/app/views/bookmarks/_endnote.html.erb +3 -0
  10. data/app/views/bookmarks/_refworks.html.erb +3 -0
  11. data/app/views/catalog/_marc_view.html.erb +32 -0
  12. data/app/views/catalog/endnote.endnote.erb +1 -0
  13. data/app/views/catalog/librarian_view.html.erb +10 -0
  14. data/blacklight-marc.gemspec +31 -0
  15. data/config/jetty.yml +4 -0
  16. data/config/locales/blacklight.en.yml +13 -0
  17. data/config/locales/blacklight.fr.yml +13 -0
  18. data/config/routes.rb +17 -0
  19. data/lib/SolrMarc.jar +0 -0
  20. data/lib/blacklight/marc.rb +18 -0
  21. data/lib/blacklight/marc/catalog.rb +20 -0
  22. data/lib/blacklight/marc/engine.rb +8 -0
  23. data/lib/blacklight/marc/railtie.rb +17 -0
  24. data/lib/blacklight/marc/routes.rb +43 -0
  25. data/lib/blacklight/marc/version.rb +5 -0
  26. data/lib/blacklight/solr/document/marc.rb +72 -0
  27. data/lib/blacklight/solr/document/marc_export.rb +587 -0
  28. data/lib/generators/blacklight_marc/marc_generator.rb +57 -0
  29. data/lib/generators/blacklight_marc/templates/config/SolrMarc/config-test.properties +37 -0
  30. data/lib/generators/blacklight_marc/templates/config/SolrMarc/config.properties +37 -0
  31. data/lib/generators/blacklight_marc/templates/config/SolrMarc/index.properties +97 -0
  32. data/lib/generators/blacklight_marc/templates/config/SolrMarc/index_scripts/dewey.bsh +47 -0
  33. data/lib/generators/blacklight_marc/templates/config/SolrMarc/index_scripts/format.bsh +126 -0
  34. data/lib/generators/blacklight_marc/templates/config/SolrMarc/translation_maps/README_MAPS +1 -0
  35. data/lib/generators/blacklight_marc/templates/config/SolrMarc/translation_maps/callnumber_map.properties +407 -0
  36. data/lib/generators/blacklight_marc/templates/config/SolrMarc/translation_maps/composition_era_map.properties +56 -0
  37. data/lib/generators/blacklight_marc/templates/config/SolrMarc/translation_maps/country_map.properties +379 -0
  38. data/lib/generators/blacklight_marc/templates/config/SolrMarc/translation_maps/format_map.properties +50 -0
  39. data/lib/generators/blacklight_marc/templates/config/SolrMarc/translation_maps/instrument_map.properties +101 -0
  40. data/lib/generators/blacklight_marc/templates/config/SolrMarc/translation_maps/language_map.properties +490 -0
  41. data/lib/railties/solr_marc.rake +158 -0
  42. data/spec/controllers/catalog_controller_spec.rb +23 -0
  43. data/spec/features/librarian_view_spec.rb +13 -0
  44. data/spec/helpers/blacklight_marc_helper_spec.rb +26 -0
  45. data/spec/integration/solr_document_spec.rb +59 -0
  46. data/spec/lib/blacklight_solr_document_marc_spec.rb +89 -0
  47. data/spec/lib/marc_export_spec.rb +743 -0
  48. data/spec/lib/tasks/solr_marc_task_spec.rb +60 -0
  49. data/spec/routing/routes_spec.rb +16 -0
  50. data/spec/spec_helper.rb +27 -0
  51. data/spec/test_app_templates/Gemfile.extra +21 -0
  52. data/spec/test_app_templates/lib/generators/test_app_generator.rb +35 -0
  53. data/spec/test_app_templates/lib/tasks/blacklight_test_app.rake +14 -0
  54. data/spec/views/bookmarks/_endnote.html.erb_spec.rb +9 -0
  55. data/spec/views/bookmarks/_refworks.html.erb_spec.rb +10 -0
  56. data/test_support/data/test_data.utf8.mrc +1 -0
  57. metadata +231 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1d908859e48042b0e0b642132ae5ddfbf981897f
4
+ data.tar.gz: 8120bcb5ea2d3d1735bde7396193e5dfc1aa68d4
5
+ SHA512:
6
+ metadata.gz: 9c4e5a0134edfbe5f648dab763a857df5e7797cf664f607379ce6e45e2170b1b7a5279a2482706f88337d4c5d3e3ea6d6fef400016e2b4a9e3cb7e9a3b6d9495
7
+ data.tar.gz: ced6d727659b9f0e2bad8f969d5f840a7a614f50fc8c65c660024768f4a9ae7c041fad71f625729b0b7076938881bc5469ff9f4b9b1058170a89ea2ba6eacadd
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ lib/solrmarc.log
19
+ spec/internal
20
+ jetty
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ notifications:
2
+ email: false
3
+
4
+ rvm:
5
+ - 2.1.0
6
+ - 2.0.0
7
+ - 1.9.3
8
+ - jruby-19mode
9
+
10
+ before_install:
11
+ - gem install bundler
12
+
13
+ notifications:
14
+ irc: "irc.freenode.org#blacklight"
15
+ email:
16
+ - blacklight-commits@googlegroups.com
17
+ env:
18
+ global:
19
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in blacklight_marc.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'devise'
8
+ gem "bootstrap-sass"
9
+ gem 'turbolinks'
10
+ gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
11
+ end
12
+
13
+ if File.exists?('spec/test_app_templates/Gemfile.extra')
14
+ eval File.read('spec/test_app_templates/Gemfile.extra'), nil, 'spec/test_app_templates/Gemfile.extra'
15
+ end
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ##########################################################################
2
+ # Copyright 2008-2014 Rector and Visitors of the University of Virginia, The Board of Trustees of the Leland Stanford Junior University, Johns Hopkins Universities, and Data Curation Experts
3
+ # Additional copyright may be held by others, as reflected in the commit log
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ [![Build Status](https://travis-ci.org/projectblacklight/blacklight_marc.png?branch=master)](https://travis-ci.org/projectblacklight/blacklight_marc)
2
+
3
+ # Blacklight::Marc
4
+
5
+ MARC-specific enhancements for [Blacklight](https://github.com/projectblacklight/blacklight)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'blacklight-marc'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ After running the blacklight generator, run the blacklight_marc generator:
18
+
19
+ $ rails generate blacklight_marc:marc
20
+
21
+ ## Features
22
+ * Rake task `solr:marc:index` to import .mrc files using SolrMarc
23
+ * Librarian view at `catalog/:id/librarian_view`
24
+ * Export records to refworks and endnote
25
+ * Blacklight::Solr::Document mixins for exporting and transforming MARC data from a stored Solr field
26
+
27
+
28
+ ## Documentation, Information and Support
29
+
30
+ * [Project Homepage](http://projectblacklight.org)
31
+ * [Developer Documentation](https://github.com/projectblacklight/blacklight/wiki)
32
+ * [Quickstart Guide](https://github.com/projectblacklight/blacklight/wiki/Quickstart)
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,68 @@
1
+ require "bundler/gem_tasks"
2
+ ZIP_URL = "https://github.com/projectblacklight/blacklight-jetty/archive/v4.0.0.zip"
3
+ APP_ROOT = File.expand_path("..", __FILE__)
4
+
5
+ TEST_APP_TEMPLATES = 'spec/test_app_templates'
6
+ TEST_APP = 'spec/internal'
7
+
8
+ require 'jettywrapper'
9
+ require 'rspec/core/rake_task'
10
+
11
+ RSpec::Core::RakeTask.new(:spec)
12
+
13
+ task :default => [:ci]
14
+
15
+ task :ci => ['blacklight_marc:generate', 'jetty:clean'] do
16
+ ENV['environment'] = "test"
17
+ jetty_params = Jettywrapper.load_config
18
+ jetty_params[:startup_wait]= 60
19
+ error = Jettywrapper.wrap(jetty_params) do
20
+ Rake::Task["blacklight_marc:fixtures"].invoke
21
+ Rake::Task['spec'].invoke
22
+ end
23
+ raise "test failures: #{error}" if error
24
+ end
25
+
26
+
27
+ namespace :blacklight_marc do
28
+
29
+ desc "Load fixtures"
30
+ task :fixtures => [:generate] do
31
+ within_test_app do
32
+ system "rake solr:marc:index_test_data RAILS_ENV=test"
33
+ abort "Error running fixtures" unless $?.success?
34
+ end
35
+ end
36
+
37
+ desc "Create the test rails app"
38
+ task :generate do
39
+ unless File.exists?('spec/internal/Rakefile')
40
+ puts "Generating rails app"
41
+ `rails new #{TEST_APP}`
42
+ puts "Copying gemfile"
43
+ open("#{TEST_APP}/Gemfile", 'a') do |f|
44
+ f.write File.read(TEST_APP_TEMPLATES + "/Gemfile.extra")
45
+ f.write "gem 'blacklight-marc', :path => '../../'"
46
+ end
47
+ puts "Copying generator"
48
+ `cp -r #{TEST_APP_TEMPLATES}/lib/generators #{TEST_APP}/lib`
49
+ within_test_app do
50
+ puts "Bundle install"
51
+ `bundle install`
52
+ puts "running test_app_generator"
53
+ system "rails generate test_app"
54
+
55
+ puts "running migrations"
56
+ puts `rake db:migrate db:test:prepare`
57
+ end
58
+ end
59
+ puts "Done generating test app"
60
+ end
61
+ end
62
+ def within_test_app
63
+ FileUtils.cd(TEST_APP)
64
+ Bundler.with_clean_env do
65
+ yield
66
+ end
67
+ FileUtils.cd(APP_ROOT)
68
+ end
@@ -0,0 +1,24 @@
1
+ module BlacklightMarcHelper
2
+
3
+ # puts together a collection of documents into one refworks export string
4
+ def render_refworks_texts(documents)
5
+ val = ''
6
+ documents.each do |doc|
7
+ if doc.respond_to?(:to_marc)
8
+ val += doc.export_as_refworks_marc_txt + "\n"
9
+ end
10
+ end
11
+ val
12
+ end
13
+
14
+ # puts together a collection of documents into one endnote export string
15
+ def render_endnote_texts(documents)
16
+ val = ''
17
+ documents.each do |doc|
18
+ if doc.respond_to?(:to_marc)
19
+ val += doc.export_as_endnote + "\n"
20
+ end
21
+ end
22
+ val
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ <li class="endnote">
2
+ <%= link_to t('blacklight.tools.endnote'), endnote_catalog_path(:sort=>params[:sort], :per_page=>params[:per_page], :id => @bookmarks.collect {|doc| doc.document_id}, :format => 'endnote'), {:class => 'btn btn-default'}%>
3
+ </li>
@@ -0,0 +1,3 @@
1
+ <li class="refworks">
2
+ <%= render :partial => 'catalog/refworks_form', :locals => {:documents=>@document_list} %>
3
+ </li>
@@ -0,0 +1,32 @@
1
+ <div id="marc_view" class="modal-body">
2
+ <% fields = @document.to_marc.find_all{|f| ('000'..'999') === f.tag } %>
3
+ <div class="field"><%= t('blacklight.search.librarian_view.leader', :leader => @document.to_marc.leader) %></div>
4
+ <%- fields.each do |field| -%>
5
+ <%- unless field.tag.to_s == "940" -%>
6
+ <div class="field">
7
+ <div class="tag_ind">
8
+ <span class="tag">
9
+ <%= h(field.tag) %>
10
+ </span>
11
+ <%- if field.is_a?(MARC::ControlField) -%>
12
+ <span class="control_field_values">
13
+ <%= h(field.value) %>
14
+ </span>
15
+ <%- else -%>
16
+ <div class="ind1">
17
+ <%= !field.indicator1.blank? ? field.indicator1 : "&nbsp;&nbsp;".html_safe -%>
18
+ </div>
19
+ <div class="ind2">
20
+ <%= !field.indicator2.blank? ? field.indicator2 : "&nbsp;&nbsp;".html_safe -%>
21
+ </div>
22
+ </div>
23
+ <div class="subfields">
24
+ <%- field.each do |sub| -%>
25
+ <span class="sub_code"><%= h(sub.code) %>|</span> <%= h(sub.value) %>
26
+ <%- end -%>
27
+ <%- end -%>
28
+ </div>
29
+ </div>
30
+ <%- end-%>
31
+ <%- end -%>
32
+ </div>
@@ -0,0 +1 @@
1
+ <%= render_endnote_texts(@documents) %>
@@ -0,0 +1,10 @@
1
+
2
+ <div class="modal-header">
3
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
4
+ <h3 class="modal-title"><%= t('blacklight.search.librarian_view.title') %></h3>
5
+ </div>
6
+ <%- if @document.respond_to?(:to_marc) -%>
7
+ <%= render "marc_view" %>
8
+ <%- else %>
9
+ <%= t('blacklight.search.librarian_view.empty') %>
10
+ <%- end -%>
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'blacklight/marc/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "blacklight-marc"
7
+ spec.version = Blacklight::Marc::VERSION
8
+ spec.authors = ["Justin Coyne"]
9
+ spec.email = ["justin@curationexperts.com"]
10
+ spec.description = %q{MARC support for Blacklight}
11
+ spec.summary = %q{MARC support for Blacklight}
12
+ spec.homepage = "https://github.com/projectblacklight/blacklight_marc"
13
+ spec.license = "Apache 2.0"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "blacklight", "~> 5.0"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rspec-rails"
26
+ spec.add_development_dependency "jettywrapper"
27
+ spec.add_dependency "rails"
28
+ # Let's allow future versions of marc, count on
29
+ # them to be backwards compat until 1.1
30
+ spec.add_dependency "marc", ">= 0.4.3", "< 1.1" # Marc record parser.
31
+ end
data/config/jetty.yml ADDED
@@ -0,0 +1,4 @@
1
+ default:
2
+ startup_wait: 15
3
+ jetty_port: <%= ENV['TEST_JETTY_PORT'] || 8888 %>
4
+ <%= ENV['TEST_JETTY_PATH'] ? "jetty_home: " + ENV['TEST_JETTY_PATH'] : '' %>
@@ -0,0 +1,13 @@
1
+ en:
2
+
3
+ blacklight:
4
+ tools:
5
+ librarian_view: 'Librarian View'
6
+
7
+
8
+ search:
9
+ librarian_view:
10
+ title: 'Librarian View'
11
+ leader: 'LEADER %{leader}'
12
+ empty: 'No MARC data found.'
13
+
@@ -0,0 +1,13 @@
1
+ fr:
2
+
3
+ blacklight:
4
+
5
+ tools:
6
+ librarian_view: 'Vue UNIMARC'
7
+
8
+ search:
9
+
10
+ librarian_view:
11
+ title: 'Vue UNIMARC'
12
+ leader: 'LABEL %{leader}'
13
+ empty: 'Pas MARC trouvé.'
data/config/routes.rb ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding : utf-8 -*-
2
+ Rails.application.routes.draw do
3
+ # A Note on User Sessions:
4
+ # Blacklight expects the following named routes or at least the associated path helper methods to be defined.
5
+ # new_user_session (for logging in) - pages that require a log in will redirect users here.
6
+ # destroy_user_session (for logging out)
7
+
8
+ # Routes for the Blacklight application are defined in Blacklight::Routes
9
+ #
10
+ # These routes can be injected into your Rails application by adding
11
+ # Blacklight.add_routes(self)
12
+ # to the application's ./config/routes.rb. The injected routes can be
13
+ # customized as well, e.g.:
14
+ # Blacklight.add_routes(self, :only => [:bookmarks]) # will only look bookmark routes
15
+ # Blacklight.add_routes(self, :except => [:catalog]) # will not load catalog routes
16
+ end
17
+
data/lib/SolrMarc.jar ADDED
Binary file
@@ -0,0 +1,18 @@
1
+ require "blacklight/marc/version"
2
+ require 'blacklight'
3
+
4
+ module Blacklight
5
+ module Marc
6
+ Blacklight::Solr::Document.autoload :Marc, 'blacklight/solr/document/marc'
7
+ Blacklight::Solr::Document.autoload :MarcExport, 'blacklight/solr/document/marc_export'
8
+
9
+ require 'blacklight/marc/engine'
10
+ require 'blacklight/marc/railtie'
11
+ autoload :Routes, 'blacklight/marc/routes'
12
+ autoload :Catalog, 'blacklight/marc/catalog'
13
+
14
+ def self.add_routes(router, options = {})
15
+ Blacklight::Marc::Routes.new(router, options).draw
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ module Blacklight::Marc
2
+ module Catalog
3
+ def librarian_view
4
+ @response, @document = get_solr_response_for_doc_id
5
+
6
+ respond_to do |format|
7
+ format.html
8
+ format.js { render :layout => false }
9
+ end
10
+ end
11
+
12
+ # grabs a bunch of documents to export to endnote
13
+ def endnote
14
+ @response, @documents = get_solr_response_for_field_values(SolrDocument.unique_key,params[:id])
15
+ respond_to do |format|
16
+ format.endnote { render :layout => false }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ require "blacklight/marc"
2
+ require "rails"
3
+
4
+ module Blacklight::Marc
5
+ class Engine < Rails::Engine
6
+
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ module Blacklight::Marc
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ load "railties/solr_marc.rake"
5
+ end
6
+
7
+ initializer 'blacklight_marc.initialize' do |app|
8
+ Mime::Type.register_alias "text/plain", :refworks_marc_txt
9
+ Mime::Type.register_alias "text/plain", :openurl_kev
10
+ Mime::Type.register "application/x-endnote-refer", :endnote
11
+ Mime::Type.register "application/marc", :marc
12
+ Mime::Type.register "application/marcxml+xml", :marcxml,
13
+ ["application/x-marc+xml", "application/x-marcxml+xml",
14
+ "application/marc+xml"]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Blacklight::Marc
3
+ class Routes
4
+
5
+ def initialize(router, options)
6
+ @router = router
7
+ @options = options
8
+ end
9
+
10
+ def draw
11
+ route_sets.each do |r|
12
+ self.send(r)
13
+ end
14
+ end
15
+
16
+ protected
17
+
18
+ def add_routes &blk
19
+ @router.instance_exec(@options, &blk)
20
+ end
21
+
22
+ def route_sets
23
+ (@options[:only] || default_route_sets) - (@options[:except] || [])
24
+ end
25
+
26
+ def default_route_sets
27
+ [:catalog]
28
+ end
29
+
30
+ module RouteSets
31
+ def catalog
32
+ add_routes do |options|
33
+ # Catalog stuff.
34
+ get 'catalog/:id/librarian_view', :to => "catalog#librarian_view", :as => "librarian_view_catalog"
35
+ get "catalog/endnote", :as => "endnote_catalog"
36
+
37
+ end
38
+ end
39
+ end
40
+
41
+ include RouteSets
42
+ end
43
+ end