bibtex-ruby 5.1.2 → 6.0.0
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/README.md +2 -4
- data/Rakefile +1 -12
- data/lib/bibtex.rb +6 -1
- data/lib/bibtex/entry.rb +39 -38
- data/lib/bibtex/entry/citeproc_converter.rb +16 -0
- data/lib/bibtex/value.rb +9 -4
- data/lib/bibtex/version.rb +3 -3
- data/test/bibtex/test_entry.rb +27 -1
- data/test/helper.rb +0 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d20ff3c667743829aca52621d06ed9817e6889f78cc4738d036f058a7f191836
|
4
|
+
data.tar.gz: 8810c0a5aa024a5b7150b02326ac00ddda0657098275a41cd0e9009c19bbd8ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cab60663c560854377d34d87934365002b2cdeabbdb7aa6bdf3df42a962ff94abfc5e647629945b065a48ef83f36c1dc8a275e62c1b98cee824b9f89870cbc5b
|
7
|
+
data.tar.gz: a0f39e0ac274f36a4aeaa911a76087f5480819c737abba310ce17fb105528816ae68a9311bfac202fd1ae71e4fe43cfe63fb37a2be652bf90945174e8756ca17
|
data/Gemfile
CHANGED
@@ -6,6 +6,8 @@ gem 'json', '~>2.0', platforms: %i[mri_18 jruby]
|
|
6
6
|
gem 'rdf', '~>3.0'
|
7
7
|
gem 'rdf-vocab', '~>3.0'
|
8
8
|
|
9
|
+
gem 'rexml', '~>3.0'
|
10
|
+
|
9
11
|
group :debug do
|
10
12
|
gem 'byebug', require: false, platforms: :mri
|
11
13
|
gem 'ruby-debug', require: false, platforms: :jruby
|
@@ -27,7 +29,6 @@ group :profile do
|
|
27
29
|
end
|
28
30
|
|
29
31
|
group :coverage do
|
30
|
-
gem 'coveralls', '~>0.8', require: false
|
31
32
|
gem 'simplecov', require: false, platforms: [:ruby]
|
32
33
|
end
|
33
34
|
|
@@ -35,6 +36,5 @@ group :development do
|
|
35
36
|
gem 'iconv', platforms: [:ruby]
|
36
37
|
gem 'racc'
|
37
38
|
gem 'rake'
|
38
|
-
gem 'rubocop', require: false
|
39
39
|
gem 'yard'
|
40
40
|
end
|
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
BibTeX-Ruby
|
2
2
|
===========
|
3
|
-
[![Build Status](https://secure.travis-ci.org/inukshuk/bibtex-ruby.png?branch=master)](http://travis-ci.org/inukshuk/bibtex-ruby)
|
4
|
-
[![Coverage Status](https://coveralls.io/repos/inukshuk/bibtex-ruby/badge.png)](https://coveralls.io/r/inukshuk/bibtex-ruby)
|
5
3
|
|
6
4
|
BibTeX-Ruby is the Rubyist's swiss-army-knife for all things BibTeX. It
|
7
5
|
includes a parser for all common BibTeX objects (@string, @preamble, @comment
|
@@ -10,7 +8,7 @@ formatted names; BibTeX-Ruby recognizes BibTeX string replacements, joins
|
|
10
8
|
values containing multiple strings or variables, supports cross-references,
|
11
9
|
and decodes common LaTeX formatting instructions to unicode; if you are in a
|
12
10
|
hurry, it also allows for easy export/conversion to formats such as YAML,
|
13
|
-
JSON, CiteProc/CSL, XML (BibTeXML), and RDF (experimental).
|
11
|
+
JSON, CiteProc/CSL, XML (BibTeXML, requires `rexml`), and RDF (experimental).
|
14
12
|
|
15
13
|
For a list of projects using BibTeX-Ruby, take a look at the
|
16
14
|
[project wiki](https://github.com/inukshuk/bibtex-ruby/wiki/Projects-Using-BibTeX-Ruby).
|
@@ -466,7 +464,7 @@ constitutes a simple BibTeX to YAML converter:
|
|
466
464
|
>> BibTeX.open('example.bib').to_yaml
|
467
465
|
|
468
466
|
Starting with version 2.0, BibTeX-Ruby's `#to_xml` exports your bibliography
|
469
|
-
to the [BibTeXML](http://bibtexml.sf.net/) format
|
467
|
+
to the [BibTeXML](http://bibtexml.sf.net/) format via `rexml`. By passing the option
|
470
468
|
`:extended => true` you can make use of the BibTeXML's extended format which
|
471
469
|
will return individual person elements and name tokens (provided you have
|
472
470
|
successfully parsed the names of your bibliography).
|
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
|
|
@@ -36,17 +35,7 @@ rescue LoadError
|
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
|
-
|
40
|
-
require 'coveralls/rake/task'
|
41
|
-
Coveralls::RakeTask.new
|
42
|
-
task test_with_coveralls: [:test, :features, 'coveralls:push']
|
43
|
-
rescue LoadError
|
44
|
-
# ignore
|
45
|
-
end
|
46
|
-
|
47
|
-
RuboCop::RakeTask.new
|
48
|
-
|
49
|
-
task default: %i[test features rubocop]
|
38
|
+
task default: %i[test features]
|
50
39
|
|
51
40
|
desc 'Generates the BibTeX parser'
|
52
41
|
task racc: ['lib/bibtex/parser.rb', 'lib/bibtex/name_parser.rb']
|
data/lib/bibtex.rb
CHANGED
@@ -65,13 +65,18 @@ require 'bibtex/names'
|
|
65
65
|
require 'bibtex/replaceable'
|
66
66
|
require 'bibtex/elements'
|
67
67
|
require 'bibtex/entry'
|
68
|
-
require 'bibtex/entry/bibtexml_converter'
|
69
68
|
require 'bibtex/entry/citeproc_converter'
|
70
69
|
require 'bibtex/error'
|
71
70
|
require 'bibtex/parser'
|
72
71
|
require 'bibtex/bibliography'
|
73
72
|
require 'bibtex/utilities'
|
74
73
|
|
74
|
+
begin
|
75
|
+
require 'bibtex/entry/bibtexml_converter'
|
76
|
+
rescue LoadError
|
77
|
+
# ignored
|
78
|
+
end
|
79
|
+
|
75
80
|
begin
|
76
81
|
require 'rdf'
|
77
82
|
require 'bibtex/entry/rdf_converter'
|
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
|
@@ -216,7 +179,7 @@ module BibTeX
|
|
216
179
|
end
|
217
180
|
|
218
181
|
def has_type?(type)
|
219
|
-
type.to_s.match(/^(?:entry|\*)$/i) || @type
|
182
|
+
type.to_s.match(/^(?:entry|\*)$/i) || @type.casecmp?(type.to_sym) || super
|
220
183
|
end
|
221
184
|
|
222
185
|
alias type? has_type?
|
@@ -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[
|
@@ -123,6 +124,21 @@ class BibTeX::Entry::CiteProcConverter
|
|
123
124
|
end
|
124
125
|
end
|
125
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
|
+
|
126
142
|
def key
|
127
143
|
hash['id'] = bibtex.key.to_s
|
128
144
|
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
|
@@ -483,6 +488,27 @@ module BibTeX
|
|
483
488
|
end
|
484
489
|
end
|
485
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
|
510
|
+
end
|
511
|
+
|
486
512
|
def test_simple
|
487
513
|
bib = BibTeX::Bibliography.open(Test.fixtures(:entry), debug: false)
|
488
514
|
refute_nil(bib)
|
data/test/helper.rb
CHANGED
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:
|
4
|
+
version: 6.0.0
|
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:
|
11
|
+
date: 2021-01-07 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:
|