bibtex-ruby 2.3.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of bibtex-ruby might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +4 -2
- data/History.txt +6 -0
- data/Manifest +2 -0
- data/README.md +3 -1
- data/features/issues/non_ascii_default_keys.feature +20 -0
- data/features/issues/non_ascii_keys.feature +17 -0
- data/features/step_definitions/bibtex_steps.rb +25 -1
- data/lib/bibtex/compatibility.rb +20 -0
- data/lib/bibtex/entry.rb +13 -6
- data/lib/bibtex/lexer.rb +4 -4
- data/lib/bibtex/version.rb +3 -3
- data/test/bibtex/test_entry.rb +5 -0
- data/test/bibtex/test_lexer.rb +6 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 032d4eb545f4e0360cb12438d83c1177dd17af9a
|
4
|
+
data.tar.gz: 2e855f8b6f4b23b67e0330cb4ffae8eea2476c08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42bcd110dda57b116de19d63ad9e5ca336c0035bde9bad0818f7b0e06c3199e470b86288eb7b4d8bfaf2d1a01d0a7ce8c24d0a8c3728dcf510df2b776f86f2f0
|
7
|
+
data.tar.gz: 7e4f01e424befdd4acec3685cbd3c87c3a1a6697574c93becadcece0433712be4a7dea645d5dc7593cbfa5cceef919161d50ee97d351f9a5392b3d79b4993294
|
data/Gemfile
CHANGED
@@ -4,6 +4,7 @@ gemspec
|
|
4
4
|
# RDF Export
|
5
5
|
gem 'rdf', '~>0.3'
|
6
6
|
|
7
|
+
|
7
8
|
group :debug do
|
8
9
|
gem 'debugger', :require => false, :platforms => [:mri_19, :mri_20]
|
9
10
|
gem 'ruby-debug', :require => false, :platforms => [:mri_18]
|
@@ -18,8 +19,8 @@ end
|
|
18
19
|
|
19
20
|
group :extra do
|
20
21
|
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
|
21
|
-
gem 'guard-minitest'
|
22
|
-
gem 'guard-cucumber'
|
22
|
+
gem 'guard-minitest', :platforms => [:ruby_20]
|
23
|
+
gem 'guard-cucumber', :platforms => [:ruby_20]
|
23
24
|
gem 'redcarpet', :platforms => [:rbx, :mri_20, :mri_19]
|
24
25
|
end
|
25
26
|
|
@@ -33,4 +34,5 @@ group :development do
|
|
33
34
|
gem 'rake'
|
34
35
|
gem 'racc'
|
35
36
|
gem 'yard'
|
37
|
+
gem 'iconv', :platforms => [:ruby_20]
|
36
38
|
end
|
data/History.txt
CHANGED
data/Manifest
CHANGED
@@ -19,6 +19,8 @@ features/issues/crossref.feature
|
|
19
19
|
features/issues/latex_filter.feature
|
20
20
|
features/issues/multiline_strings.feature
|
21
21
|
features/issues/name_parsing.feature
|
22
|
+
features/issues/non_ascii_default_keys.feature
|
23
|
+
features/issues/non_ascii_keys.feature
|
22
24
|
features/issues/number_keys.feature
|
23
25
|
features/issues/parse_months.feature
|
24
26
|
features/issues/slash_keys.feature
|
data/README.md
CHANGED
@@ -97,7 +97,9 @@ Save a bibliography to a file:
|
|
97
97
|
|
98
98
|
Compatibility
|
99
99
|
-------------
|
100
|
-
The BibTeX-Ruby gem has been developed and tested on Ruby
|
100
|
+
The BibTeX-Ruby gem has been developed and tested on Ruby 2.0 and 1.9; up to
|
101
|
+
version 2.x BibTeX-Ruby also supports Ruby 1.8, but starting with version 3.0.0
|
102
|
+
support 1.8 is not a priority anymore. It has
|
101
103
|
been confirmed to work with JRuby, Rubinius, and REE, however, there have
|
102
104
|
been repeated [issues](https://github.com/inukshuk/bibtex-ruby/issues)
|
103
105
|
(performance mostly) with MacRuby caused by MacRuby's current StringScanner
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Feature: Parse BibTeX files and convert LaTeX to Unicode
|
2
|
+
As a hacker who works with bibliographies
|
3
|
+
I want to be able to have autogenerated keys respect non-ASCII characters
|
4
|
+
by transliterating them
|
5
|
+
|
6
|
+
@default_keys
|
7
|
+
Scenario: A single entry with an author whose name contains non-ASCII characters
|
8
|
+
When I create an entry with these elements:
|
9
|
+
| type | author | title | location | year |
|
10
|
+
| book | Christian Müller | Title | Berlin | 2013 |
|
11
|
+
Then my bibliography should contain an entry with a key like "mu.?ller2013a"
|
12
|
+
|
13
|
+
@default_keys
|
14
|
+
Scenario: Multiple entries with an author whose name contains non-ASCII characters
|
15
|
+
When I create entries with these elements:
|
16
|
+
| type | author | title | location | year |
|
17
|
+
| book | Christian Müller | First Title | Berlin | 2013 |
|
18
|
+
| book | Christian Müller | Second Title | Berlin | 2013 |
|
19
|
+
Then my bibliography should contain an entry with a key like "mu.?ller2013a"
|
20
|
+
And my bibliography should contain an entry with a key like "mu.?ller2013b"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Feature: Keys containing non-ASCII characters
|
2
|
+
As a hacker who works with bibliographies
|
3
|
+
I want to parse BibTeX entries with keys containing non-ASCII characters
|
4
|
+
Because they can occur in many languages other than English
|
5
|
+
|
6
|
+
Scenario: An entry whose key contains a German umlaut
|
7
|
+
When I parse the following file:
|
8
|
+
"""
|
9
|
+
@article{müller.2011,
|
10
|
+
author = {Christian Müller},
|
11
|
+
title = {Important article},
|
12
|
+
journal = {Not so important journal},
|
13
|
+
volume = {5},
|
14
|
+
year = {2011}
|
15
|
+
}
|
16
|
+
"""
|
17
|
+
Then my bibliography should contain an article with id "müller.2011"
|
@@ -30,6 +30,26 @@ When /^I convert all entries using the filter "([^"]*)"$/ do |filter|
|
|
30
30
|
@bibliography.convert(filter)
|
31
31
|
end
|
32
32
|
|
33
|
+
When /^I create an entry with these elements:$/ do |table|
|
34
|
+
@bibliography = BibTeX::Bibliography.new
|
35
|
+
entry = BibTeX::Entry.new
|
36
|
+
table.hashes.first.each_pair do |field, value|
|
37
|
+
entry[field.to_sym] = value
|
38
|
+
end
|
39
|
+
@bibliography << entry.parse_names
|
40
|
+
end
|
41
|
+
|
42
|
+
When /^I create entries with these elements:$/ do |table|
|
43
|
+
@bibliography = BibTeX::Bibliography.new
|
44
|
+
table.hashes.each do |entries|
|
45
|
+
entry = BibTeX::Entry.new
|
46
|
+
entries.each_pair do |field, value|
|
47
|
+
entry[field.to_sym] = value
|
48
|
+
end
|
49
|
+
@bibliography << entry.parse_names
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
33
53
|
|
34
54
|
Then /^my bibliography should contain the following objects:$/ do |table|
|
35
55
|
@bibliography.each_with_index do |object, index|
|
@@ -59,6 +79,10 @@ Then /^my bibliography should contain an entry with (?:key|id) "([^"]*)"$/ do |k
|
|
59
79
|
refute_nil @bibliography[key.to_s]
|
60
80
|
end
|
61
81
|
|
82
|
+
Then /^my bibliography should contain an entry with an? (?:key|id) like "([^"]*)"$/ do |key|
|
83
|
+
pattern = Regexp.compile key
|
84
|
+
refute_nil @bibliography.detect { |e| e.key.to_s =~ pattern }
|
85
|
+
end
|
62
86
|
Then /^my bibliography should contain an entry with (?:key|id) "([^"]*)" and a?n? (\w+) value of "([^"]*)"$/ do |key,field,value|
|
63
87
|
refute_nil @bibliography[key.to_s]
|
64
88
|
assert_equal value, @bibliography[key.to_s][field.downcase.to_sym].to_s
|
@@ -92,4 +116,4 @@ end
|
|
92
116
|
|
93
117
|
Then /^the entry with key "([^"]*)" should have a field "([^"]*)" with the value "([^"]*)"$/ do |key, field, value|
|
94
118
|
assert_equal value, @bibliography[key][field.downcase.to_sym].to_s
|
95
|
-
end
|
119
|
+
end
|
data/lib/bibtex/compatibility.rb
CHANGED
@@ -16,3 +16,23 @@ if RUBY_VERSION < '1.9'
|
|
16
16
|
|
17
17
|
BibTeX::NameParser.patterns[:upper] = /[[:upper:]ÄÖÜ][^\t\r\n\s\{\}\d\\,]*/o
|
18
18
|
end
|
19
|
+
|
20
|
+
module BibTeX
|
21
|
+
begin
|
22
|
+
require 'iconv'
|
23
|
+
|
24
|
+
@iconv = Iconv.new('ascii//translit//ignore', 'utf-8')
|
25
|
+
|
26
|
+
def self.transliterate(str)
|
27
|
+
@iconv.iconv(str)
|
28
|
+
end
|
29
|
+
rescue LoadError
|
30
|
+
|
31
|
+
@iconv_replacements = Hash[*%w(ä ae ö oe ü ue Ä Ae Ö Oe Ü Ue ß ss)]
|
32
|
+
|
33
|
+
# Returns +str+ transliterated containing only ASCII characters.
|
34
|
+
def self.transliterate(str)
|
35
|
+
str.gsub(/[äöüÄÖÜß]/, @iconv_replacements)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/bibtex/entry.rb
CHANGED
@@ -720,10 +720,18 @@ module BibTeX
|
|
720
720
|
end
|
721
721
|
|
722
722
|
def issued
|
723
|
-
|
724
|
-
|
723
|
+
return unless has_field?(:year)
|
724
|
+
|
725
|
+
parts = [fields[:year].to_s]
|
725
726
|
|
726
|
-
|
727
|
+
return { 'literal' => parts[0] } unless parts[0] =~ /^\d+$/
|
728
|
+
|
729
|
+
if has_field?(:month)
|
730
|
+
parts.push MONTHS.find_index(fields[:month].to_s.intern)
|
731
|
+
parts[1] = parts[1] + 1 unless parts[1].nil?
|
732
|
+
end
|
733
|
+
|
734
|
+
{ 'date-parts' => [parts.compact.map(&:to_i)] }
|
727
735
|
end
|
728
736
|
|
729
737
|
alias citeproc_date issued
|
@@ -859,13 +867,12 @@ module BibTeX
|
|
859
867
|
def default_key
|
860
868
|
k = names[0]
|
861
869
|
k = k.respond_to?(:family) ? k.family : k.to_s
|
862
|
-
k = k
|
870
|
+
k = BibTeX.transliterate(k)
|
871
|
+
k = k[/[A-Za-z-]+/] || 'unknown'
|
863
872
|
k << (has_field?(:year) ? year : '-')
|
864
873
|
k << 'a'
|
865
874
|
k.downcase!
|
866
875
|
k
|
867
876
|
end
|
868
|
-
|
869
|
-
|
870
877
|
end
|
871
878
|
end
|
data/lib/bibtex/lexer.rb
CHANGED
@@ -46,8 +46,8 @@ module BibTeX
|
|
46
46
|
:braces => /\{|\}/o,
|
47
47
|
:eq => /\s*=\s*/o,
|
48
48
|
:comma => /\s*,\s*/o,
|
49
|
-
:number =>
|
50
|
-
:name => /[[:alpha:]
|
49
|
+
:number => /[[:digit:]]+/o,
|
50
|
+
:name => /[[:alpha:][:digit:]\/:_!$\?\.%&\*-]+/io,
|
51
51
|
:quote => /\s*"/o,
|
52
52
|
:unquote => /[\{\}"]/o,
|
53
53
|
:sharp => /\s*#\s*/o,
|
@@ -59,8 +59,8 @@ module BibTeX
|
|
59
59
|
:string => /string/io,
|
60
60
|
:comment => /comment\b/io,
|
61
61
|
:preamble => /preamble\b/io,
|
62
|
-
:key => /\s*[[:alpha:]
|
63
|
-
:optional_key => /\s*[[:alpha:]
|
62
|
+
:key => /\s*[[:alpha:][:digit:] \/:_!$\?\.%+&\*-]+,/io,
|
63
|
+
:optional_key => /\s*[[:alpha:][:digit:] \/:_!$\?\.%+&\*-]*,/io
|
64
64
|
}.freeze
|
65
65
|
|
66
66
|
MODE = Hash.new(:meta).merge({
|
data/lib/bibtex/version.rb
CHANGED
data/test/bibtex/test_entry.rb
CHANGED
@@ -269,6 +269,11 @@ module BibTeX
|
|
269
269
|
assert_equal 'Melville', e['author'][0]['family']
|
270
270
|
end
|
271
271
|
|
272
|
+
it 'support literal dates in citeproc export' do
|
273
|
+
@entry.year = 'Test'
|
274
|
+
assert_equal({ 'literal' => 'Test' }, @entry.issued)
|
275
|
+
end
|
276
|
+
|
272
277
|
describe 'given a filter object or a filter name' do
|
273
278
|
before do
|
274
279
|
@filter = Object.new
|
data/test/bibtex/test_lexer.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'helper.rb'
|
2
4
|
|
3
5
|
module BibTeX
|
@@ -21,6 +23,10 @@ module BibTeX
|
|
21
23
|
Lexer.new.analyse("@misc{foo, }").symbols.must_be :==, [:AT, :NAME, :LBRACE, :KEY, :RBRACE, false]
|
22
24
|
end
|
23
25
|
|
26
|
+
it 'matches KEY tokens with non-ascii characters' do
|
27
|
+
Lexer.new.analyse("@misc{löwe, }").symbols.must_be :==, [:AT, :NAME, :LBRACE, :KEY, :RBRACE, false]
|
28
|
+
end
|
29
|
+
|
24
30
|
it 'matches KEY tokens after whitespace' do
|
25
31
|
Lexer.new.analyse("@misc{ foo, }").symbols.must_be :==, [:AT, :NAME, :LBRACE, :KEY, :RBRACE, false]
|
26
32
|
end
|
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: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvester Keil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: latex-decode
|
@@ -71,6 +71,8 @@ files:
|
|
71
71
|
- features/issues/latex_filter.feature
|
72
72
|
- features/issues/multiline_strings.feature
|
73
73
|
- features/issues/name_parsing.feature
|
74
|
+
- features/issues/non_ascii_default_keys.feature
|
75
|
+
- features/issues/non_ascii_keys.feature
|
74
76
|
- features/issues/number_keys.feature
|
75
77
|
- features/issues/parse_months.feature
|
76
78
|
- features/issues/slash_keys.feature
|