We are currently deploying GitLab EE 10.4.0-rc5. For status updates, please follow https://twitter.com/GitLabStatus

Commit ace439ec by Erik Hetzner

id -> easyKey

parent e2d7092e
......@@ -5,35 +5,35 @@ import unittest2
class TestJsonencoder(unittest2.TestCase):
def setUp(self):
self.encoder = ZoteroJSONEncoder()
self.citation = CitationInfo(key="foo")
self.citation = CitationInfo(citekey="foo")
self.citation.id = "foo"
citation2 = CitationInfo(key="bar")
citation2 = CitationInfo(citekey="bar")
citation2.id = "bar"
self.citation_cluster = CitationCluster([self.citation, citation2])
def test_basic(self):
json = self.encoder.encode(self.citation)
self.assertEqual(json, '{"id": "foo"}')
self.assertEqual(json, '{"easyKey": "foo"}')
def test_suppress_author(self):
self.citation.suppress_author = True
json = self.encoder.encode(self.citation)
self.assertEqual(json, '{"suppress-author": true, "id": "foo"}')
self.assertEqual(json, '{"easyKey": "foo", "suppress-author": true}')
def test_author_only(self):
self.citation.author_only = True
json = self.encoder.encode(self.citation)
self.assertEqual(json, '{"id": "foo", "author-only": true}')
self.assertEqual(json, '{"easyKey": "foo", "author-only": true}')
def test_all(self):
self.citation.prefix = "see"
self.citation.suffix = "and nowhere else",
self.citation.locator = "p. 10"
json = self.encoder.encode(self.citation)
self.assertEqual(json, '{"locator": "p. 10", "prefix": "see ", "id": "foo", "suffix": " and nowhere else"}')
self.assertEqual(json, '{"easyKey": "foo", "locator": "p. 10", "prefix": "see ", "suffix": " and nowhere else"}')
def test_cluster(self):
self.citation_cluster.index = 2
self.citation_cluster.note_index = 3
json = self.encoder.encode(self.citation_cluster)
self.assertEqual(json, '{"citationItems": [{"id": "foo"}, {"id": "bar"}], "properties": {"index": 2, "noteIndex": 3}}')
self.assertEqual(json, '{"citationItems": [{"easyKey": "foo"}, {"easyKey": "bar"}], "properties": {"index": 2, "noteIndex": 3}}')
......@@ -5,19 +5,19 @@ class CitationInfo(object):
"""Class to hold information about a citation for passing to
citeproc."""
def __init__(self, **kwargs):
self.citekey = kwargs.get('citekey')
self.label = kwargs.get('label', None)
self.locator = kwargs.get('locator', None)
self.suppress_author = kwargs.get('suppress_author', False)
self.prefix = kwargs.get('prefix', None)
def __init__(self, citekey, label=None, locator=None, suppress_author=False, prefix=None, suffix=None, author_only=False, theid=None):
self.citekey = citekey
self.label = label
self.locator = locator
self.suppress_author = suppress_author
self.prefix = prefix
if self.prefix:
self.prefix = re.sub(r'\s+,', ',', self.prefix)
self.suffix = kwargs.get('suffix', None)
self.suffix = suffix
if self.suffix:
self.suffix = re.sub(r'\s+,', ',', self.suffix)
self.author_only = kwargs.get('author_only', False)
self.id = kwargs.get('id', None)
self.author_only = author_only
self.id = theid
def __str__(self):
if self.suppress_author: suppress_str = "-"
......
......@@ -6,8 +6,11 @@ class ZoteroJSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, CitationInfo):
retval = {}
if obj.id: retval['id'] = obj.id
if obj.citekey: retval['easyKey'] = obj.citekey
# need to make a decision here at some point
if obj.citekey:
retval['easyKey'] = obj.citekey
elif obj.id:
retval['id'] = obj.id
if obj.prefix: retval['prefix'] = "%s "%(obj.prefix) # ensure spaces in prefix, suffix
if obj.suffix: retval['suffix'] = " %s"%(obj.suffix)
if obj.label: retval['label'] = obj.label
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment