bibtex-ruby 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bibtex-ruby might be problematic. Click here for more details.

data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ === 1.1.0 / 2011-01-24
2
+
3
+ * Improved YAML export.
4
+
5
+ === 1.0.1 / 2011-01-17
6
+
7
+ * Removed StringScanner extension.
8
+
1
9
  === 1.0.0 / 2011-01-17
2
10
 
3
11
  * Initial Release. See README.rdoc for further details.
data/Manifest CHANGED
@@ -4,10 +4,10 @@ Manifest
4
4
  README.rdoc
5
5
  Rakefile
6
6
  examples/bib2html.rb
7
+ examples/bib2yaml.rb
7
8
  examples/markdown.bib
8
9
  lib/bibtex.rb
9
10
  lib/bibtex/bibliography.rb
10
- lib/bibtex/bibtex.y
11
11
  lib/bibtex/elements.rb
12
12
  lib/bibtex/entry.rb
13
13
  lib/bibtex/error.rb
@@ -15,7 +15,6 @@ lib/bibtex/lexer.rb
15
15
  lib/bibtex/parser.output
16
16
  lib/bibtex/parser.rb
17
17
  lib/bibtex/string_replacement.rb
18
- lib/extensions/core.rb
19
18
  test/bib/00_empty.bib
20
19
  test/bib/01_no_bibtex.bib
21
20
  test/bib/02_string.bib
@@ -30,5 +29,6 @@ test/bib/10_bibdesk.bib
30
29
  test/test_bibtex.rb
31
30
  test/test_comment.rb
32
31
  test/test_entry.rb
32
+ test/test_export.rb
33
33
  test/test_preamble.rb
34
34
  test/test_string.rb
