blacklight-citeproc 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +86 -0
- data/app/controllers/blacklight/citeproc/citation_controller.rb +37 -0
- data/app/models/concerns/blacklight/document/bibtex.rb +56 -0
- data/app/views/blacklight/citeproc/citation/print_single.html.erb +6 -0
- data/blacklight-citeproc.gemspec +33 -0
- data/config/locales/blacklight-citeproc.en.yml +5 -0
- data/config/routes.rb +3 -0
- data/lib/blacklight/citeproc.rb +6 -0
- data/lib/blacklight/citeproc/engine.rb +6 -0
- data/lib/blacklight/citeproc/version.rb +5 -0
- data/lib/generators/blacklight/citeproc/install_generator.rb +45 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 58728c3ed06908d2c5fea28545abcef6d99e57dc65c783b59b9f94f036f2b6f7
|
4
|
+
data.tar.gz: b3489bf8ab8a75996200af7dcf440a1b23911533d01841ac1880d2cd1dbc823f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 91d78c9b8154b1bf72d80dea5e24eaee1f129a5ab6532728853804d555eb947eaee46b4b133cd8b8fa6704c15ec9f8e10fce1fe0eb32c6f1b7d799f6d49c40aa
|
7
|
+
data.tar.gz: ceb6103e2cb503ebb91e6c4ce21e0529ab3d2ccc0018397f68a1cc922c1f96a460ab07b0c332dd9a925ab6c9b12208f56fc8b671e884ddfaeebbd495905f658b
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Blacklight::Citeproc
|
2
|
+
Swap in really accurate citations using a wide variety of citation styles to your Blacklight app.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'blacklight-citeproc'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
```bash
|
13
|
+
$ bundle
|
14
|
+
```
|
15
|
+
|
16
|
+
And then run the install generator:
|
17
|
+
```bash
|
18
|
+
$ rails generate blacklight:citeproc:install
|
19
|
+
```
|
20
|
+
|
21
|
+
Go into your application's catalog controller, and set the correct fields:
|
22
|
+
```ruby
|
23
|
+
config.citeproc = {
|
24
|
+
bibtex_field: 'bibtex_s' # Optional. If you are already indexing BibTeX into solr, this will be the preferred way to get bibliographic data
|
25
|
+
# If no bibtex_field defined, or if it is not found in the solr document, use these fields instead:
|
26
|
+
fields: {
|
27
|
+
address: 'published_ssm',
|
28
|
+
annote: 'annotation_tsim',
|
29
|
+
author: 'author_tsim',
|
30
|
+
booktitle: 'booktitle_tsim',
|
31
|
+
chapter: 'chapter_tsim',
|
32
|
+
doi: 'doi_tsim',
|
33
|
+
edition: 'edition_tsim',
|
34
|
+
editor: 'editor_tsim',
|
35
|
+
how_published: 'how_published_tsim',
|
36
|
+
institution: 'institution_tsim',
|
37
|
+
journal: 'journal_tsim',
|
38
|
+
key: 'id',
|
39
|
+
month: 'month_tsim',
|
40
|
+
note: 'note_tsim',
|
41
|
+
number: 'number_tsim',
|
42
|
+
organization: 'organization_tsim',
|
43
|
+
pages: 'pages_tsim',
|
44
|
+
publisher: 'publisher_tsim',
|
45
|
+
school: 'school_tsim',
|
46
|
+
series: 'series_tsim',
|
47
|
+
title: 'title_tsim',
|
48
|
+
type: 'type_tsim',
|
49
|
+
url: 'url_tsim',
|
50
|
+
volume: 'number_tsim',
|
51
|
+
year: 'pub_date_ssim'
|
52
|
+
},
|
53
|
+
styles: %w(apa chicago-fullnote-bibliography modern-language-association ieee council-of-science-editors),
|
54
|
+
format: {
|
55
|
+
field: format
|
56
|
+
default_format: :book
|
57
|
+
mappings: {
|
58
|
+
article: [],
|
59
|
+
book: ['Book', 'Musical Score', 'Ebook'],
|
60
|
+
booklet: [],
|
61
|
+
conference: [],
|
62
|
+
inbook: [],
|
63
|
+
incollection: [],
|
64
|
+
inproceedings: [],
|
65
|
+
manual: [],
|
66
|
+
mastersthesis: [],
|
67
|
+
misc: ['Map/Globe', 'Non-musical Recording', 'Musical Recording', 'Image', 'Software/Data', 'Video/Film'],
|
68
|
+
phdthesis: [],
|
69
|
+
proceedings: [],
|
70
|
+
techreport: [],
|
71
|
+
unpublished: []
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
```
|
76
|
+
|
77
|
+
Finally, go into your locale files and make sure to add friendly versions of the citations styles you are using for each locale your app uses.
|
78
|
+
|
79
|
+
```yaml
|
80
|
+
en:
|
81
|
+
blacklight:
|
82
|
+
citeproc:
|
83
|
+
styles:
|
84
|
+
apa: APA 6th Edition
|
85
|
+
```
|
86
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'bibtex'
|
2
|
+
require 'citeproc'
|
3
|
+
require 'csl/styles'
|
4
|
+
|
5
|
+
module Blacklight::Citeproc
|
6
|
+
class BadConfigError < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
class CitationController < ApplicationController
|
10
|
+
include Blacklight::Searchable
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@processors = []
|
14
|
+
@citations = []
|
15
|
+
|
16
|
+
throw BadConfigError, 'Catalog controller needs a config.citeproc section' unless blacklight_config.citeproc
|
17
|
+
@config = blacklight_config.citeproc
|
18
|
+
@config[:styles].each do |style|
|
19
|
+
@processors << ::CiteProc::Processor.new(format: 'html', style: style)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def print_single
|
24
|
+
_, document = search_service.fetch(params[:id])
|
25
|
+
bibtex = ::BibTeX::Bibliography.new
|
26
|
+
bibtex << document.export_as(:bibtex)
|
27
|
+
|
28
|
+
@processors.each do |processor|
|
29
|
+
processor.import bibtex.to_citeproc
|
30
|
+
citation = processor.render(:bibliography, id: params[:id]).first.tr('{}', '')
|
31
|
+
@citations << {citation: citation.html_safe, label: processor.options[:style]}
|
32
|
+
end
|
33
|
+
render layout: false
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# This is a document extension meant to be mixed into a
|
2
|
+
# Blacklight::Solr::Document class, such as SolrDocument. It provides support
|
3
|
+
# for creating bibtex format from a Solr document.
|
4
|
+
#
|
5
|
+
# This extension would normally be registered using
|
6
|
+
# Blacklight::Solr::Document#use_extension. eg:
|
7
|
+
#
|
8
|
+
# SolrDocument.use_extension( Blacklight::Document::BibTeX )
|
9
|
+
#
|
10
|
+
# This extension also expects some data from blacklight_config (set in Catalog Controller)
|
11
|
+
|
12
|
+
require 'bibtex'
|
13
|
+
|
14
|
+
module Blacklight::Document::Bibtex
|
15
|
+
def self.extended(document)
|
16
|
+
Blacklight::Document::Bibtex.register_export_formats(document)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.register_export_formats(document)
|
20
|
+
document.will_export_as(:bibtex, "application/x-bibtex")
|
21
|
+
end
|
22
|
+
|
23
|
+
def export_as_bibtex
|
24
|
+
config = ::CatalogController.blacklight_config.citeproc
|
25
|
+
|
26
|
+
entry = ::BibTeX::Entry.new
|
27
|
+
entry.type = :book
|
28
|
+
entry.key = self.id
|
29
|
+
entry.title = self.first config[:fields][:title]
|
30
|
+
multiple_valued_fields = %i{author editor}
|
31
|
+
multiple_valued_fields.each do |field|
|
32
|
+
entry.send("#{field}=", self.fetch(config[:fields][field])) if self.has? config[:fields][field]
|
33
|
+
end
|
34
|
+
|
35
|
+
single_valued_fields = %i{address annote booktitle chapter doi edition how_published institution
|
36
|
+
journal key month note number organization pages publisher school series url volume year}
|
37
|
+
single_valued_fields.each do |field|
|
38
|
+
entry.send("#{field}=", self.first(config[:fields][field])) if self.has? config[:fields][field]
|
39
|
+
end
|
40
|
+
|
41
|
+
return entry
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def bibtex_type config
|
46
|
+
config[:format][:mappings].each do |bibtex, solr|
|
47
|
+
if solr.include? self.first config[:format][:field]
|
48
|
+
return bibtex
|
49
|
+
end
|
50
|
+
end
|
51
|
+
default_type = config[:format][:default_format] || :book
|
52
|
+
return default_type
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
$:.push File.expand_path("lib", __dir__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "blacklight/citeproc/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "blacklight-citeproc"
|
9
|
+
spec.version = Blacklight::Citeproc::VERSION
|
10
|
+
spec.authors = ["Jane Sandberg"]
|
11
|
+
spec.email = ["sandbej@linnbenton.edu"]
|
12
|
+
spec.homepage = "https://github.com/sandbergja/blacklight-citeproc"
|
13
|
+
spec.summary = ""
|
14
|
+
spec.description = ""
|
15
|
+
spec.license = "Apache-2.0"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency "bibtex-ruby", "~> 4.4.6"
|
25
|
+
spec.add_dependency "citeproc-ruby", "~> 1.1"
|
26
|
+
spec.add_dependency "csl-styles", "~> 1.0.1.9"
|
27
|
+
|
28
|
+
spec.add_development_dependency "rspec-rails", "~> 3.0"
|
29
|
+
spec.add_development_dependency "engine_cart", "~> 2.0"
|
30
|
+
spec.add_development_dependency "solr_wrapper"
|
31
|
+
|
32
|
+
end
|
33
|
+
|
data/config/routes.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Blacklight::Citeproc
|
4
|
+
class Install < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
def inject_routes
|
7
|
+
inject_into_file 'config/routes.rb', after: /mount Blacklight::Engine.*$/ do
|
8
|
+
"\n mount Blacklight::Citeproc::Engine => '/'\n"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
def add_blacklight_citeproc_config
|
12
|
+
insert_into_file "app/controllers/catalog_controller.rb", after: " configure_blacklight do |config|\n" do
|
13
|
+
<<-CONFIG
|
14
|
+
config.citeproc = {
|
15
|
+
#bibtex_field: 'bibtex_s' # Optional. If you are already indexing BibTeX into solr, this will be the preferred way to get bibliographic data
|
16
|
+
fields: {
|
17
|
+
address: 'published_ssm',
|
18
|
+
author: 'author_tsim',
|
19
|
+
edition: 'edition_tsim',
|
20
|
+
publisher: 'publisher_tsim',
|
21
|
+
title: 'title_tsim',
|
22
|
+
url: 'url_tsim',
|
23
|
+
year: 'pub_date_ssim'
|
24
|
+
},
|
25
|
+
styles: %w(apa chicago-fullnote-bibliography modern-language-association ieee council-of-science-editors),
|
26
|
+
format: {
|
27
|
+
field: 'format',
|
28
|
+
default_format: :book,
|
29
|
+
mappings: {
|
30
|
+
book: ['Book', 'Musical Score', 'Ebook'],
|
31
|
+
misc: ['Map/Globe', 'Non-musical Recording', 'Musical Recording', 'Image', 'Software/Data', 'Video/Film'],
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
CONFIG
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_marc_extension_to_solrdocument
|
40
|
+
insert_into_file "app/models/solr_document.rb", :after => "include Blacklight::Solr::Document" do
|
41
|
+
"\n use_extension(Blacklight::Document::Bibtex)\n"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blacklight-citeproc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jane Sandberg
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bibtex-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.4.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.4.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: citeproc-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: csl-styles
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.1.9
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.1.9
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: engine_cart
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: solr_wrapper
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: ''
|
98
|
+
email:
|
99
|
+
- sandbej@linnbenton.edu
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- README.md
|
105
|
+
- app/controllers/blacklight/citeproc/citation_controller.rb
|
106
|
+
- app/models/concerns/blacklight/document/bibtex.rb
|
107
|
+
- app/views/blacklight/citeproc/citation/print_single.html.erb
|
108
|
+
- blacklight-citeproc.gemspec
|
109
|
+
- config/locales/blacklight-citeproc.en.yml
|
110
|
+
- config/routes.rb
|
111
|
+
- lib/blacklight/citeproc.rb
|
112
|
+
- lib/blacklight/citeproc/engine.rb
|
113
|
+
- lib/blacklight/citeproc/version.rb
|
114
|
+
- lib/generators/blacklight/citeproc/install_generator.rb
|
115
|
+
homepage: https://github.com/sandbergja/blacklight-citeproc
|
116
|
+
licenses:
|
117
|
+
- Apache-2.0
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.7.6.2
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: ''
|
139
|
+
test_files: []
|