blacklight-ris 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +81 -0
- data/Rakefile +37 -0
- data/app/helpers/blacklight_ris_helper.rb +17 -0
- data/app/models/concerns/blacklight/solr/document/ris_export.rb +37 -0
- data/app/models/concerns/blacklight/solr/document/ris_fields.rb +12 -0
- data/app/views/bookmarks/index.ris.erb +1 -0
- data/config/routes.rb +2 -0
- data/lib/blacklight/ris/catalog.rb +21 -0
- data/lib/blacklight/ris/engine.rb +16 -0
- data/lib/blacklight/ris/version.rb +5 -0
- data/lib/blacklight/ris.rb +8 -0
- data/lib/tasks/blacklight/ris_tasks.rake +4 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1a8d3a0519f3934e4ebddfdee72cc123c323bc0ec8085223d81cf093f4cd9f1b
|
4
|
+
data.tar.gz: 87422585dffe4625444aa94964cc54bd8e63431a560c20fb3bc2d33befdae2cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5608cfed0c79ae83532160aeeb67191ad6c55f7dd2b6fc7700965b191d8824076c31a062acc91b9bd7de1497f3b78a9be9d3bce7c270051090faad4773f8d332
|
7
|
+
data.tar.gz: 0ab726f67034f0465017cc5c9f20a35424c16e5dd7068e43b7dacd0f49690bc225630748e3706d1d05b4fa6d5b11705a057c81a8503e7144433ca3d04210b949
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Jeff Chiu
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# blacklight-ris
|
2
|
+
|
3
|
+
Adds "Download in RIS format" functionality to [Blacklight](https://github.com/projectblacklight/blacklight).
|
4
|
+
|
5
|
+
## Description
|
6
|
+
Blacklight plugin that adds the ability to download a [RIS representation](https://en.wikipedia.org/wiki/RIS_(file_format)) of a record from a catalog show page and a set of records from the bookmarks index page.
|
7
|
+
|
8
|
+
### Versioning
|
9
|
+
`v0.1.0` -> Known to work with Blacklight v6 and Rails 4
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'blacklight-ris', '0.1.0'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
```bash
|
21
|
+
$ bundle install
|
22
|
+
```
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Modify your `SolrDocument` class with the extension modules for RIS,
|
27
|
+
and define your field mappings using the `ris_field_mappings` hash.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class SolrDocument
|
31
|
+
|
32
|
+
# ...existing code...
|
33
|
+
|
34
|
+
include Blacklight::Solr::Document::RisFields
|
35
|
+
use_extension(Blacklight::Solr::Document::RisExport)
|
36
|
+
|
37
|
+
ris_field_mappings.merge!(
|
38
|
+
# Procs are evaluated in context of SolrDocument instance
|
39
|
+
:TY => Proc.new {
|
40
|
+
format = fetch('format_a', [])
|
41
|
+
if format.member?('Book')
|
42
|
+
'BOOK'
|
43
|
+
elsif format.member?('Journal/Periodical')
|
44
|
+
'JOUR'
|
45
|
+
else
|
46
|
+
'GEN'
|
47
|
+
end
|
48
|
+
},
|
49
|
+
# use solr field named 'title'
|
50
|
+
:TI => 'title',
|
51
|
+
:AU => 'author_creator_a',
|
52
|
+
:PY => 'publication_date_a',
|
53
|
+
# this assumes you're using blacklight-marc
|
54
|
+
:CY => Proc.new { marclibrary.get_ris_cy_field(to_marc) },
|
55
|
+
:PB => Proc.new { marclibrary.get_ris_pb_field(to_marc) },
|
56
|
+
:ET => 'edition',
|
57
|
+
:SN => Proc.new { marclibrary.get_ris_sn_field(to_marc) },
|
58
|
+
)
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
Modify your `CatalogController` to include the
|
63
|
+
`Blacklight::Ris::Catalog` module. Put this at the end of any existing
|
64
|
+
includes.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
class CatalogController < ApplicationController
|
68
|
+
# ...existing includes...
|
69
|
+
include Blacklight::Catalog
|
70
|
+
|
71
|
+
# add this line
|
72
|
+
include Blacklight::Ris::Catalog
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
The show view and bookmarks page should now display links for
|
77
|
+
downloading records in RIS format.
|
78
|
+
|
79
|
+
## License
|
80
|
+
|
81
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Blacklight::Ris'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task default: :test
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
module BlacklightRisHelper
|
3
|
+
|
4
|
+
# this helper is called from the Show view and Bookmarks view
|
5
|
+
def ris_path(opts = {})
|
6
|
+
if controller_name == "bookmarks"
|
7
|
+
bookmarks_path(opts.merge(format: 'ris'))
|
8
|
+
else
|
9
|
+
solr_document_path(opts.merge(format: 'ris'))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def render_ris(documents)
|
14
|
+
documents.map {|x| x.export_as(:ris)}.compact.join("\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
module Blacklight::Solr::Document::RisExport
|
3
|
+
|
4
|
+
def self.extended(document)
|
5
|
+
document.will_export_as(:ris, 'application/x-research-info-systems')
|
6
|
+
end
|
7
|
+
|
8
|
+
def export_as_ris
|
9
|
+
ris_hash = to_ris_hash
|
10
|
+
lines = ris_hash.keys
|
11
|
+
.select { |key| ris_hash[key].present? }
|
12
|
+
.flat_map { |key| render_ris_key_value(key, ris_hash[key]) }
|
13
|
+
lines << 'ER - '
|
14
|
+
lines.compact.join("\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
def render_ris_key_value(key, val)
|
18
|
+
if val.is_a?(Array)
|
19
|
+
val.map { |v| "#{key} - #{v}" }
|
20
|
+
else
|
21
|
+
"#{key} - #{val}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_ris_hash
|
26
|
+
h = Hash.new
|
27
|
+
self.class.ris_field_mappings.each do |key, val|
|
28
|
+
if val.is_a?(Proc)
|
29
|
+
h[key] = instance_eval(&val)
|
30
|
+
else
|
31
|
+
h[key] = fetch(val, '')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
h
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render_ris(@document_list) %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
module Blacklight::Ris
|
3
|
+
|
4
|
+
# mix-in for CatalogController
|
5
|
+
module Catalog
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
# this also causes Blacklight's show endpoint to handle .ris
|
10
|
+
add_show_tools_partial(:ris, label: 'Download in RIS format', if: :render_ris_action?, modal: false, path: :ris_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def render_ris_action? config, options = {}
|
16
|
+
doc = options[:document] || (options[:document_list] || []).first
|
17
|
+
doc && doc.respond_to?(:export_formats) && doc.export_formats.keys.include?(:ris )
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Blacklight
|
2
|
+
module Ris
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
isolate_namespace Blacklight::Ris
|
5
|
+
|
6
|
+
initializer 'blacklight-ris.initialize' do |app|
|
7
|
+
Mime::Type.register 'application/x-research-info-systems', :ris
|
8
|
+
end
|
9
|
+
|
10
|
+
initializer 'blacklight-ris.helpers' do |app|
|
11
|
+
ActionView::Base.send :include, BlacklightRisHelper
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blacklight-ris
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Chiu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
description: RIS format export for Blacklight
|
28
|
+
email:
|
29
|
+
- jeffchiu@upenn.edu
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- app/helpers/blacklight_ris_helper.rb
|
38
|
+
- app/models/concerns/blacklight/solr/document/ris_export.rb
|
39
|
+
- app/models/concerns/blacklight/solr/document/ris_fields.rb
|
40
|
+
- app/views/bookmarks/index.ris.erb
|
41
|
+
- config/routes.rb
|
42
|
+
- lib/blacklight/ris.rb
|
43
|
+
- lib/blacklight/ris/catalog.rb
|
44
|
+
- lib/blacklight/ris/engine.rb
|
45
|
+
- lib/blacklight/ris/version.rb
|
46
|
+
- lib/tasks/blacklight/ris_tasks.rake
|
47
|
+
homepage: https://github.com/upenn-libraries/blacklight-ris
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata:
|
51
|
+
rubygems_mfa_required: 'false'
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubygems_version: 3.0.3.1
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: RIS format export for Blacklight
|
71
|
+
test_files: []
|