Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions python/citation_vim/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_sub_source(self):
output = []
for item in self.get_items():
if self.context['collection'] == "" or self.context['collection'] in item.collections:
output.append(self.item_to_array(item))
output.append(item.to_list(self.context))
return output

def get_collections(self):
Expand Down Expand Up @@ -66,30 +66,20 @@ def filter_duplicate_keys(self):
output = []
for item in items:
if last_item.key == item.key:
output.append(self.item_to_array(item))
output.append(item.to_list(self.context))
last_item = item
return output

def item_to_array(self, item):
return [
getattr(item, self.context['source_field']),
item.describe(self.context),
item.file,
item.combined,
]

def get_items(self):
"""
Returns items from cache or parser
Returns items from cache or parser
"""
if self.cache and self.is_cached():
if self.cache and self.is_cached():
return self.read_cache()
parser = self.get_parser()
items = parser.load()
if self.context['reverse_order']:
items = parser.load()
items.reverse()
else:
items = parser.load()
if self.cache:
self.write_cache(items)
return items
Expand Down
8 changes: 8 additions & 0 deletions python/citation_vim/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,11 @@ def get_field_value(self, field):
def wrap(self, string):
wrapper = self.context['wrap_chars']
return u'%s%s%s' % (wrapper[0], string, wrapper[1])

def to_list(self, context):
return [
getattr(self, self.context['source_field']),
self.describe(self.context),
self.file,
self.combined,
]