bibtex-ruby 5.1.0 → 5.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Rakefile +1 -4
- data/lib/bibtex/bibliography.rb +1 -1
- data/lib/bibtex/entry.rb +38 -37
- data/lib/bibtex/entry/citeproc_converter.rb +28 -6
- data/lib/bibtex/value.rb +9 -4
- data/lib/bibtex/version.rb +1 -1
- data/test/bibtex/test_entry.rb +59 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6856304b07fca1f55d4f88bbf72876e38438016762854b4ba6131a49c53d1f5c
|
4
|
+
data.tar.gz: 617f34575c3276fb79986b4d724726beb3b5aba5fc82d712f39c867084e7c56b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8803ce4b87cba0939eb1586fdb6d34edd42d71acc266716df0dd23101fa8fff0e8ccefdb889b3962010c3e24861527ace743ec0e871a386364f8cab70d0b137
|
7
|
+
data.tar.gz: c5bfc4fc88f97dcd5be53e7775d09b439f81cbf2e2c25b8aac6f7e327f0913e66a4374b9d3bd29adb5b037ee464308fd532df8beaf4d49d9e36e394e79f49ac9
|
data/Gemfile
CHANGED
@@ -27,13 +27,13 @@ group :profile do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
group :coverage do
|
30
|
-
gem 'coveralls',
|
30
|
+
gem 'coveralls', require: false
|
31
31
|
gem 'simplecov', require: false, platforms: [:ruby]
|
32
32
|
end
|
33
33
|
|
34
34
|
group :development do
|
35
35
|
gem 'iconv', platforms: [:ruby]
|
36
|
+
gem 'racc'
|
36
37
|
gem 'rake'
|
37
|
-
gem 'rubocop', require: false
|
38
38
|
gem 'yard'
|
39
39
|
end
|
data/Rakefile
CHANGED
@@ -11,7 +11,6 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), './lib'))
|
|
11
11
|
|
12
12
|
require 'rake/clean'
|
13
13
|
require 'rake/testtask'
|
14
|
-
require 'rubocop/rake_task'
|
15
14
|
|
16
15
|
require 'bibtex/version'
|
17
16
|
|
@@ -44,9 +43,7 @@ rescue LoadError
|
|
44
43
|
# ignore
|
45
44
|
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
task default: %i[test features rubocop]
|
46
|
+
task default: %i[test features]
|
50
47
|
|
51
48
|
desc 'Generates the BibTeX parser'
|
52
49
|
task racc: ['lib/bibtex/parser.rb', 'lib/bibtex/name_parser.rb']
|
data/lib/bibtex/bibliography.rb
CHANGED
@@ -47,7 +47,7 @@ module BibTeX
|
|
47
47
|
# -:filter: convert all entries using the sepcified filter (not set by default)
|
48
48
|
#
|
49
49
|
def open(path, options = {})
|
50
|
-
b = parse(File.read(path), options)
|
50
|
+
b = parse(File.read(path, encoding: 'utf-8'), options)
|
51
51
|
b.path = path
|
52
52
|
return b unless block_given?
|
53
53
|
|
data/lib/bibtex/entry.rb
CHANGED
@@ -117,43 +117,6 @@ module BibTeX
|
|
117
117
|
self
|
118
118
|
end
|
119
119
|
|
120
|
-
# Generate accessors for required fields (#52)
|
121
|
-
REQUIRED_FIELDS.values.flatten.uniq.each do |name|
|
122
|
-
unless method_defined? name
|
123
|
-
define_method(name) do
|
124
|
-
get name
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
writer = "#{name}="
|
129
|
-
|
130
|
-
next if method_defined? writer
|
131
|
-
|
132
|
-
define_method(writer) do |value|
|
133
|
-
add name, value
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# Generate author, editor and translator accessors
|
138
|
-
NAME_FIELDS.each do |contributor|
|
139
|
-
unless method_defined? contributor
|
140
|
-
define_method(contributor) do
|
141
|
-
get contributor
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
writer = "#{contributor}="
|
146
|
-
|
147
|
-
unless method_defined? writer
|
148
|
-
define_method(writer) do |value|
|
149
|
-
add contributor, value
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
alias_method "#{contributor}s", contributor
|
154
|
-
alias_method "#{contributor}s=", writer
|
155
|
-
end
|
156
|
-
|
157
120
|
# call-seq:
|
158
121
|
# entry.each { |key, value| block } -> entry
|
159
122
|
# entry.each_pair { |key, value| block } -> entry
|
@@ -669,6 +632,44 @@ module BibTeX
|
|
669
632
|
fields[:date].to_s[/\d{4}/]
|
670
633
|
end
|
671
634
|
|
635
|
+
# Generate accessors for required fields (#52)
|
636
|
+
REQUIRED_FIELDS.values.flatten.uniq.each do |name|
|
637
|
+
unless method_defined? name
|
638
|
+
define_method(name) do
|
639
|
+
get name
|
640
|
+
end
|
641
|
+
end
|
642
|
+
|
643
|
+
writer = "#{name}="
|
644
|
+
|
645
|
+
next if method_defined? writer
|
646
|
+
|
647
|
+
define_method(writer) do |value|
|
648
|
+
add name, value
|
649
|
+
end
|
650
|
+
end
|
651
|
+
|
652
|
+
# Generate author, editor and translator accessors
|
653
|
+
NAME_FIELDS.each do |contributor|
|
654
|
+
unless method_defined? contributor
|
655
|
+
define_method(contributor) do
|
656
|
+
get contributor
|
657
|
+
end
|
658
|
+
end
|
659
|
+
|
660
|
+
writer = "#{contributor}="
|
661
|
+
|
662
|
+
unless method_defined? writer
|
663
|
+
define_method(writer) do |value|
|
664
|
+
add contributor, value
|
665
|
+
end
|
666
|
+
end
|
667
|
+
|
668
|
+
alias_method "#{contributor}s", contributor
|
669
|
+
alias_method "#{contributor}s=", writer
|
670
|
+
end
|
671
|
+
|
672
|
+
|
672
673
|
private
|
673
674
|
|
674
675
|
# Returns a default key for this entry.
|
@@ -20,6 +20,7 @@ class BibTeX::Entry::CiteProcConverter
|
|
20
20
|
organization publisher
|
21
21
|
howpublished publisher
|
22
22
|
type genre
|
23
|
+
urldate accessed
|
23
24
|
].map(&:intern)]).freeze
|
24
25
|
|
25
26
|
CSL_FIELDS = %w[
|
@@ -56,6 +57,7 @@ class BibTeX::Entry::CiteProcConverter
|
|
56
57
|
|
57
58
|
def initialize(bibtex, options = {})
|
58
59
|
@bibtex = bibtex
|
60
|
+
@hash = {}
|
59
61
|
@options = { quotes: [] }.merge(options)
|
60
62
|
end
|
61
63
|
|
@@ -122,6 +124,21 @@ class BibTeX::Entry::CiteProcConverter
|
|
122
124
|
end
|
123
125
|
end
|
124
126
|
|
127
|
+
def accessed
|
128
|
+
return unless hash.key? 'accessed'
|
129
|
+
|
130
|
+
hash['accessed'] =
|
131
|
+
case hash['accessed']
|
132
|
+
when %r{^[\d/\s-]+$}
|
133
|
+
{
|
134
|
+
'date-parts' =>
|
135
|
+
hash['accessed'].split('/').map { |pt| pt.split('-').map(&:to_i) }
|
136
|
+
}
|
137
|
+
else
|
138
|
+
{ 'literal' => hash['accessed'] }
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
125
142
|
def key
|
126
143
|
hash['id'] = bibtex.key.to_s
|
127
144
|
end
|
@@ -141,21 +158,26 @@ class BibTeX::Entry::CiteProcConverter
|
|
141
158
|
|
142
159
|
private
|
143
160
|
|
144
|
-
attr_reader :bibtex, :options
|
161
|
+
attr_reader :bibtex, :options, :hash
|
145
162
|
|
146
163
|
def convert(key, value)
|
147
164
|
return if BibTeX::Entry::DATE_FIELDS.include?(key)
|
165
|
+
return include_url(value) if howpublished_with_url?(key, value)
|
148
166
|
|
149
|
-
|
167
|
+
citeproc_key = CSL_FILTER[key].to_s
|
150
168
|
|
151
|
-
if hash.key?(
|
169
|
+
if hash.key?(citeproc_key)
|
152
170
|
hash[key] = value.to_citeproc(options)
|
153
171
|
else
|
154
|
-
hash[
|
172
|
+
hash[citeproc_key] = value.to_citeproc(options)
|
155
173
|
end
|
156
174
|
end
|
157
175
|
|
158
|
-
def
|
159
|
-
|
176
|
+
def howpublished_with_url?(key, value)
|
177
|
+
key == :howpublished && value.include?('url')
|
178
|
+
end
|
179
|
+
|
180
|
+
def include_url(value)
|
181
|
+
hash['URL'] = value.to_s[/url{?([^}]*)/, 1]
|
160
182
|
end
|
161
183
|
end
|
data/lib/bibtex/value.rb
CHANGED
@@ -49,9 +49,9 @@ module BibTeX
|
|
49
49
|
alias to_a tokens
|
50
50
|
|
51
51
|
def_delegators :to_s, :=~, :===,
|
52
|
-
*String.instance_methods(false).reject
|
53
|
-
m =~ /^\W|^(length|dup|replace|to_s|inspect)$|!$/
|
54
|
-
|
52
|
+
*String.instance_methods(false).reject { |m|
|
53
|
+
m =~ /^\W|^(length|dup|replace|to_s|to_i|inspect)$|!$/
|
54
|
+
}
|
55
55
|
|
56
56
|
def_delegators :@tokens, :[], :length
|
57
57
|
def_delegator :@tokens, :each, :each_token
|
@@ -180,7 +180,12 @@ module BibTeX
|
|
180
180
|
# If the option :filter is given, the Value will be converted using
|
181
181
|
# the filter(s) specified.
|
182
182
|
def to_s(options = {})
|
183
|
-
|
183
|
+
if options.key?(:filter)
|
184
|
+
return convert(options[:filter]).to_s(
|
185
|
+
options.reject { |k,| k == :filter || (k == :quotes && (!atomic? || symbol?)) }
|
186
|
+
)
|
187
|
+
end
|
188
|
+
|
184
189
|
return value.to_s unless options.key?(:quotes) && atomic? && !symbol?
|
185
190
|
|
186
191
|
q = Array(options[:quotes])
|
data/lib/bibtex/version.rb
CHANGED
data/test/bibtex/test_entry.rb
CHANGED
@@ -31,7 +31,8 @@ module BibTeX
|
|
31
31
|
@bib = Bibliography.parse <<-END
|
32
32
|
@book{a, editor = "A", title = "A"}
|
33
33
|
@incollection{a1, crossref = "a"}
|
34
|
-
@incollection{b1, crossref = "
|
34
|
+
@incollection{b1, crossref = "b2"}
|
35
|
+
@book{b, author = "B", title = "B", date = "2020", urldate = "2020"}
|
35
36
|
END
|
36
37
|
end
|
37
38
|
|
@@ -124,6 +125,10 @@ module BibTeX
|
|
124
125
|
it 'includes inherited values' do
|
125
126
|
@bib['a1'].to_citeproc['container-title'].must_be :==, @bib['a'].title.to_s
|
126
127
|
end
|
128
|
+
|
129
|
+
it 'converts urldate' do
|
130
|
+
@bib['b'].to_citeproc['accessed'].must_be :==, 'date-parts' => [[2020]]
|
131
|
+
end
|
127
132
|
end
|
128
133
|
|
129
134
|
describe '#save_inherited_fields' do
|
@@ -433,7 +438,7 @@ module BibTeX
|
|
433
438
|
end
|
434
439
|
end
|
435
440
|
|
436
|
-
describe '
|
441
|
+
describe '#to_citeproc' do
|
437
442
|
before do
|
438
443
|
@entry = Entry.new do |e|
|
439
444
|
e.type = :book
|
@@ -450,6 +455,58 @@ module BibTeX
|
|
450
455
|
it 'should accept option to use non-dropping-particle' do
|
451
456
|
assert_equal 'van', @entry.to_citeproc(particle: 'non-dropping-particle')['author'][0]['non-dropping-particle']
|
452
457
|
end
|
458
|
+
|
459
|
+
describe 'howpublished' do
|
460
|
+
it 'converts to "URL" when there is a url (without filters)' do
|
461
|
+
bibtex = <<-END
|
462
|
+
@book{noauthor_2017-xx,
|
463
|
+
title = "Google",
|
464
|
+
howpublished = "\\url{http://www.google.com/}"
|
465
|
+
}
|
466
|
+
END
|
467
|
+
bibliography = Bibliography.parse(bibtex)
|
468
|
+
|
469
|
+
citeproc = bibliography.to_citeproc
|
470
|
+
|
471
|
+
assert_equal('http://www.google.com/', citeproc[0]['URL'])
|
472
|
+
assert_nil(citeproc[0]['publisher'])
|
473
|
+
end
|
474
|
+
|
475
|
+
it 'converts to "URL" when there is a url (with latex)' do
|
476
|
+
bibtex = <<-END
|
477
|
+
@book{noauthor_2017-xx,
|
478
|
+
title = "Google",
|
479
|
+
howpublished = "\\url{http://www.google.com/}"
|
480
|
+
}
|
481
|
+
END
|
482
|
+
bibliography = Bibliography.parse(bibtex, filter: :latex)
|
483
|
+
|
484
|
+
citeproc = bibliography.to_citeproc
|
485
|
+
|
486
|
+
assert_equal('http://www.google.com/', citeproc[0]['URL'])
|
487
|
+
end
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
describe '#to_s' do
|
492
|
+
before do
|
493
|
+
@bib = Bibliography.parse(<<-BIBINPUT, parse_months: false)
|
494
|
+
@misc{foo,
|
495
|
+
title = {A
|
496
|
+
title},
|
497
|
+
series = {A
|
498
|
+
series},
|
499
|
+
month = dec
|
500
|
+
}
|
501
|
+
BIBINPUT
|
502
|
+
end
|
503
|
+
it 'applies filters when converting to strings' do
|
504
|
+
assert_equal "@misc{foo,\n"\
|
505
|
+
" title = {A title},\n"\
|
506
|
+
" series = {A series},\n"\
|
507
|
+
" month = dec\n"\
|
508
|
+
"}\n", @bib['foo'].to_s(filter: :linebreaks)
|
509
|
+
end
|
453
510
|
end
|
454
511
|
|
455
512
|
def test_simple
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bibtex-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1.
|
4
|
+
version: 5.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvester Keil
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: latex-decode
|
@@ -128,7 +128,7 @@ homepage: http://inukshuk.github.com/bibtex-ruby
|
|
128
128
|
licenses:
|
129
129
|
- GPL-3.0
|
130
130
|
metadata: {}
|
131
|
-
post_install_message:
|
131
|
+
post_install_message:
|
132
132
|
rdoc_options: []
|
133
133
|
require_paths:
|
134
134
|
- lib
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
146
|
rubygems_version: 3.1.2
|
147
|
-
signing_key:
|
147
|
+
signing_key:
|
148
148
|
specification_version: 4
|
149
149
|
summary: A BibTeX parser, converter and API for Ruby.
|
150
150
|
test_files:
|
@@ -157,8 +157,8 @@ test_files:
|
|
157
157
|
- test/bibtex/test_string.rb
|
158
158
|
- test/bibtex/test_utilities.rb
|
159
159
|
- test/bibtex/test_value.rb
|
160
|
-
- test/bibtex/test_entry.rb
|
161
160
|
- test/bibtex/test_filters.rb
|
162
161
|
- test/bibtex/test_bibliography.rb
|
162
|
+
- test/bibtex/test_entry.rb
|
163
163
|
- test/test_bibtex.rb
|
164
164
|
- test/test_export.rb
|