bibtex-ruby 1.1.2 → 1.2.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.

data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bibtex-ruby (1.1.2)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ json (1.5.1)
10
+ minitest (2.0.2)
11
+ racc (1.4.6)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bibtex-ruby!
18
+ json (>= 1.5.0)
19
+ minitest (>= 2.0.2)
20
+ racc (>= 1.4.6)
data/Manifest CHANGED
@@ -1,8 +1,11 @@
1
+ Gemfile
2
+ Gemfile.lock
1
3
  History.txt
2
4
  LICENSE
3
5
  Manifest
4
6
  README.md
5
7
  Rakefile
8
+ bibtex-ruby.gemspec
6
9
  examples
7
10
  examples/bib2html.rb
8
11
  examples/bib2yaml.rb
@@ -14,10 +17,11 @@ lib/bibtex/bibtex.y
14
17
  lib/bibtex/elements.rb
15
18
  lib/bibtex/entry.rb
16
19
  lib/bibtex/error.rb
20
+ lib/bibtex/extensions.rb
17
21
  lib/bibtex/lexer.rb
18
22
  lib/bibtex/parser.output
19
23
  lib/bibtex/parser.rb
20
- lib/bibtex/string_replacement.rb
24
+ lib/bibtex/utilities.rb
21
25
  lib/bibtex/version.rb
22
26
  lib/bibtex.rb
23
27
  test
@@ -33,9 +37,12 @@ test/bib/07_entry.bib
33
37
  test/bib/08_decoret.bib
34
38
  test/bib/09_errors.bib
35
39
  test/bib/10_bibdesk.bib
40
+ test/bib/11_roundtrip.bib
41
+ test/helper.rb
36
42
  test/test_bibtex.rb
37
43
  test/test_comment.rb
38
44
  test/test_entry.rb
39
45
  test/test_export.rb
40
46
  test/test_preamble.rb
41
- test/test_string.rb
47
+ test/test_string.rb
48
+ test/test_utilities.rb
data/README.md CHANGED
@@ -2,36 +2,38 @@ BibTeX-Ruby
2
2
  ===========
3
3
 
4
4
  The BibTeX-Ruby package contains a parser for BibTeX bibliography files and a
5
- class structure to manage BibTeX objects in Ruby. It is designed to support all
6
- BibTeX objects (including @comment, string-replacements via @string, as well
7
- as string concatenation using '#') and handles all content outside of BibTeX
8
- objects as 'meta comments' which may or may not be included in post-processing.
5
+ class structure to manage or convert BibTeX objects in Ruby. It is designed to
6
+ support all BibTeX objects (including @comment, string-replacements via @string,
7
+ as well as string concatenation using '#') and handles all content outside of
8
+ BibTeX objects as 'meta comments' which may or may not be included in
9
+ post-processing.
9
10
 
10
11
 
11
12
  Quickstart
12
13
  ----------
13
14
 
