Skip to content

Instantly share code, notes, and snippets.

@inukshuk
Created January 27, 2014 21:44
Show Gist options
  • Save inukshuk/8657987 to your computer and use it in GitHub Desktop.
Save inukshuk/8657987 to your computer and use it in GitHub Desktop.
Experiment with the CiteProc-Ruby pre-release!
require 'nokogiri' # optional
require 'edtf' # optional
require 'citeproc'
require 'bibtex'
require 'csl/styles'
cp = CiteProc::Processor.new locale: 'en', style: 'apa', format: 'html'
bib = BibTeX.parse(<<-EOS)
@article{greenwade93,
author = "George D. Greenwade",
title = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
year = "1993",
journal = "TUGBoat",
volume = "14",
number = "3",
pages = "342--351"
}
EOS
bib.convert :latex
cp.import bib.to_citeproc
puts cp.render :citation, id: 'greenwade93', locator: '23'
puts cp.render :citation, id: 'greenwade93', locator: '23-26'
puts cp.render :bibliography, id: 'greenwade93'
# Change the style
cp.options[:style] = 'chicago-author-date'
cp.engine.update!
puts cp.render :bibliography, id: 'greenwade93'
# Parse the CSL Snippet below (can be a full style too)
csl = CSL.parse!(DATA)
# Fetch a citation item from the processor
item = cp['greenwade93']
# Render the item with the csl snippet
puts cp.engine.renderer.render item.cite, csl
__END__
<bibliography>
<layout suffix=".">
<group delimiter=" ">
<label variable="page"/>
<text variable="page"/>
</group>
</layout>
</bibliography>
source 'https://rubygems.org'
gem 'citeproc', :git => 'https://github.com/inukshuk/citeproc.git'
gem 'citeproc-ruby', :git => 'https://github.com/inukshuk/citeproc-ruby.git'
gem 'csl', :git => 'https://github.com/inukshuk/csl-ruby.git'
gem 'nokogiri' # not required: speeds up XML parsing
gem 'edtf' # not required: more advanced name parsers
gem 'bibtex-ruby'
# not required but convenient: gives you
# local access to all CSL styles and locales
gem 'csl-styles'
@andriusvelykis
Copy link

Weird, it works now :) Dunno what has changed (I have rebuilt it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment