bibsync 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bibsync.rb +1 -0
- data/lib/bibsync/bibliography.rb +5 -3
- data/lib/bibsync/command.rb +2 -2
- data/lib/bibsync/{actions/jabref.xml → jabref.xml} +0 -0
- data/lib/bibsync/jabref_formatter.rb +18 -0
- data/lib/bibsync/version.rb +1 -1
- data/test/fixture/test.bib +4 -0
- data/test/test_bibliography.rb +22 -0
- metadata +5 -6
- data/lib/bibsync/actions/jabref_format.rb +0 -22
- data/test/actions/test_jabref_format.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ee82317ca7e8c3e5fa9de627bfd9b2f240dced2
|
4
|
+
data.tar.gz: 547ff333dc6cb12d5b98e3280aed47aa539889b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3778420afe0ea4faeedca5e56c74c7f518f258ddc4cc6ce1dcc09d63fc62b42fa77ec752bc9b5ae0c2c74fbf79138abd3aeb5ee4d00cfe75530e2a7b7540d0bd
|
7
|
+
data.tar.gz: f68cd142a1f99b983df76b3b311def93d0a765d4af8ff1b7d2222d96812b2fd70d7ca5683362a42a31e84ca730a475a393e11303ef8c866907d203feb9860574
|
data/lib/bibsync.rb
CHANGED
data/lib/bibsync/bibliography.rb
CHANGED
@@ -4,12 +4,13 @@ module BibSync
|
|
4
4
|
extend Forwardable
|
5
5
|
|
6
6
|
attr_reader :file
|
7
|
-
attr_accessor :
|
7
|
+
attr_accessor :transform_hook, :format_hook
|
8
8
|
def_delegators :@entries, :empty?, :size
|
9
9
|
def_delegator :@entries, :each_value, :each
|
10
10
|
|
11
11
|
def initialize(file = nil)
|
12
|
-
@entries
|
12
|
+
@entries = {}
|
13
|
+
@transform_hook, @format_hook = nil, nil
|
13
14
|
load(file)
|
14
15
|
end
|
15
16
|
|
@@ -54,10 +55,11 @@ module BibSync
|
|
54
55
|
|
55
56
|
raise 'No filename given' unless @file
|
56
57
|
if @dirty
|
57
|
-
@
|
58
|
+
@transform_hook.call(self) if @transform_hook
|
58
59
|
tmpfile = "#{@file}.tmp"
|
59
60
|
begin
|
60
61
|
File.open(tmpfile, 'w') {|f| f.write(self) }
|
62
|
+
@format_hook.call(tmpfile) if @format_hook
|
61
63
|
File.rename(tmpfile, @file)
|
62
64
|
ensure
|
63
65
|
File.unlink(tmpfile) rescue nil
|
data/lib/bibsync/command.rb
CHANGED
@@ -90,7 +90,8 @@ module BibSync
|
|
90
90
|
|
91
91
|
if @options[:bib]
|
92
92
|
bib = @options[:bib] = Bibliography.new(@options[:bib])
|
93
|
-
bib.
|
93
|
+
bib.transform_hook = Transformer.new
|
94
|
+
bib.format_hook = JabRefFormatter.new if @options[:jabref]
|
94
95
|
at_exit { bib.save }
|
95
96
|
end
|
96
97
|
|
@@ -100,7 +101,6 @@ module BibSync
|
|
100
101
|
actions << :SynchronizeFiles << :DetermineArXivDOI << :SynchronizeMetadata if @options[:sync] || @options[:resync]
|
101
102
|
actions << :FindMyCitations if @options[:citedbyme]
|
102
103
|
actions << :Validate if @options[:bib]
|
103
|
-
actions << :JabRefFormat if @options[:jabref]
|
104
104
|
|
105
105
|
if actions.empty?
|
106
106
|
puts "Please specify actions! See #{$0} --help"
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module BibSync
|
2
|
+
class JabRefFormatter
|
3
|
+
include Log
|
4
|
+
|
5
|
+
def call(file)
|
6
|
+
if File.read(file, 80) !~ /JabRef/
|
7
|
+
notice 'Transforming file with JabRef'
|
8
|
+
tmp_file = "#{file}.formatted.bib"
|
9
|
+
begin
|
10
|
+
`jabref --primp #{Shellwords.escape File.join(File.dirname(__FILE__), 'jabref.xml')} --nogui --import #{Shellwords.escape file} --output #{Shellwords.escape tmp_file} 2>&1 >/dev/null`
|
11
|
+
File.rename(tmp_file, file) if File.exists?(tmp_file)
|
12
|
+
ensure
|
13
|
+
File.unlink(tmp_file) rescue nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/bibsync/version.rb
CHANGED
data/test/fixture/test.bib
CHANGED
data/test/test_bibliography.rb
CHANGED
@@ -114,6 +114,28 @@ describe BibSync::Bibliography do
|
|
114
114
|
end
|
115
115
|
|
116
116
|
describe '#save' do
|
117
|
+
it 'must support transform hook' do
|
118
|
+
begin
|
119
|
+
bib['NoShortJournal'][:shortjournal].must_equal nil
|
120
|
+
tmpfile = File.join(fixturedir, 'transform.bib')
|
121
|
+
bib.transform_hook = BibSync::Transformer.new
|
122
|
+
bib.save(tmpfile)
|
123
|
+
bib['NoShortJournal'][:shortjournal].must_equal 'PRL'
|
124
|
+
ensure
|
125
|
+
File.unlink(tmpfile) rescue nil
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'must support format hook' do
|
130
|
+
begin
|
131
|
+
tmpfile = File.join(fixturedir, 'format.bib')
|
132
|
+
bib.format_hook = BibSync::JabRefFormatter.new
|
133
|
+
bib.save(tmpfile)
|
134
|
+
File.read(tmpfile).must_match(/created\s+with\s+JabRef/)
|
135
|
+
ensure
|
136
|
+
File.unlink(tmpfile) rescue nil
|
137
|
+
end
|
138
|
+
end
|
117
139
|
end
|
118
140
|
|
119
141
|
describe '#<<' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bibsync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Mendler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -89,14 +89,14 @@ files:
|
|
89
89
|
- lib/bibsync/actions/determine_arxiv_doi.rb
|
90
90
|
- lib/bibsync/actions/fetch_from_arxiv.rb
|
91
91
|
- lib/bibsync/actions/find_my_citations.rb
|
92
|
-
- lib/bibsync/actions/jabref.xml
|
93
|
-
- lib/bibsync/actions/jabref_format.rb
|
94
92
|
- lib/bibsync/actions/synchronize_files.rb
|
95
93
|
- lib/bibsync/actions/synchronize_metadata.rb
|
96
94
|
- lib/bibsync/actions/validate.rb
|
97
95
|
- lib/bibsync/bibliography.rb
|
98
96
|
- lib/bibsync/command.rb
|
99
97
|
- lib/bibsync/entry.rb
|
98
|
+
- lib/bibsync/jabref.xml
|
99
|
+
- lib/bibsync/jabref_formatter.rb
|
100
100
|
- lib/bibsync/literal.rb
|
101
101
|
- lib/bibsync/log.rb
|
102
102
|
- lib/bibsync/transformer.rb
|
@@ -106,7 +106,6 @@ files:
|
|
106
106
|
- test/actions/test_determine_arxiv_doi.rb
|
107
107
|
- test/actions/test_fetch_from_arxiv.rb
|
108
108
|
- test/actions/test_find_my_citations.rb
|
109
|
-
- test/actions/test_jabref_format.rb
|
110
109
|
- test/actions/test_synchronize_files.rb
|
111
110
|
- test/actions/test_synchronize_metadata.rb
|
112
111
|
- test/actions/test_validate.rb
|
@@ -140,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
139
|
version: '0'
|
141
140
|
requirements: []
|
142
141
|
rubyforge_project: bibsync
|
143
|
-
rubygems_version: 2.0.
|
142
|
+
rubygems_version: 2.0.3
|
144
143
|
signing_key:
|
145
144
|
specification_version: 4
|
146
145
|
summary: BibSync is a tool to synchronize scientific papers and BibTeX bibliography
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module BibSync
|
2
|
-
module Actions
|
3
|
-
class JabRefFormat
|
4
|
-
include Utils
|
5
|
-
include Log
|
6
|
-
|
7
|
-
def initialize(options)
|
8
|
-
raise 'Option --bib is required' unless @bib = options[:bib]
|
9
|
-
end
|
10
|
-
|
11
|
-
def run
|
12
|
-
@bib.save
|
13
|
-
if File.read(@bib.file, 80) !~ /JabRef/
|
14
|
-
notice 'Transforming file with JabRef'
|
15
|
-
tmp_file = "#{@bib.file}.tmp.bib"
|
16
|
-
`jabref --primp #{Shellwords.escape File.join(File.dirname(__FILE__), 'jabref.xml')} --nogui --import #{Shellwords.escape @bib.file} --output #{Shellwords.escape tmp_file} 2>&1 >/dev/null`
|
17
|
-
File.rename(tmp_file, @bib.file) if File.exists?(tmp_file)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe BibSync::Actions::JabRefFormat do
|
4
|
-
before do
|
5
|
-
@tmpfile = File.join(fixturedir, 'tmp.bib')
|
6
|
-
FileUtils.copy(File.join(fixturedir, 'test.bib'), @tmpfile)
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
File.unlink(@tmpfile) if File.exists?(@tmpfile)
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:bib) do
|
14
|
-
BibSync::Bibliography.new(@tmpfile)
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:action) do
|
18
|
-
BibSync::Actions::JabRefFormat.new(bib: bib)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should format file' do
|
22
|
-
action.run
|
23
|
-
File.read(@tmpfile).must_match(/created\s+with\s+JabRef/)
|
24
|
-
end
|
25
|
-
end
|