14
- $ irb
15
- > require 'bibtex'
16
- => true
17
- > bib = BibTeX::Bibliography.open('./ruby.bib')
18
- => book{pickaxe,
19
- address {Raleigh, North Carolina},
20
- author {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
21
- date-added {2010-08-05 09:54:07 0200},
22
- date-modified {2010-08-05 10:07:01 0200},
23
- keywords {ruby},
24
- publisher {The Pragmatic Bookshelf},
25
- series {The Facets of Ruby},
26
- title {Programming Ruby 1.9: The Pragmatic Programmers Guide},
27
- year {2009}
28
- }
29
- > bib[:pickaxe][:author]
30
- => ["Thomas, Dave, and Fowler, Chad, and Hunt, Andy"]
31
- > bib[:pickaxe].author
32
- => ["Thomas, Dave, and Fowler, Chad, and Hunt, Andy"]
33
- > bib[:pickaxe].author = ['Thomas, D., Fowler, C., and Hunt, A.']
34
- => ["Thomas, D., and Fowler, C., and Hunt, A."]
15
+ $ [sudo] gem install bibtex-ruby
16
+ $ irb
17
+ > require 'bibtex'
18
+ => true
19
+ > bib = BibTeX.open('./ruby.bib')
20
+ => book{pickaxe,
21
+ address {Raleigh, North Carolina},
22
+ author {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
23
+ date-added {2010-08-05 09:54:07 0200},
24
+ date-modified {2010-08-05 10:07:01 0200},
25
+ keywords {ruby},
26
+ publisher {The Pragmatic Bookshelf},
27
+ series {The Facets of Ruby},
28
+ title {Programming Ruby 1.9: The Pragmatic Programmers Guide},
29
+ year {2009}
30
+ }
31
+ > bib[:pickaxe].year
32
+ => "2009"
33
+ > bib[:pickaxe][:title]
34
+ => "Programming Ruby 1.9: The Pragmatic Programmer's Guide"
35
+ > bib[:pickaxe].author = 'Thomas, D., Fowler, C., and Hunt, A.'
36
+ => "Thomas, D., and Fowler, C., and Hunt, A."
35
37
 
36
38
 
37
39
  Installation
@@ -39,63 +41,134 @@ Installation
39
41
 
40
42
  If you just want to use it:
41
43
 
42
- $ [sudo] gem install bibtex-ruby
44
+ $ [sudo] gem install bibtex-ruby
43
45
 
44
46
  If you want to work with the sources:
45
47
 
46
- $ [sudo] gem install racc
47
- $ git clone http://github.com/inukshuk/bibtex-ruby.git
48
- $ cd bibtex-ruby
49
- $ rake racc
50
- $ rake rdoc
51
- $ rake test
48
+ $ git clone http://github.com/inukshuk/bibtex-ruby.git
49
+ $ cd bibtex-ruby
50
+ $ [sudo] bundle install
51
+ $ rake racc
52
+ $ rake rdoc
53
+ $ rake test
52
54
 
53
- Or, alternatively, fork the [project on github](http://github.com/inukshuk/bibtex-ruby.git).
55
+ Or, alternatively, fork the [project on GitHub](http://github.com/inukshuk/bibtex-ruby.git).
54
56
 
55
57
 
56
58
  Requirements
57
59
  ------------
58
60
 
59
- * The parser generator [racc](http://i.loveruby.net/en/projects/racc/) is required to generate parser.
60
- * The *minitest* gem is required to run the tests in older Ruby versions (prior to 1.9).
61
- * The *json* gem is required on older ruby versions for JSON export (prior to 1.9).
61
+ * The parser generator [racc](http://i.loveruby.net/en/projects/racc/) is
62
+ required to generate parser.
63
+ * The *minitest* gem is required to run the tests in older Ruby versions.
64
+ * The *json* gem is required on older Ruby versions for JSON export.
65
+
66
+ The bibtex-ruby gem has been tested on Ruby versions 1.8.7 and 1.9.2; it has
67
+ been confirmed to work with REE 1.8.7 x86_64 and JRuby 1.5.6 x86_64-java. It
68
+ does not work with MacRuby 0.8 because of a bug in MacRuby's implementation
69
+ of the *StringScanner* class, however, this has been fixed in SVN (see
70
+ [#1](https://github.com/inukshuk/bibtex-ruby/issues/closed#issue/1) for details).
71
+
62
72
 
63
73
 
64
74
  Usage
65
75
  -----
66
76
 
67
- It is very easy to use BibTeX-Ruby. You can use the class method `BibTeX::Bibliography.open`
68
- to open a '.bib' file. Normally, BibTeX-Ruby will discard all content outside of
69
- regular BibTeX elements; however, if you wish to include everything, simply add
70
- `:include => [:meta_comments]` to your invocation of `BibTeX::Bibliography.open`.
77
+ It is very easy to use BibTeX-Ruby. You can use the top level utility methods
78
+ **BibTeX.open** and **BibTeX.parse** to open a '.bib' file or to parse a string
79
+ containing BibTeX contents. Normally, BibTeX-Ruby will discard all text outside
80
+ of regular BibTeX elements; however, if you wish to include everything, simply add
81
+ `:include => [:meta_comments]` to your invocation of **BibTeX.open** or **BibTeX.parse**.
71
82
 
72
83
  Once BibTeX-Ruby has parsed your '.bib' file, you can easily access individual entries.
73
- For example, if your bibliography object `bib` contained the following entry:
74
-
75
- @book{pickaxe,
76
- address = {Raleigh, North Carolina},
77
- author = {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
78
- date-added = {2010-08-05 09:54:07 +0200},
79
- date-modified = {2010-08-05 10:07:01 +0200},
80
- keywords = {ruby},
81
- publisher = {The Pragmatic Bookshelf},
82
- series = {The Facets of Ruby},
83
- title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
84
- year = {2009}
85
- }
86
-
84
+ For example, if you set up your bibliography as follows:
85
+
86
+ bib = BibTeX.parse <<-END
87
+ @book{pickaxe,
88
+ address = {Raleigh, North Carolina},
89
+ author = {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
90
+ date-added = {2010-08-05 09:54:07 +0200},
91
+ date-modified = {2010-08-05 10:07:01 +0200},
92
+ keywords = {ruby},
93
+ publisher = {The Pragmatic Bookshelf},
94
+ series = {The Facets of Ruby},
95
+ title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
96
+ year = {2009}
97
+ }
98
+ END
99
+
87
100
  You could easily access it, using the entry's key, 'pickaxe', like so: `bib[:pickaxe]`;
88
- you also have easy access to individual fields, for example: `bib[:pickaxe](:author)`.
101
+ you also have easy access to individual fields, for example: `bib[:pickaxe][:author]`.
102
+ Alternatively, BibTeX-Ruby accepts ghost methods to conveniently access an entry's fields,
103
+ similar to **ActiveRecord::Base**. Therefore, it is equally possible to access the
104
+ 'author' field above as `bib[:pickaxe].author`.
105
+
106
+ Instead of parsing strings you can also create BibTeX elements by using Ruby:
107
+
108
+ > bib = BibTeX::Bibliography.new
109
+ > bib << BibTeX::Entry.new({
110
+ > :type => :book,
111
+ > :key => 'rails',
112
+ > :address => 'Raleigh, North Carolina',
113
+ > :author => 'Ruby, Sam, and Thomas, Dave, and Hansson, David Heinemeier',
114
+ > :booktitle => 'Agile Web Development with Rails',
115
+ > :edition => 'third',
116
+ > :keywords => 'ruby, rails',
117
+ > :publisher => 'The Pragmatic Bookshelf',
118
+ > :series => 'The Facets of Ruby',
119
+ > :title => 'Agile Web Development with Rails',
120
+ > :year => '2009'
121
+ > })
122
+ > book = BibTeX::Entry.new
123
+ > book.type = :book
124
+ > book.key = 'mybook'
125
+ > bib << book
126
+
127
+
128
+
129
+ ### String Replacement
89
130
 
90
131
  If your bibliography contains BibTeX @string objects, you can let BibTeX-Ruby
91
132
  replace the strings for you. You have access to a bibliography's strings via
92
- `BibTeX::Bibliography#strings` and you can replace the strings of an entry using
93
- the `BibTeX::Entry#replace!` method. Thus, to replace all strings defined in your
94
- bibliography object `bib` your could use this code:
95
-
96
- bib.entries.each do |entry|
97
- entry.replace!(bib.strings)
98
- end
133
+ **BibTeX::Bibliography#strings** and you can replace the strings of an entry using
134
+ the **BibTeX::Entry#replace!** method. Thus, to replace all strings defined in your
135
+ bibliography object **bib** your could use this code:
136
+
137
+ bib.entries.each do |entry|
138
+ entry.replace!(bib.strings)
139
+ end
140
+
141
+ A shorthand version for replacing all strings in a given bibliography is the
142
+ `Bibliography#replace_strings` method. Similarly, you can use the
143
+ `Bibliography#join_strings` method to join individual strings together. For instance:
144
+
145
+ > bib = BibTeX::Bibliography.new
146
+ > bib.add BibTeX::Element.parse '@string{ foo = "foo" }'
147
+ > bib.add BibTeX::Element.parse '@string{ bar = "bar" }'
148
+ > bib.add BibTeX::Element.parse <<-END
149
+ > @book{abook,
150
+ > author = foo # "Author",
151
+ > title = foo # bar
152
+ > }
153
+ > END
154
+ > puts bib[:abook].to_s
155
+ @book{abook,
156
+ author = foo # "Author",
157
+ title = foo # bar
158
+ }
159
+ > bib.replace_strings
160
+ > puts bib[:abook].to_s
161
+ @book{abook,
162
+ author = "foo" # "Author",
163
+ title = "foo" # "bar"
164
+ }
165
+ > bib.join_strings
166
+ @book{abook,
167
+ author = {fooAuthor},
168
+ title = {foobar}
169
+ }
170
+
171
+ ### Conversions
99
172
 
100
173
  Furthermore, BibTeX-Ruby allows you to export your bibliography for processing
101
174
  by other tools. Currently supported formats include YAML, JSON, and XML.
@@ -104,10 +177,15 @@ Of course, you can also export your bibliography back to BibTeX; if you include
104
177
  except for whitespace, blank lines and letter case (BibTeX-Ruby will downcase
105
178
  all keys).
106
179
 
107
- In order to export your bibliography use `#to_s`, `#to_yaml`, `#to_json`, or
108
- `#to_xml`, respectively.
180
+ In order to export your bibliography use **#to\_s**, **#to\_yaml**, **#to\_json**, or
181
+ **#to\_xml**, respectively. For example, the following line constitutes a simple
182
+ BibTeX to YAML converter:
183
+
184
+ BibTeX.open('example.bib').to_yaml
185
+
186
+ Look at the 'examples' directory for more elaborate examples of a BibTeX to YAML
187
+ and a BibTeX to HTML converter.
109
188
 
110
- Look at the 'examples' directory for a simple BibTeX to YAML and BibTeX to HTML converter.
111
189
 
112
190
 
113
191
  The Parser
@@ -143,7 +221,7 @@ number of general remarks:
143
221
 
144
222
  * BibTeX-Ruby begins in comment-mode, treating all text it encounters as comments.
145
223
  Normally these comments are ignored; however, if you wish the parser to include
146
- them, you can do so by adding the symbol `:meta_comments`` to the `:include`` array
224
+ them, you can do so by adding the symbol `:meta_comments` to the `:include` array
147
225
  in the parser's options.
148
226
  * Note that string literals in BibTeX are either contained in quotes or braces;
149
227
  nested quotes in a quoted literal are not escaped with a usual backslash but
@@ -185,8 +263,8 @@ constants can be used within string assignments in other @string or @preamble
185
263
  objects, as well as in regular BibTeX entries. For example, this is a valid constant
186
264
  definition and usage:
187
265
 
188
- @string{ generator = "BibTeX-Ruby"}
189
- @preamble{ "This bibliography was generated by " # generator }
266
+ @string{ generator = "BibTeX-Ruby"}
267
+ @preamble{ "This bibliography was generated by " # generator }
190
268
 
191
269
 
192
270
  ### @preamble
data/Rakefile CHANGED
@@ -1,62 +1,13 @@
1
1
  # -*- ruby -*-
2
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
3
 
3
4
  require 'rubygems'
4
5
  require 'rake'
5
6
  require 'rake/clean'
6
7
  require 'rake/testtask'
7
8
  require 'rake/rdoctask'
8
- require 'rake/gempackagetask'
9
9
 
10
- require './lib/bibtex/version.rb'
11
-
12
-
13
- spec = Gem::Specification.new do |s|
14
- s.platform = Gem::Platform::RUBY
15
- s.name = 'bibtex-ruby'
16
- s.rubyforge_project = s.name
17
- s.version = BibTeX::Version::STRING
18
- s.summary = "A BibTeX parser written in Ruby"
19
- s.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)."
20
- s.homepage = 'http://inukshuk.github.com/bibtex-ruby'
21
- s.authors = ["Sylvester Keil"]
22
- s.email = 'http://sylvester.keil.or.at'
23
- s.cert_chain = ["/Users/sylvester/.gem/keys/gem-public_cert.pem"]
24
- s.signing_key = '/Users/sylvester/.gem/keys/gem-private_key.pem'
25
- s.has_rdoc = true
26
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "BibTeX-Ruby Documentation", "--main", "README.rdoc"]
27
- s.extra_rdoc_files = ["README.md"]
28
- s.files = File.open('Manifest').readlines.map(&:chomp)
29
- s.test_files = FileList['test/test*.rb']
30
- s.require_paths = ["lib"]
31
- s.date = Time.now
32
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
33
-
34
- if s.respond_to? :specification_version then
35
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
36
- s.specification_version = 3
37
-
38
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
39
- s.add_development_dependency('racc', [">= 1.4.6"])
40
- s.add_development_dependency('minitest', [">= 2.0.2"])
41
- s.add_development_dependency('json', [">= 1.5.0"])
42
- else
43
- s.add_dependency('racc', [">= 1.4.6"])
44
- s.add_dependency('minitest', [">= 2.0.2"])
45
- s.add_dependency('json', [">= 1.5.0"])
46
- end
47
- else
48
- s.add_dependency('racc', [">= 1.4.6"])
49
- s.add_dependency('minitest', [">= 2.0.2"])
50
- s.add_dependency('json', [">= 1.5.0"])
51
- end
52
-
53
- end
54
-
55
- Rake::GemPackageTask.new(spec) do |pkg|
56
- pkg.need_zip = true
57
- pkg.need_tar = true
58
- pkg.package_dir = 'build'
59
- end
10
+ require 'bibtex/version'
60
11
 
61
12
  Rake::RDocTask.new(:rdoc_task) do |rd|
62
13
  rd.main = 'README.md'
@@ -68,7 +19,7 @@ end
68
19
 
69
20
  Rake::TestTask.new(:test_task) do |t|
70
21
  t.libs << "test"
71
- t.test_files = FileList['test/test*.rb']
22
+ t.test_files = FileList['test/test_*.rb']
72
23
  t.verbose = true
73
24
  end
74
25
 
@@ -94,11 +45,19 @@ task :manifest => ['clean', 'racc'] do
94
45
  m.close
95
46
  end
96
47
 
48
+ desc 'Builds the gem file'
49
+ task :build => ['manifest'] do
50
+ system 'gem build bibtex-ruby.gemspec'
51
+ end
52
+
53
+ desc 'Pushes the gem file to rubygems.org'
54
+ task :release => ['build'] do
55
+ system "gem push bibtex-ruby-#{BibTeX::Version::STRING}"
56
+ end
97
57
 
98
58
  CLEAN.include('lib/bibtex/parser.rb')
99
59
  CLEAN.include('lib/bibtex/parser.output')
100
60
  CLEAN.include('doc/html')
101
- CLEAN.include('build')
102
-
61
+ CLEAN.include('*.gem')
103
62
 
104
63
  # vim: syntax=ruby
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+
5
+ require 'bibtex/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'bibtex-ruby'
9
+ s.version = BibTeX::Version::STRING
10
+ s.platform = Gem::Platform::RUBY
11
+ s.authors = ['Sylvester Keil']
12
+ s.email = 'http://sylvester.keil.or.at'
13
+ s.homepage = 'http://inukshuk.github.com/bibtex-ruby'
14
+ s.summary = 'A BibTeX parser and converter written in Ruby.'
15
+ s.description = 'A (fairly complete) BibTeX parser written in Ruby. Supports regular BibTeX entries, @comments, string replacement via @string. Allows for easy export/conversion to formats such as YAML, JSON, and XML.'
16
+ s.date = Time.now
17
+
18
+ s.required_rubygems_version = '>= 1.3.6'
19
+ s.rubyforge_project = s.name
20
+
21
+ s.add_development_dependency('racc', ['>= 1.4.6'])
22
+ s.add_development_dependency('minitest', ['>= 2.0.2'])
23
+ s.add_development_dependency('json', ['>= 1.5.0'])
24
+
25
+ s.files = File.open('Manifest').readlines.map(&:chomp)
26
+ s.test_files = Dir.glob('test/test*.rb')
27
+ s.executables = []
28
+ s.require_path = 'lib'
29
+
30
+ s.has_rdoc = true
31
+ s.rdoc_options = %w{--line-numbers --inline-source --title "BibTeX-Ruby Documentation" --main README.md --webcvs=http://github.com/inukshuk/bibtex-ruby/tree/master/}
32
+ s.extra_rdoc_files = %w{README.md}
33
+
34
+ end
35
+
36
+ # vim: syntax=ruby