Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate dependent CSL style
require 'csl' # gem install csl --pre
style = CSL::Style.new do |s|
s['class'] = 'in-text'
s['default-locale'] = 'en-US'
s.title = 'Natura'
s.id = 'http://www.zotero.org/styles/natura.csl'
# add default self link to id
s.self_link!
s.independent_parent_link = 'http://www.zotero.org/styles/foobar.csl'
s.documentation_link = 'http://natura.com'
s.info.issn = '7283-0918'
s.info.citation_format = 'numeric'
s.info.category = { field: 'biology'}
s.info.category = { field: 'physics'}
end
# style.dependent? #-> true
# style.independent_parent #-> would load and parse the parent style
# style.valid? #-> would make sure the style is valid
# add the default CC license
style.default_license!
# tag the updated field with the current time
style.info.update!
# puts style.to_xml #-> would output the style as xml
puts style.to_s #-> pretty prints the style as xml
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" version="1.0" class="in-text" default-locale="en-US">
<info>
<title>Natura</title>
<id>http://www.zotero.org/styles/natura.csl</id>
<issn>7283-0918</issn>
<link href="http://www.zotero.org/styles/natura.csl" rel="self"/>
<link href="http://www.zotero.org/styles/foobar.csl" rel="independent-parent"/>
<link href="http://natura.com" rel="documentation"/>
<category citation-format="numeric"/>
<category field="biology"/>
<category field="physics"/>
<updated>2013-03-28 18:33:35 +0100</updated>
<rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
</info>
</style>
@inukshuk

This comment has been minimized.

Copy link
Owner Author

commented Mar 28, 2013

This should include the xmlns in the style node – that's most likely a bug in the gem version, will be fixed upstream. : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.