inukshuk / citeproc-ruby

A Citation Style Language (CSL) Cite Processor
101 stars 22 forks source link

Example in Readme.md does not work #1

Closed houshuang closed 13 years ago

houshuang commented 13 years ago

The example given in Readme.md does not work. I typed exactly the same into my IRB, after installing the Gem:

irb(main):001:0> require 'rubygems' => false irb(main):002:0> require 'citeproc' => true irb(main):003:0> book = { irb(main):004:1* 'author' => [{ 'given' => 'Edgar Allen', 'family' => 'Poe' }], irb(main):005:1* 'title' => 'Poetry, Tales, and Selected Essays', irb(main):006:1* 'type' => 'book', irb(main):007:1* 'issued' => { 'date-parts' => [[1996]] }, irb(main):008:1* 'editor' => [{ 'family' => 'Quinn', 'given' => 'Patrick F.'}, { 'family' => 'Thompson', 'given' => 'G.R.' }], irb(main):009:1* 'publisher' => 'Library of America', irb(main):010:1* 'publisher-place' => 'New York' irb(main):011:1> } => {"author"=>[{"given"=>"Edgar Allen", "family"=>"Poe"}], "title"=>"Poetry, Tales, and Selected Essays", "type"=>"book", "issued"=>{"date-parts"=>[[1996]]}, "editor"=>[{"family"=>"Quinn", "given"=>"Patrick F."}, {"family"=>"Thompson", "given"=>"G.R."}], "publisher"=>"Library of America", "publisher-place"=>"New York"} irb(main):012:0> CiteProc.process(book) NameError: uninitialized constant Object::CiteProc from (irb):12 from /usr/local/bin/irb19:12:in `

'

I get a bit further if I use Citeproc instead of CiteProc

irb(main):013:0> Citeproc.process(book) NoMethodError: undefined method process' for Citeproc:Module from (irb):13 from /usr/local/bin/irb19:12:in

'

But still can't get there.

A functioning example would be very helpful - I tried looking at the rspecs, but I couldn't make much sense of them.

inukshuk commented 13 years ago

Thanks for trying citeproc-ruby. As it says in the Readme, this is still an experimental release, however, the example below should work just fine (I just tried this):

$ ruby -v
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]
$ gem i citeproc-ruby
Fetching: citeproc-ruby-0.0.1.gem (100%)
Successfully installed citeproc-ruby-0.0.1
1 gem installed
Installing ri documentation for citeproc-ruby-0.0.1...
Building YARD (yri) index for citeproc-ruby-0.0.1...
Installing RDoc documentation for citeproc-ruby-0.0.1...
$ irb
>> require 'citeproc'
=> true
>> defined? CiteProc
=> "constant"
>> book = {
...
>>       }
=> {"author"=>[{"given"=>"Edgar Allen", "family"=>"Poe"}], "title"=>"Poetry, ...
>> CiteProc.process(book, :style => 'https://github.com/citation-style-language/styles/raw/master/chicago-author-date.csl')
=> "Poe, Edgar Allen. 1996. Poetry, Tales, and Selected Essays. Ed. Patrick F. Quinn and G.R. Thompson. New York: Library of America."
>> CiteProc.process(book, :style => 'https://github.com/citation-style-language/styles/raw/master/chicago-author-date.csl', :format => 'html')
=> "Poe, Edgar Allen. 1996. <i>Poetry, Tales, and Selected Essays</i>. Ed. Patrick F. Quinn and G.R. Thompson. New York: Library of America."

A couple of things to note:

Hope that helps!

houshuang commented 13 years ago

Thank you very much for your quick reply - and for creating citeproc-ruby. It's exactly what I need for my little project (inserting formatted bibliography snippets in a Dokuwiki, from a Bibdesk file).

Here's what I did:

Stian-Haklevs-MacBook-Pro:~ stian$ ruby19 -v ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.3] Stian-Haklevs-MacBook-Pro:~ stian$ sudo gem19 i citeproc-ruby Password: Successfully installed citeproc-ruby-0.0.1 1 gem installed Installing ri documentation for citeproc-ruby-0.0.1... file 'Documentation"' not found Installing RDoc documentation for citeproc-ruby-0.0.1... file 'Documentation"' not found Stian-Haklevs-MacBook-Pro:~ stian$ irb19 irb(main):001:0> require 'citeproc' => true irb(main):002:0> defined? CiteProc => nil irb(main):003:0> $: => ["/usr/local/lib/ruby/gems/1.9.1/gems/citeproc-rb-0.0.1/lib", "/usr/local/lib/ruby/gems/1.9.1/gems/builder-3.0.0/lib", "/usr/local/lib/ruby/site_ruby/1.9.1", "/usr/local/lib/ruby/site_ruby/1.9.1/x86_64-darwin10.7.3", "/usr/local/lib/ruby/site_ruby", "/usr/local/lib/ruby/vendor_ruby/1.9.1", "/usr/local/lib/ruby/vendor_ruby/1.9.1/x86_64-darwin10.7.3", "/usr/local/lib/ruby/vendor_ruby", "/usr/local/lib/ruby/1.9.1", "/usr/local/lib/ruby/1.9.1/x86_64-darwin10.7.3"] irb(main):004:0>

inukshuk commented 13 years ago

I think I spotted the problem there:

irb(main):003:0
> $: => ["/usr/local/lib/ruby/gems/1.9.1/gems/citeproc-rb-0.0.1/lib",

You seem to have the citeproc-rb gem installed, which is loaded instead of citeproc-ruby. I guess citeproc-rb is using the same name so right now you should have only one of them installed (if this is a problem going forward, I'll have to address that but I think citeproc-rb isn't being actively developed anymore).

As regards inserting formatted biliography snippets I think citeproc-ruby is pretty much usable for that purpose right now (although I haven't made stuff like bibliography headers editable etc.) --- but there is no disambiguation support yet (this is because the cite processing is still very much in progress).

Having said that, my original use-case was pretty similar to yours (converting bibdesk bibliographies); I haven't come around to doing it, but I was going to write a quick script that reads in .bib files and generates a formatted bibliography. Let me know, if this sounds useful to you and I'll keep you in the loop.

houshuang commented 13 years ago

Thanks, that makes a lot of sense!

Yeah, so far I am just going through, extracting each unique cite key, throwing them into a file with @, and running the file through pandoc, which creates a nicely formatted bibliography. I then open the file, and read each citation in, and match it with the citekey, etc. A bit of a work around, but works well enough. :) Having citeproc right in Ruby would be a lot more flexible though.

I'll share whatever I come up with too.

Thanks!