data/README.rdoc CHANGED
@@ -11,6 +11,7 @@ objects as `meta comments' which may be included in post-processing.
11
11
 
12
12
  * require 'bibtex'
13
13
  * bib = BibTeX::Bibliography.open('file.bib')
14
+ * bib.to_yaml
14
15
 
15
16
 
16
17
  == Installation
@@ -35,11 +36,12 @@ Or, alternatively, fork the (project on github)[http://github.com/inukshuk/bibte
35
36
 
36
37
  * The parser generator {+racc+}[http://i.loveruby.net/en/projects/racc/] is required to generate parser.
37
38
  * The +minitest+ gem is required to run the tests in older Ruby versions (prior to 1.9).
39
+ * The +json+ gem is required on older ruby versions for JSON export.
38
40
 
39
41
 
40
42
  == Usage
41
43
 
42
- Look at the `examples' directory for a simple BibTeX to HTML converter.
44
+ Look at the `examples' directory for a simple BibTeX to YAML and BibTeX to HTML converter.
43
45
 
44
46
 
45
47
  == The Parser
data/Rakefile CHANGED
@@ -7,13 +7,14 @@ require 'rake/rdoctask'
7
7
  require 'rake/testtask'
8
8
  require 'echoe'
9
9
 
10
- Echoe.new('bibtex-ruby', '1.0.0') do |p|
11
- p.description = "A BibTeX parser written in Ruby"
10
+ Echoe.new('bibtex-ruby', '1.1.0') do |p|
11
+ p.summary = "A BibTeX parser written in Ruby"
12
+ p.description = "A (fairly complete) BibTeX parser written in Ruby. Supports regular BibTeX entries, @comments, string replacement via @string, and simple export formats (e.g. YAML)."
12
13
  p.url = "http://github.com/inukshuk/bibtex-ruby"
13
14
  p.author = "Sylvester Keil"
14
15
  p.email = "http://sylvester.keil.or.at"
15
16
  p.ignore_pattern = []
16
- p.development_dependencies = [['racc', '>=1.4.6']]
17
+ p.development_dependencies = [['racc', '>=1.4.6'], ['minitest']]
17
18
  p.need_tgz = true
18
19
  p.rdoc_options = ["--line-numbers", "--inline-source", "--title", "BibTeX-Ruby Documentation", "--main", "README.rdoc"]
19
20
  end
data/bibtex-ruby.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{bibtex-ruby}
5
- s.version = "1.0.0"
5
+ s.version = "1.1.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sylvester Keil"]
9
9
  s.cert_chain = ["/Users/sylvester/.gem/keys/gem-public_cert.pem"]
10
- s.date = %q{2011-01-18}
11
- s.description = %q{A (fairly complete) BibTeX parser written in Ruby}
10
+ s.date = %q{2011-01-24}
11
+ s.description = %q{A (fairly complete) BibTeX parser written in Ruby. Supports regular BibTeX entries, @comments, string replacement via @string, and simple export formats (e.g. YAML).}
12
12
  s.email = %q{http://sylvester.keil.or.at}
13
- s.extra_rdoc_files = ["LICENSE", "README.rdoc", "lib/bibtex.rb", "lib/bibtex/bibliography.rb", "lib/bibtex/bibtex.y", "lib/bibtex/elements.rb", "lib/bibtex/entry.rb", "lib/bibtex/error.rb", "lib/bibtex/lexer.rb", "lib/bibtex/parser.output", "lib/bibtex/parser.rb", "lib/bibtex/string_replacement.rb", "lib/extensions/core.rb"]
14
- s.files = ["History.txt", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "examples/bib2html.rb", "examples/markdown.bib", "lib/bibtex.rb", "lib/bibtex/bibliography.rb", "lib/bibtex/bibtex.y", "lib/bibtex/elements.rb", "lib/bibtex/entry.rb", "lib/bibtex/error.rb", "lib/bibtex/lexer.rb", "lib/bibtex/parser.output", "lib/bibtex/parser.rb", "lib/bibtex/string_replacement.rb", "lib/extensions/core.rb", "test/bib/00_empty.bib", "test/bib/01_no_bibtex.bib", "test/bib/02_string.bib", "test/bib/03_string.bib", "test/bib/04_string_replacement.bib", "test/bib/05_comment.bib", "test/bib/06_preamble.bib", "test/bib/07_entry.bib", "test/bib/08_decoret.bib", "test/bib/09_errors.bib", "test/bib/10_bibdesk.bib", "test/test_bibtex.rb", "test/test_comment.rb", "test/test_entry.rb", "test/test_preamble.rb", "test/test_string.rb", "bibtex-ruby.gemspec"]
13
+ s.extra_rdoc_files = ["LICENSE", "README.rdoc", "lib/bibtex.rb", "lib/bibtex/bibliography.rb", "lib/bibtex/elements.rb", "lib/bibtex/entry.rb", "lib/bibtex/error.rb", "lib/bibtex/lexer.rb", "lib/bibtex/parser.output", "lib/bibtex/parser.rb", "lib/bibtex/string_replacement.rb", "lib/extensions/core.rb"]
14
+ s.files = ["History.txt", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "bibtex-ruby.gemspec", "examples/bib2html.rb", "examples/bib2yaml.rb", "examples/markdown.bib", "lib/bibtex.rb", "lib/bibtex/bibliography.rb", "lib/bibtex/elements.rb", "lib/bibtex/entry.rb", "lib/bibtex/error.rb", "lib/bibtex/lexer.rb", "lib/bibtex/parser.output", "lib/bibtex/parser.rb", "lib/bibtex/string_replacement.rb", "lib/extensions/core.rb", "test/bib/00_empty.bib", "test/bib/01_no_bibtex.bib", "test/bib/02_string.bib", "test/bib/03_string.bib", "test/bib/04_string_replacement.bib", "test/bib/05_comment.bib", "test/bib/06_preamble.bib", "test/bib/07_entry.bib", "test/bib/08_decoret.bib", "test/bib/09_errors.bib", "test/bib/10_bibdesk.bib", "test/test_bibtex.rb", "test/test_comment.rb", "test/test_entry.rb", "test/test_export.rb", "test/test_preamble.rb", "test/test_string.rb"]
15
15
  s.homepage = %q{http://github.com/inukshuk/bibtex-ruby}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "BibTeX-Ruby Documentation", "--main", "README.rdoc"]
17
17
  s.require_paths = ["lib"]
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.rubygems_version = %q{1.3.7}
20
20
  s.signing_key = %q{/Users/sylvester/.gem/keys/gem-private_key.pem}
21
21
  s.summary = %q{A BibTeX parser written in Ruby}
22
- s.test_files = ["test/test_bibtex.rb", "test/test_comment.rb", "test/test_entry.rb", "test/test_preamble.rb", "test/test_string.rb"]
22
+ s.test_files = ["test/test_bibtex.rb", "test/test_comment.rb", "test/test_entry.rb", "test/test_export.rb", "test/test_preamble.rb", "test/test_string.rb"]
23
23
 
24
24
  if s.respond_to? :specification_version then
25
25
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -27,10 +27,13 @@ Gem::Specification.new do |s|
27
27
 
28
28
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
29
29
  s.add_development_dependency(%q<racc>, [">= 1.4.6"])
30
+ s.add_development_dependency(%q<minitest>, [">= 0"])
30
31
  else
31
32
  s.add_dependency(%q<racc>, [">= 1.4.6"])
33
+ s.add_dependency(%q<minitest>, [">= 0"])
32
34
  end
33
35
  else
34
36
  s.add_dependency(%q<racc>, [">= 1.4.6"])
37
+ s.add_dependency(%q<minitest>, [">= 0"])
35
38
  end
36
39
  end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bibtex'
5
+ require 'yaml'
6
+
7
+ if ARGV.length < 1
8
+ puts "Usage: #{$0} <bib> [<yml>]"
9
+ else
10
+ out = ARGV.length == 2 ? File.open(ARGV[1], 'w') : STDOUT
11
+ out.puts BibTeX::Bibliography.open(ARGV[0]).to_yaml
12
+ end
data/lib/bibtex.rb CHANGED
@@ -15,7 +15,11 @@
15
15
  # You should have received a copy of the GNU General Public License
16
16
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  #++
18
- #
18
+
19
+ $:.unshift(File.dirname(__FILE__)) unless
20
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
21
+
22
+
19
23
  # = BibTeX
20
24
  #
21
25
  # This module encompasses a parser for BibTeX files and
@@ -31,7 +35,7 @@ module BibTeX
31
35
  require 'logger'
32
36
 
33
37
  # The current library version.
34
- VERSION = '1.0.0'
38
+ VERSION = '1.1.0'
35
39
 
36
40
  #
37
41
  # An instance of the Ruby core class +Logger+.
@@ -149,10 +149,11 @@ module BibTeX
149
149
  @data.map(&:to_s).join
150
150
  end
151
151
 
152
+ # Returns a YAML representation of the bibliography. Only BibTeX entries are exported.
152
153
  def to_yaml
153
- @data.map(&:to_yaml).join
154
+ @entries.values.map(&:to_hash).to_yaml
154
155
  end
155
-
156
+
156
157
  def to_xml
157
158
  xml = REXML::Document.new
158
159
  xml << REXML::XMLDecl.new('1.0','UTF-8')
@@ -16,7 +16,6 @@
16
16
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  #++
18
18
 
19
- require 'json'
20
19
  require 'rexml/document'
21
20
  require 'yaml'
22
21
 
@@ -52,6 +51,7 @@ module BibTeX
52
51
  end
53
52
 
54
53
  def to_json
54
+ require 'json'
55
55
  self.to_hash.to_json
56
56
  end
57
57
 
data/lib/bibtex/entry.rb CHANGED
@@ -137,7 +137,7 @@ module BibTeX
137
137
  end
138
138
 
139
139
  def to_hash
140
- { @type.to_s => @fields.keys.map { |k| { k.to_s => StringReplacement.to_s(@fields[k], :delimiter => ['{','}']) } }.inject({ 'key' => @key }) { |sum,n| sum.merge(n) } }.to_yaml
140
+ @fields.keys.map { |k| { k.to_s => StringReplacement.to_s(@fields[k], :delimiter => ['{','}']) } }.inject({ 'key' => @key, 'type' => @type.to_s }) { |sum,n| sum.merge(n) }
141
141
  end
142
142
 
143
143
  def to_xml
data/test/test_bibtex.rb CHANGED
@@ -1,5 +1,5 @@
1
+ require File.expand_path('../../lib/bibtex.rb', __FILE__)
1
2
  require 'rubygems'
2
- require 'bibtex'
3
3
  require 'minitest/unit'
4
4
  require 'minitest/autorun'
5
5
 
data/test/test_comment.rb CHANGED
@@ -1,5 +1,5 @@
1
+ require File.expand_path('../../lib/bibtex.rb', __FILE__)
1
2
  require 'rubygems'
2
- require 'bibtex'
3
3
  require 'minitest/unit'
4
4
  require 'minitest/autorun'
5
5
 
data/test/test_entry.rb CHANGED
@@ -1,5 +1,5 @@
1
+ require File.expand_path('../../lib/bibtex.rb', __FILE__)
1
2
  require 'rubygems'
2
- require 'bibtex'
3
3
  require 'minitest/unit'
4
4
  require 'minitest/autorun'
5
5
 
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../../lib/bibtex.rb', __FILE__)
2
+ require 'rubygems'
3
+ require 'minitest/unit'
4
+ require 'minitest/autorun'
5
+ require 'yaml'
6
+
7
+ class TestString < MiniTest::Unit::TestCase
8
+
9
+ def setup
10
+ end
11
+
12
+ def teardown
13
+ end
14
+
15
+ def test_yaml
16
+ bib = BibTeX::Bibliography.open('test/bib/10_bibdesk.bib', :debug => true)
17
+ yaml = YAML.load(bib.to_yaml)
18
+ refute_nil(yaml)
19
+ assert_equal(3, yaml.length)
20
+ assert_equal(['dragon', 'pickaxe', 'rails'], yaml.map { |y| y['key'] }.sort)
21
+ assert_equal('{The Facets of Ruby}', yaml[0]['series'])
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
+ require File.expand_path('../../lib/bibtex.rb', __FILE__)
1
2
  require 'rubygems'
2
- require 'bibtex'
3
3
  require 'minitest/unit'
4
4
  require 'minitest/autorun'
5
5
 
data/test/test_string.rb CHANGED
@@ -1,5 +1,5 @@
1
+ require File.expand_path('../../lib/bibtex.rb', __FILE__)
1
2
  require 'rubygems'
2
- require 'bibtex'
3
3
  require 'minitest/unit'
4
4
  require 'minitest/autorun'
5
5
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
+ - 1
7
8
  - 0
8
- - 0
9
- version: 1.0.0
9
+ version: 1.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sylvester Keil
@@ -35,7 +35,7 @@ cert_chain:
35
35
  J/FeJ8pSGMcNlQbhGpGIX+ARJK5ArG0Aq4214ttgefkdQJvw5r9hG3J4AgM=
36
36
  -----END CERTIFICATE-----
37
37
 
38
- date: 2011-01-18 00:00:00 +01:00
38
+ date: 2011-01-24 00:00:00 +01:00
39
39
  default_executable:
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
@@ -53,7 +53,20 @@ dependencies:
53
53
  version: 1.4.6
54
54
  type: :development
55
55
  version_requirements: *id001
56
- description: A (fairly complete) BibTeX parser written in Ruby
56
+ - !ruby/object:Gem::Dependency
57
+ name: minitest
58
+ prerelease: false
59
+ requirement: &id002 !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ type: :development
68
+ version_requirements: *id002
69
+ description: A (fairly complete) BibTeX parser written in Ruby. Supports regular BibTeX entries, @comments, string replacement via @string, and simple export formats (e.g. YAML).
57
70
  email: http://sylvester.keil.or.at
58
71
  executables: []
59
72
 
@@ -64,7 +77,6 @@ extra_rdoc_files:
64
77
  - README.rdoc
65
78
  - lib/bibtex.rb
66
79
  - lib/bibtex/bibliography.rb
67
- - lib/bibtex/bibtex.y
68
80
  - lib/bibtex/elements.rb
69
81
  - lib/bibtex/entry.rb
70
82
  - lib/bibtex/error.rb
@@ -79,11 +91,12 @@ files:
79
91
  - Manifest
80
92
  - README.rdoc
81
93
  - Rakefile
94
+ - bibtex-ruby.gemspec
82
95
  - examples/bib2html.rb
96
+ - examples/bib2yaml.rb
83
97
  - examples/markdown.bib
84
98
  - lib/bibtex.rb
85
99
  - lib/bibtex/bibliography.rb
86
- - lib/bibtex/bibtex.y
87
100
  - lib/bibtex/elements.rb
88
101
  - lib/bibtex/entry.rb
89
102
  - lib/bibtex/error.rb
@@ -106,9 +119,9 @@ files:
106
119
  - test/test_bibtex.rb
107
120
  - test/test_comment.rb
108
121
  - test/test_entry.rb
122
+ - test/test_export.rb
109
123
  - test/test_preamble.rb
110
124
  - test/test_string.rb
111
- - bibtex-ruby.gemspec
112
125
  has_rdoc: true
113
126
  homepage: http://github.com/inukshuk/bibtex-ruby
114
127
  licenses: []
@@ -151,5 +164,6 @@ test_files:
151
164
  - test/test_bibtex.rb
152
165
  - test/test_comment.rb
153
166
  - test/test_entry.rb
167
+ - test/test_export.rb
154
168
  - test/test_preamble.rb
155
169
  - test/test_string.rb
metadata.gz.sig CHANGED
Binary file
data/lib/bibtex/bibtex.y DELETED
@@ -1,129 +0,0 @@
1
- #--
2
- # BibTeX-Ruby
3
- # Copyright (C) 2010 Sylvester Keil <http://sylvester.keil.or.at>
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- #++
18
- #
19
- # A BibTeX grammar for the parser generator +racc+
20
- #
21
-
22
- # -*- racc -*-
23
-
24
- class BibTeX::Parser
25
-
26
- token AT COMMA COMMENT CONTENT ERROR EQ LBRACE META_COMMENT
27
- NAME NUMBER PREAMBLE RBRACE SHARP STRING STRING_LITERAL
28
-
29
- expect 0
30
-
31
- rule
32
-
33
- bibliography : /* empty */ { result = Bibliography.new }
34
- | objects { result = val[0] }
35
-
36
- objects : object { result = Bibliography.new << val[0] }
37
- | objects object { result << val[1] }
38
-
39
- object : AT at_object { result = val[1] }
40
- | META_COMMENT { result = BibTeX::MetaComment.new(val[0]) }
41
- | ERROR { result = BibTeX::Error.new(val[0]) }
42
-
43
- at_object : comment { result = val[0] }
44
- | string { result = val[0] }
45
- | preamble { result = val[0] }
46
- | entry { result = val[0] }
47
-
48
- comment : COMMENT LBRACE content RBRACE { result = BibTeX::Comment.new(val[2]) }
49
-
50
- content : /* empty */ { result = '' }
51
- | CONTENT { result = val[0] }
52
-
53
- preamble : PREAMBLE LBRACE string_value RBRACE { result = BibTeX::Preamble.new(val[2]) }
54
-
55
- string : STRING LBRACE string_assignment RBRACE { result = BibTeX::String.new(val[2][0],val[2][1]); }
56
-
57
- string_assignment : NAME EQ string_value { result = [val[0].downcase.to_sym, val[2]] }
58
-
59
- string_value : string_literal { result = [val[0]] }
60
- | string_value SHARP string_literal { result << val[2] }
61
-
62
- string_literal : NAME { result = val[0].downcase.to_sym }
63
- | STRING_LITERAL { result = val[0] }
64
-
65
- entry : entry_head assignments RBRACE { result = val[0] << val[1] }
66
- | entry_head assignments COMMA RBRACE { result = val[0] << val[1] }
67
- | entry_head RBRACE { result = val[0] }
68
-
69
- entry_head : NAME LBRACE key COMMA { result = BibTeX::Entry.new(val[0].downcase.to_sym,val[2]) }
70
-
71
- key : NAME { result = val[0] }
72
- | NUMBER { result = val[0] }
73
-
74
- assignments : assignment { result = val[0] }
75
- | assignments COMMA assignment { result.merge!(val[2]) }
76
-
77
- assignment : NAME EQ value { result = { val[0].downcase.to_sym => val[2] } }
78
-
79
- value : string_value { result = val[0] }
80
- | NUMBER { result = val[0] }
81
- | LBRACE content RBRACE { result = val[1] }
82
-
83
- end
84
-
85
- ---- header
86
- require 'bibtex/lexer'
87
-
88
- ---- inner
89
-
90
- attr_reader :lexer
91
-
92
- def initialize(options={})
93
- @options = options
94
- @options[:include] ||= [:errors]
95
- @lexer = Lexer.new(options)
96
- end
97
-
98
- def parse(input)
99
- @yydebug = self.debug?
100
-
101
- self.lexer.src = input
102
- self.lexer.analyse
103
-
104
- do_parse
105
- end
106
-
107
- def next_token
108
- token = self.lexer.next_token
109
- if token[0] == :ERROR
110
- self.include_errors? ? token : next_token
111
- else
112
- [token[0],token[1][0]]
113
- end
114
- end
115
-
116
- def debug?
117
- @options[:debug] == true || ENV['DEBUG'] == true
118
- end
119
-
120
- def include_errors?
121
- @options[:include].include?(:errors)
122
- end
123
-
124
- def on_error(tid, val, vstack)
125
- #raise(ParseError, "Failed to parse BibTeX on value %s (%s) %s" % [val.inspect, token_to_str(tid) || '?', vstack.inspect])
126
- Log.error("Failed to parse BibTeX on value %s (%s) %s" % [val.inspect, token_to_str(tid) || '?', vstack.inspect])
127
- end
128
-
129
- # -*- racc -*-