-
Notifications
You must be signed in to change notification settings - Fork 14
/
global.rb
60 lines (48 loc) · 1.65 KB
/
global.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# encoding: UTF-8
$:.push(File.dirname($0))
require 'utility-functions'
# Contains keyboard related functionality which can be invoked from any publication
# triggered through Cmd+. shows a Pashua list of all references with titles
# upon selection, a properly formatted citation like [@scardamalia2004knowledge] is inserted
def bib_selector
require 'pashua'
include Pashua
bib = json_bib
config = "
*.title = researchr
cb.type = combobox
cb.completion = 2
cb.label = Insert a citation
cb.width = 800
cb.tooltip = Choose from the list or enter another name
db.type = cancelbutton
db.label = Cancel
db.tooltip = Closes this window without taking action"
# create list of citations
out = ''
json_bib.sort.each do |a|
out << "cb.option = #{a[0]}: #{a[1][3][0..90]}\n"
end
# show dialogue
pagetmp = pashua_run config + out
exit if pagetmp['cancel'] == 1
/^(?<citekey>.+?)\:/ =~ pagetmp['cb'] # extract citekey from citekey + title string
pbcopy("[@#{citekey}]")
end
# grab from clipboard, either look up DOI through API, or
# use anystyle parser to convert text to bibtex. Paste to clipboard.
def anystyle_parse
search = pbpaste
if search.downcase[0..2] == "doi" || search.index("dx.doi.org") || (search =~ /^10\./ && !search.strip.index(" "))
growl "Looking up DOI"
bibtex = doi_to_bibtex(search)
fail "DOI lookup not successful" unless bibtex
else
require 'anystyle/parser'
search = search.gsub("-\n", "").gsub("\n", " ")
bibtex = Anystyle.parse(search, :bibtex).to_s
fail "Could not parse string" if bibtex == search
end
pbcopy(cleanup_bibtex_string(bibtex))
end
send *ARGV unless ARGV == []