middleman-citation 0.0.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/.yardopts +1 -0
- data/Gemfile +16 -1
- data/Gemfile.lock +129 -44
- data/Guardfile +12 -0
- data/README.md +37 -10
- data/Rakefile +20 -1
- data/features/support/env.rb +4 -0
- data/fixtures/test.bib +93 -0
- data/lib/middleman-citation.rb +52 -25
- data/lib/middleman-citation/citations.rb +33 -0
- data/lib/middleman-citation/version.rb +1 -1
- data/lib/middleman_extension.rb +1 -0
- data/middleman-citation.gemspec +2 -4
- data/spec/cite_spec.rb +47 -0
- data/spec/spec_helper.rb +100 -0
- metadata +29 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df3100f95e3b00a8dde2c4e7d4268cf900624e78
|
4
|
+
data.tar.gz: 5334dfdb4123806ec377c7adb1c08b0b48ca12e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de796752aab080082f670edde6de3eb85e6a14317e95311db17d448eef37af2d44f909cd40239f51b407264b7d00efbcf472ca61bdeda6c0d941b8a13bc0891b
|
7
|
+
data.tar.gz: cb4c6890411c2a8181818738fde1ec18c308ed2ee7ff57a67e0b2ab91c5472fa5241e9593dc0549a749fe6a7349d6e0ba1a503b943b1f80404c1bbb71412bc24
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
lib/**/*.rb
|
data/Gemfile
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in
|
3
|
+
# Specify your gem's dependencies in middleman-citation.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
+
group :development do
|
7
|
+
gem 'rake'
|
8
|
+
gem 'rdoc'
|
9
|
+
gem 'yard'
|
10
|
+
gem 'guard'
|
11
|
+
gem 'pry'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem 'cucumber'
|
16
|
+
gem 'aruba'
|
17
|
+
gem 'rspec'
|
18
|
+
gem 'rspec-html-matchers'
|
19
|
+
gem 'guard-rspec'
|
20
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,86 +1,171 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
middleman-citation (0.0.
|
4
|
+
middleman-citation (0.0.2.2)
|
5
5
|
bibtex-ruby
|
6
|
-
citeproc-ruby
|
6
|
+
citeproc-ruby
|
7
|
+
csl-styles
|
7
8
|
middleman-core (~> 3)
|
8
9
|
|
9
10
|
GEM
|
10
11
|
remote: https://rubygems.org/
|
11
12
|
specs:
|
12
|
-
activesupport (4.
|
13
|
-
i18n (~> 0.
|
13
|
+
activesupport (4.2.4)
|
14
|
+
i18n (~> 0.7)
|
14
15
|
json (~> 1.7, >= 1.7.7)
|
15
16
|
minitest (~> 5.1)
|
16
|
-
thread_safe (~> 0.
|
17
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
17
18
|
tzinfo (~> 1.1)
|
18
|
-
|
19
|
+
aruba (0.10.0)
|
20
|
+
childprocess (~> 0.5.6)
|
21
|
+
contracts (~> 0.9)
|
22
|
+
cucumber (>= 1.3.19)
|
23
|
+
ffi (~> 1.9.10)
|
24
|
+
rspec-expectations (>= 2.99)
|
25
|
+
thor (~> 0.19)
|
26
|
+
bibtex-ruby (4.0.14)
|
19
27
|
latex-decode (~> 0.0)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
28
|
+
builder (3.2.2)
|
29
|
+
capybara (2.4.4)
|
30
|
+
mime-types (>= 1.16)
|
31
|
+
nokogiri (>= 1.3.3)
|
32
|
+
rack (>= 1.0.0)
|
33
|
+
rack-test (>= 0.5.4)
|
34
|
+
xpath (~> 2.0)
|
35
|
+
childprocess (0.5.7)
|
36
|
+
ffi (~> 1.0, >= 1.0.11)
|
37
|
+
citeproc (1.0.1)
|
38
|
+
namae (~> 0.8)
|
39
|
+
citeproc-ruby (1.0.4)
|
40
|
+
citeproc (~> 1.0)
|
41
|
+
csl (~> 1.2)
|
42
|
+
coderay (1.1.0)
|
43
|
+
contracts (0.12.0)
|
44
|
+
csl (1.2.3)
|
45
|
+
namae (~> 0.7)
|
46
|
+
csl-styles (1.0.1.4)
|
47
|
+
csl (~> 1.0)
|
48
|
+
cucumber (2.1.0)
|
49
|
+
builder (>= 2.1.2)
|
50
|
+
cucumber-core (~> 1.3.0)
|
51
|
+
diff-lcs (>= 1.1.3)
|
52
|
+
gherkin3 (~> 3.1.0)
|
53
|
+
multi_json (>= 1.7.5, < 2.0)
|
54
|
+
multi_test (>= 0.1.2)
|
55
|
+
cucumber-core (1.3.0)
|
56
|
+
gherkin3 (~> 3.1.0)
|
57
|
+
diff-lcs (1.2.5)
|
25
58
|
erubis (2.7.0)
|
26
|
-
ffi (1.9.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
59
|
+
ffi (1.9.10)
|
60
|
+
formatador (0.2.5)
|
61
|
+
gherkin3 (3.1.2)
|
62
|
+
guard (2.13.0)
|
63
|
+
formatador (>= 0.2.4)
|
64
|
+
listen (>= 2.7, <= 4.0)
|
65
|
+
lumberjack (~> 1.0)
|
66
|
+
nenv (~> 0.1)
|
67
|
+
notiffany (~> 0.0)
|
68
|
+
pry (>= 0.9.12)
|
69
|
+
shellany (~> 0.0)
|
70
|
+
thor (>= 0.18.1)
|
71
|
+
guard-rspec (4.3.1)
|
72
|
+
guard (~> 2.1)
|
73
|
+
rspec (>= 2.14, < 4.0)
|
74
|
+
hooks (0.4.1)
|
75
|
+
uber (~> 0.0.14)
|
76
|
+
i18n (0.7.0)
|
77
|
+
json (1.8.3)
|
78
|
+
latex-decode (0.2.2)
|
32
79
|
unicode (~> 0.4)
|
33
|
-
listen (
|
34
|
-
celluloid (>= 0.15.2)
|
80
|
+
listen (3.0.3)
|
35
81
|
rb-fsevent (>= 0.9.3)
|
36
82
|
rb-inotify (>= 0.9)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
middleman-core (3.3.5)
|
42
|
-
activesupport (~> 4.1.0)
|
83
|
+
lumberjack (1.0.9)
|
84
|
+
method_source (0.8.2)
|
85
|
+
middleman-core (3.4.0)
|
86
|
+
activesupport (~> 4.1)
|
43
87
|
bundler (~> 1.1)
|
88
|
+
capybara (~> 2.4.4)
|
44
89
|
erubis
|
45
90
|
hooks (~> 0.3)
|
46
|
-
i18n (~> 0.
|
47
|
-
listen (
|
91
|
+
i18n (~> 0.7.0)
|
92
|
+
listen (~> 3.0.3)
|
48
93
|
padrino-helpers (~> 0.12.3)
|
49
94
|
rack (>= 1.4.5, < 2.0)
|
50
|
-
rack-test (~> 0.6.2)
|
51
95
|
thor (>= 0.15.2, < 2.0)
|
52
96
|
tilt (~> 1.4.1, < 2.0)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
97
|
+
mime-types (2.6.1)
|
98
|
+
mini_portile (0.6.2)
|
99
|
+
minitest (5.8.0)
|
100
|
+
multi_json (1.11.2)
|
101
|
+
multi_test (0.1.2)
|
102
|
+
namae (0.9.2)
|
103
|
+
nenv (0.2.0)
|
104
|
+
nokogiri (1.6.6.2)
|
105
|
+
mini_portile (~> 0.6.0)
|
106
|
+
notiffany (0.0.8)
|
107
|
+
nenv (~> 0.1)
|
108
|
+
shellany (~> 0.0)
|
109
|
+
padrino-helpers (0.12.5)
|
59
110
|
i18n (~> 0.6, >= 0.6.7)
|
60
|
-
padrino-support (= 0.12.
|
111
|
+
padrino-support (= 0.12.5)
|
61
112
|
tilt (~> 1.4.1)
|
62
|
-
padrino-support (0.12.
|
113
|
+
padrino-support (0.12.5)
|
63
114
|
activesupport (>= 3.1)
|
64
|
-
|
65
|
-
|
115
|
+
pry (0.10.3)
|
116
|
+
coderay (~> 1.1.0)
|
117
|
+
method_source (~> 0.8.1)
|
118
|
+
slop (~> 3.4)
|
119
|
+
rack (1.6.4)
|
120
|
+
rack-test (0.6.3)
|
66
121
|
rack (>= 1.0)
|
67
122
|
rake (10.3.2)
|
68
|
-
rb-fsevent (0.9.
|
123
|
+
rb-fsevent (0.9.6)
|
69
124
|
rb-inotify (0.9.5)
|
70
125
|
ffi (>= 0.5.0)
|
126
|
+
rdoc (4.2.0)
|
127
|
+
json (~> 1.4)
|
128
|
+
rspec (3.3.0)
|
129
|
+
rspec-core (~> 3.3.0)
|
130
|
+
rspec-expectations (~> 3.3.0)
|
131
|
+
rspec-mocks (~> 3.3.0)
|
132
|
+
rspec-core (3.3.2)
|
133
|
+
rspec-support (~> 3.3.0)
|
134
|
+
rspec-expectations (3.3.1)
|
135
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
136
|
+
rspec-support (~> 3.3.0)
|
137
|
+
rspec-html-matchers (0.7.0)
|
138
|
+
nokogiri (~> 1)
|
139
|
+
rspec (~> 3)
|
140
|
+
rspec-mocks (3.3.2)
|
141
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
142
|
+
rspec-support (~> 3.3.0)
|
143
|
+
rspec-support (3.3.0)
|
144
|
+
shellany (0.0.1)
|
145
|
+
slop (3.6.0)
|
71
146
|
thor (0.19.1)
|
72
|
-
thread_safe (0.3.
|
147
|
+
thread_safe (0.3.5)
|
73
148
|
tilt (1.4.1)
|
74
|
-
timers (1.1.0)
|
75
149
|
tzinfo (1.2.2)
|
76
150
|
thread_safe (~> 0.1)
|
77
|
-
uber (0.0.
|
78
|
-
unicode (0.4.4.
|
151
|
+
uber (0.0.15)
|
152
|
+
unicode (0.4.4.2)
|
153
|
+
xpath (2.0.0)
|
154
|
+
nokogiri (~> 1.3)
|
155
|
+
yard (0.8.7.6)
|
79
156
|
|
80
157
|
PLATFORMS
|
81
158
|
ruby
|
82
159
|
|
83
160
|
DEPENDENCIES
|
84
|
-
|
161
|
+
aruba
|
162
|
+
cucumber
|
163
|
+
guard
|
164
|
+
guard-rspec
|
85
165
|
middleman-citation!
|
166
|
+
pry
|
86
167
|
rake
|
168
|
+
rdoc
|
169
|
+
rspec
|
170
|
+
rspec-html-matchers
|
171
|
+
yard
|
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Middleman-citation
|
2
2
|
|
3
|
+
[ ![Codeship Status for gabysbrain/middleman-citation](https://codeship.com/projects/cd5fdc40-6601-0133-2d2b-5adfc3e4cb23/status?branch=master)](https://codeship.com/projects/113648)
|
4
|
+
|
3
5
|
This is an extension for the [Middleman](http://middlemanapp.com/) static
|
4
6
|
site generator that adds functions you can use in your templates for
|
5
7
|
formating citations from BibTeX.
|
@@ -21,16 +23,16 @@ Or install it yourself as:
|
|
21
23
|
|
22
24
|
$ gem install middleman-citation
|
23
25
|
|
24
|
-
|
25
26
|
## Configuration
|
26
27
|
|
27
28
|
In your `config.rb` file for your site add:
|
28
29
|
|
29
30
|
require 'middleman-citation'
|
30
31
|
|
31
|
-
activate :citation do |
|
32
|
-
|
33
|
-
|
32
|
+
activate :citation do |opts|
|
33
|
+
opts.bibtex = '/path/to/your.bib' # path to a bibtex file
|
34
|
+
opts.style = 'ieee' # style from citeproc-styles
|
35
|
+
opts.format = 'html' # output format
|
34
36
|
end
|
35
37
|
|
36
38
|
## Usage
|
@@ -38,14 +40,39 @@ In your `config.rb` file for your site add:
|
|
38
40
|
This adds the following helper methods you can use in your Middleman
|
39
41
|
templates.
|
40
42
|
|
43
|
+
* `citations_search(search_term, author)`: Search the BibTeX file for all
|
44
|
+
citations matching a search term (such as `'@article'`) and by the given
|
45
|
+
author. The `author` argument can be ommitted to match all authors and
|
46
|
+
a `search_term` of `nil` will match all items in the bibliography.
|
47
|
+
|
48
|
+
* `citation(key)`: Given a BibTeX citation key as returned from
|
49
|
+
`citations_search`, return a formatted string the citation according to
|
50
|
+
how the `style` and `format` options were set.
|
51
|
+
|
52
|
+
For extra control on the output, one can use:
|
53
|
+
|
54
|
+
* `citation_entry(key)`: Return the unformatted entry (a hash)
|
55
|
+
corresponding to the BibTeX citation key.
|
41
56
|
|
57
|
+
* `citation_formatted(entry)`: Format an unformatted entry.
|
42
58
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
59
|
+
In fact the `citation` method is implemented using these:
|
60
|
+
|
61
|
+
def citation(key)
|
62
|
+
entry = citation_entry(key)
|
63
|
+
citation_formatted(entry)
|
64
|
+
end
|
65
|
+
|
66
|
+
The point is that one can interrogate the unformatted entry to
|
67
|
+
add extra formatting: The following code adds a DOI link if the
|
68
|
+
entry matching the `key` has a `URL` field containing the DOI.
|
69
|
+
|
70
|
+
entry = citation_entry(key)
|
71
|
+
entry_html = citation_formatted(entry)
|
72
|
+
if doi_url = entry.fetch('URL', false) then
|
73
|
+
doi_link = "(%s)" % link_to('doi', doi_url)
|
74
|
+
end
|
75
|
+
[entry_html, doi_link].compact.join(' ')
|
49
76
|
|
50
77
|
## Contributing
|
51
78
|
|
data/Rakefile
CHANGED
@@ -1 +1,20 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'cucumber/rake/task'
|
5
|
+
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
6
|
+
t.cucumber_opts = "--color --tags ~@wip --strict"
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rspec/core/rake_task'
|
10
|
+
desc "Run RSpec"
|
11
|
+
RSpec::Core::RakeTask.new do |spec|
|
12
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
13
|
+
spec.rspec_opts = ['--color', '--format documentation']
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'rake/clean'
|
17
|
+
|
18
|
+
task test: ['spec', 'cucumber']
|
19
|
+
|
20
|
+
task default: :test
|
data/fixtures/test.bib
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
@article{Turkay:2011a,
|
2
|
+
Author = {Turkay, Cagatay and J. Parulek and N. Reuter and Hauser, Helwig},
|
3
|
+
Date-Added = {2015-11-04 09:50:16 +0000},
|
4
|
+
Date-Modified = {2015-11-04 09:50:48 +0000},
|
5
|
+
Doi = {10.1111/j.1467-8659.2011.01920.x},
|
6
|
+
Journal = {Computer Graphics Forum},
|
7
|
+
Month = {jun},
|
8
|
+
Number = {3},
|
9
|
+
Pages = {711--720},
|
10
|
+
Publisher = {Wiley-Blackwell},
|
11
|
+
Title = {Interactive Visual Analysis of Temporal Cluster Structures},
|
12
|
+
Url = {http://dx.doi.org/10.1111/j.1467-8659.2011.01920.x},
|
13
|
+
Volume = {30},
|
14
|
+
Year = 2011,
|
15
|
+
Bdsk-Url-1 = {http://dx.doi.org/10.1111/j.1467-8659.2011.01920.x}}
|
16
|
+
|
17
|
+
@article{Correa:2013,
|
18
|
+
Author = {Carlos D. Correa and Peter Lindstrom},
|
19
|
+
Date-Added = {2015-11-02 14:06:07 +0000},
|
20
|
+
Date-Modified = {2015-11-02 14:06:07 +0000},
|
21
|
+
Doi = {10.1615/int.j.uncertaintyquantification.2012003959},
|
22
|
+
Journal = {Int. J. {UncertaintyQuantification}},
|
23
|
+
Number = {3},
|
24
|
+
Pages = {187--201},
|
25
|
+
Publisher = {Begell House},
|
26
|
+
Title = {{THE} {MUTUAL} {INFORMATION} {DIAGRAM} {FOR} {UNCERTAINTY} {VISUALIZATION}},
|
27
|
+
Url = {http://dx.doi.org/10.1615/int.j.uncertaintyquantification.2012003959},
|
28
|
+
Volume = {3},
|
29
|
+
Year = 2013,
|
30
|
+
Bdsk-Url-1 = {http://dx.doi.org/10.1615/int.j.uncertaintyquantification.2012003959}}
|
31
|
+
|
32
|
+
@article{Beck:2016,
|
33
|
+
Author = {Fabian Beck and Sebastian Koch and Daniel Weiskopf},
|
34
|
+
Date-Added = {2015-11-02 11:01:01 +0000},
|
35
|
+
Date-Modified = {2015-11-02 11:01:01 +0000},
|
36
|
+
Doi = {10.1109/tvcg.2015.2467757},
|
37
|
+
Journal = {{IEEE} Trans. Visual. Comput. Graphics},
|
38
|
+
Month = {jan},
|
39
|
+
Number = {1},
|
40
|
+
Pages = {180--189},
|
41
|
+
Publisher = {Institute of Electrical {\\&} Electronics Engineers ({IEEE})},
|
42
|
+
Title = {Visual Analysis and Dissemination of Scientific Literature Collections with {SurVis}},
|
43
|
+
Url = {http://dx.doi.org/10.1109/tvcg.2015.2467757},
|
44
|
+
Volume = {22},
|
45
|
+
Year = 2016,
|
46
|
+
Bdsk-Url-1 = {http://dx.doi.org/10.1109/tvcg.2015.2467757}}
|
47
|
+
|
48
|
+
@article{Lehmann:2016,
|
49
|
+
Author = {Dirk J. Lehmann and Holger Theisel},
|
50
|
+
Date-Added = {2015-11-02 10:47:37 +0000},
|
51
|
+
Date-Modified = {2015-11-02 10:47:37 +0000},
|
52
|
+
Doi = {10.1109/tvcg.2015.2467132},
|
53
|
+
Journal = {{IEEE} Trans. Visual. Comput. Graphics},
|
54
|
+
Month = {jan},
|
55
|
+
Number = {1},
|
56
|
+
Pages = {609--618},
|
57
|
+
Publisher = {Institute of Electrical {\\&} Electronics Engineers ({IEEE})},
|
58
|
+
Title = {Optimal Sets of Projections of High-Dimensional Data},
|
59
|
+
Url = {http://dx.doi.org/10.1109/tvcg.2015.2467132},
|
60
|
+
Volume = {22},
|
61
|
+
Year = 2016,
|
62
|
+
Bdsk-Url-1 = {http://dx.doi.org/10.1109/tvcg.2015.2467132}}
|
63
|
+
|
64
|
+
@article{Rubio-Sanchez:2016,
|
65
|
+
Author = {Manuel Rubio-Sanchez and Laura Raya and Francisco Diaz and Alberto Sanchez},
|
66
|
+
Date-Added = {2015-11-02 10:47:09 +0000},
|
67
|
+
Date-Modified = {2015-11-02 10:47:09 +0000},
|
68
|
+
Doi = {10.1109/tvcg.2015.2467324},
|
69
|
+
Journal = {{IEEE} Trans. Visual. Comput. Graphics},
|
70
|
+
Month = {jan},
|
71
|
+
Number = {1},
|
72
|
+
Pages = {619--628},
|
73
|
+
Publisher = {Institute of Electrical {\\&} Electronics Engineers ({IEEE})},
|
74
|
+
Title = {A comparative study between {RadViz} and Star Coordinates},
|
75
|
+
Url = {http://dx.doi.org/10.1109/tvcg.2015.2467324},
|
76
|
+
Volume = {22},
|
77
|
+
Year = 2016,
|
78
|
+
Bdsk-Url-1 = {http://dx.doi.org/10.1109/tvcg.2015.2467324}}
|
79
|
+
|
80
|
+
@article{Torsney-Weir:2011,
|
81
|
+
Author = {Torsney-Weir, Thomas and Saad, Ahmed and M{\"o}ller, Torsten and Weber, Britta and Hege, Hans-Christian and Verbavatz, Jean-Marc and Bergner, Steven},
|
82
|
+
Date-Added = {2012-12-23 15:54:34 +0000},
|
83
|
+
Date-Modified = {2013-04-07 20:00:22 +0000},
|
84
|
+
Journal = {IEEE Transactions on Visualization and Computer Graphics},
|
85
|
+
Keywords = {Visualization, High-D, Image Segmentation, Multi-objective},
|
86
|
+
Month = nov # {\slash } # dec,
|
87
|
+
Number = {12},
|
88
|
+
Pages = {1892--1901},
|
89
|
+
Rating = {0},
|
90
|
+
Title = {Tuner: Principled Parameter Finding for Image Segmentation Algorithms Using Visual Response Surface Exploration},
|
91
|
+
Volume = {17},
|
92
|
+
Year = {2011}}
|
93
|
+
|
data/lib/middleman-citation.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
require "middleman-citation/version"
|
2
|
+
require "middleman-citation/citations"
|
2
3
|
require "middleman-core"
|
3
4
|
require "bibtex"
|
4
|
-
require "citeproc"
|
5
5
|
|
6
6
|
module Middleman
|
7
|
+
|
7
8
|
class CitationExtension < Middleman::Extension
|
8
|
-
|
9
|
-
option :
|
10
|
-
|
9
|
+
|
10
|
+
option :bibtex, nil, 'Path to the bibtex file'
|
11
|
+
option :style, 'chicago-author-date', 'Citation style'
|
12
|
+
option :format, 'html', 'Citation format'
|
13
|
+
|
11
14
|
def initialize(app, options_hash={}, &block)
|
12
15
|
super
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# middleman-deploy in the helper methods below...
|
17
|
-
@@cite_style = options.style
|
16
|
+
app.set(:bibtex, BibTeX.open(options.bibtex, :filter => 'latex'))
|
17
|
+
app.set(:cite_style, options.style)
|
18
|
+
app.set(:cite_format, options.format)
|
18
19
|
end
|
19
20
|
|
20
21
|
helpers do
|
@@ -23,26 +24,52 @@ module Middleman
|
|
23
24
|
# Params:
|
24
25
|
# +key+:: bibtex key located in the BibTeX file defined in the config
|
25
26
|
def cite_full(key)
|
26
|
-
|
27
|
-
@@bibtex[key].convert_latex
|
28
|
-
CiteProc.process(@@bibtex[key].to_citeproc, :style => @@cite_style)
|
27
|
+
Citations::cite_full(key, @@bibtex, @@cite_style)
|
29
28
|
end
|
30
|
-
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# +cite_full+.
|
29
|
+
|
30
|
+
# Given a BibTeX citation return a block containing the citation
|
31
|
+
# that we can embed in a webpage inline
|
34
32
|
# Params:
|
35
|
-
# +
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
33
|
+
# +key+:: bibtex key located in the BibTeX file defined in the config
|
34
|
+
def cite_inline(key)
|
35
|
+
Citations::cite_inline(key, @@bibtex, @@cite_style)
|
36
|
+
end
|
37
|
+
|
38
|
+
def citations_search(search_key, author = nil)
|
39
|
+
entries_matching_key = bibtex.query(search_key)
|
40
|
+
entries =
|
41
|
+
if author then
|
42
|
+
search_by_author(entries_matching_key, author)
|
43
|
+
else
|
44
|
+
entries_matching_key
|
45
|
+
end
|
46
|
+
entries.sort { |x, y| y.year.to_i <=> x.year.to_i }.map(&:key)
|
47
|
+
end
|
48
|
+
|
49
|
+
def citation_entry(key)
|
50
|
+
bibtex[key].convert_latex.to_citeproc
|
51
|
+
end
|
52
|
+
|
53
|
+
def citation_formatted(entry)
|
54
|
+
CiteProc.process(entry, :style => cite_style, :format => cite_format)
|
55
|
+
end
|
56
|
+
|
57
|
+
def citation(key)
|
58
|
+
entry = citation_entry(key)
|
59
|
+
citation_formatted(entry)
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def search_by_author(entries, author)
|
65
|
+
bib_author = BibTeX::Name.parse(author)
|
66
|
+
entries.select do |e|
|
67
|
+
e.respond_to?(:author) &&
|
68
|
+
e.author &&
|
69
|
+
e.author.include?(bib_author)
|
42
70
|
end
|
43
|
-
results.sort! {|x,y| y.year.to_i-x.year.to_i}
|
44
|
-
results.map {|x| x.key}
|
45
71
|
end
|
72
|
+
|
46
73
|
end
|
47
74
|
end
|
48
75
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
require "bibtex"
|
3
|
+
require "citeproc"
|
4
|
+
require "csl/styles"
|
5
|
+
|
6
|
+
module Citations
|
7
|
+
class InvalidKeyError < StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
class InvalidStyleError < StandardError
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.cite_full(key, bib, style, format='text')
|
14
|
+
cp = CiteProc::Processor.new style: style, format: format
|
15
|
+
cp.import bib.to_citeproc
|
16
|
+
# need to convert latex special characters, like {\"o} to unicode
|
17
|
+
#bib[key].convert_latex
|
18
|
+
#puts bib[key]
|
19
|
+
#CiteProc.process(bib[key].to_citeproc, :style => style)
|
20
|
+
begin
|
21
|
+
cp.render(:bibliography, id: key).join("\n")
|
22
|
+
rescue TypeError => e
|
23
|
+
raise InvalidKeyError, "citation key '#{key}' not found"
|
24
|
+
rescue CSL::ParseError => e
|
25
|
+
raise InvalidStyleError, "citation style '#{style}' not found"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.cite_inline(key, bib, style)
|
30
|
+
" <span class='inline-citation'><span class='citation'>#{cite_full(key, bib, style,'html')}</span></span>"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'middleman-citation'
|
data/middleman-citation.gemspec
CHANGED
@@ -22,9 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.add_runtime_dependency "bibtex-ruby"
|
25
|
-
spec.add_runtime_dependency "citeproc-ruby"
|
25
|
+
spec.add_runtime_dependency "citeproc-ruby"
|
26
|
+
spec.add_runtime_dependency "csl-styles"
|
26
27
|
spec.add_runtime_dependency "middleman-core", ["~> 3"]
|
27
|
-
|
28
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
29
|
-
spec.add_development_dependency "rake"
|
30
28
|
end
|
data/spec/cite_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'middleman-citation/citations'
|
2
|
+
|
3
|
+
RSpec.describe Citations, "citations" do
|
4
|
+
require 'bibtex'
|
5
|
+
bib = BibTeX.open('fixtures/test.bib', :filter => :latex)
|
6
|
+
|
7
|
+
turkay_chi = "Turkay, Cagatay, J. Parulek, N. Reuter, and Helwig Hauser. 2011. “Interactive Visual Analysis of Temporal Cluster Structures.” Computer Graphics Forum 30 (3). Wiley-Blackwell: 711–20. doi:10.1111/j.1467-8659.2011.01920.x. http://dx.doi.org/10.1111/j.1467-8659.2011.01920.x."
|
8
|
+
turkay_ieee = "C. Turkay, J. Parulek, N. Reuter, and H. Hauser, “Interactive Visual Analysis of Temporal Cluster Structures,” Computer Graphics Forum, vol. 30, no. 3, pp. 711–720, Jun. 2011."
|
9
|
+
tw_chi = "Torsney-Weir, Thomas, Ahmed Saad, Torsten Möller, Britta Weber, Hans-Christian Hege, Jean-Marc Verbavatz, and Steven Bergner. 2011. “Tuner: Principled Parameter Finding for Image Segmentation Algorithms Using Visual Response Surface Exploration.” IEEE Transactions on Visualization and Computer Graphics 17 (12): 1892–1901."
|
10
|
+
|
11
|
+
context "long-form citation" do
|
12
|
+
it "gives a nice error for a bad style" do
|
13
|
+
expect {Citations::cite_full('Turkay:2011a', bib, 'crazyformat')}.to \
|
14
|
+
raise_error(Citations::InvalidStyleError, /crazyformat/)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "gives a nice error for a bad key" do
|
18
|
+
expect {Citations::cite_full('notthere', bib, 'chicago-author-date')}.to \
|
19
|
+
raise_error(Citations::InvalidKeyError, /notthere/)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "generates a proper chicago-style citation" do
|
23
|
+
full_cite = Citations::cite_full('Turkay:2011a', bib, 'chicago-author-date')
|
24
|
+
expect(full_cite).to eq(turkay_chi)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "generates a proper ieee-style citation" do
|
28
|
+
full_cite = Citations::cite_full('Turkay:2011a', bib, 'ieee')
|
29
|
+
expect(full_cite).to eq(turkay_ieee)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "properly handles accented characters" do
|
33
|
+
full_cite = Citations::cite_full('Torsney-Weir:2011', bib, 'chicago-author-date')
|
34
|
+
expect(full_cite).to eq(tw_chi)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "short-form inline citation" do
|
39
|
+
it "generates a proper chicago-style citation" do
|
40
|
+
inline_cite = Citations::cite_inline('Turkay:2011a', bib, 'chicago-author-date')
|
41
|
+
expect(inline_cite).to have_tag("span", :with => {:class => 'inline-citation'}) do
|
42
|
+
with_tag('span', :text => turkay_chi, :with => {:class => 'citation'})
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-html-matchers
|
35
|
+
require 'rspec-html-matchers'
|
36
|
+
config.include RSpecHtmlMatchers
|
37
|
+
|
38
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
39
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
40
|
+
config.mock_with :rspec do |mocks|
|
41
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
42
|
+
# a real object. This is generally recommended, and will default to
|
43
|
+
# `true` in RSpec 4.
|
44
|
+
mocks.verify_partial_doubles = true
|
45
|
+
end
|
46
|
+
|
47
|
+
# The settings below are suggested to provide a good initial experience
|
48
|
+
# with RSpec, but feel free to customize to your heart's content.
|
49
|
+
=begin
|
50
|
+
# These two settings work together to allow you to limit a spec run
|
51
|
+
# to individual examples or groups you care about by tagging them with
|
52
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
53
|
+
# get run.
|
54
|
+
config.filter_run :focus
|
55
|
+
config.run_all_when_everything_filtered = true
|
56
|
+
|
57
|
+
# Allows RSpec to persist some state between runs in order to support
|
58
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
59
|
+
# you configure your source control system to ignore this file.
|
60
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
61
|
+
|
62
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
63
|
+
# recommended. For more details, see:
|
64
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
65
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
66
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
67
|
+
config.disable_monkey_patching!
|
68
|
+
|
69
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
70
|
+
# be too noisy due to issues in dependencies.
|
71
|
+
config.warnings = true
|
72
|
+
|
73
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
74
|
+
# file, and it's useful to allow more verbose output when running an
|
75
|
+
# individual spec file.
|
76
|
+
if config.files_to_run.one?
|
77
|
+
# Use the documentation formatter for detailed output,
|
78
|
+
# unless a formatter has already been configured
|
79
|
+
# (e.g. via a command-line flag).
|
80
|
+
config.default_formatter = 'doc'
|
81
|
+
end
|
82
|
+
|
83
|
+
# Print the 10 slowest examples and example groups at the
|
84
|
+
# end of the spec run, to help surface which specs are running
|
85
|
+
# particularly slow.
|
86
|
+
config.profile_examples = 10
|
87
|
+
|
88
|
+
# Run specs in random order to surface order dependencies. If you find an
|
89
|
+
# order dependency and want to debug it, you can fix the order by providing
|
90
|
+
# the seed, which is printed after each run.
|
91
|
+
# --seed 1234
|
92
|
+
config.order = :random
|
93
|
+
|
94
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
95
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
96
|
+
# test failures related to randomization by passing the same `--seed` value
|
97
|
+
# as the one that triggered the failure.
|
98
|
+
Kernel.srand config.seed
|
99
|
+
=end
|
100
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-citation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Torsney-Weir
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bibtex-ruby
|
@@ -28,58 +28,44 @@ dependencies:
|
|
28
28
|
name: citeproc-ruby
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: csl-styles
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: middleman-core
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
type: :
|
61
|
+
version: '3'
|
62
|
+
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rake
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - '>='
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - '>='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
68
|
+
version: '3'
|
83
69
|
description: |2
|
84
70
|
A middleman extension that gives helpers for
|
85
71
|
creating citations using citeproc
|
@@ -90,14 +76,23 @@ extensions: []
|
|
90
76
|
extra_rdoc_files: []
|
91
77
|
files:
|
92
78
|
- .gitignore
|
79
|
+
- .rspec
|
80
|
+
- .yardopts
|
93
81
|
- Gemfile
|
94
82
|
- Gemfile.lock
|
83
|
+
- Guardfile
|
95
84
|
- LICENSE
|
96
85
|
- README.md
|
97
86
|
- Rakefile
|
87
|
+
- features/support/env.rb
|
88
|
+
- fixtures/test.bib
|
98
89
|
- lib/middleman-citation.rb
|
90
|
+
- lib/middleman-citation/citations.rb
|
99
91
|
- lib/middleman-citation/version.rb
|
92
|
+
- lib/middleman_extension.rb
|
100
93
|
- middleman-citation.gemspec
|
94
|
+
- spec/cite_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
101
96
|
homepage: https://github.com/gabysbrain/middleman-citation
|
102
97
|
licenses:
|
103
98
|
- MIT
|
@@ -122,4 +117,8 @@ rubygems_version: 2.0.3
|
|
122
117
|
signing_key:
|
123
118
|
specification_version: 4
|
124
119
|
summary: Middleman extension for citeproc
|
125
|
-
test_files:
|
120
|
+
test_files:
|
121
|
+
- features/support/env.rb
|
122
|
+
- spec/cite_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
has_rdoc:
|