asciidoctor-bibliography 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +23 -4
- data/asciidoctor-bibliography.gemspec +8 -8
- data/lib/asciidoctor-bibliography.rb +6 -0
- data/lib/asciidoctor-bibliography/asciidoctor/bibliographer_preprocessor.rb +35 -23
- data/lib/asciidoctor-bibliography/bibliographer.rb +0 -15
- data/lib/asciidoctor-bibliography/citation.rb +29 -22
- data/lib/asciidoctor-bibliography/databases/bibtex.rb +4 -1
- data/lib/asciidoctor-bibliography/formatter.rb +28 -0
- data/lib/asciidoctor-bibliography/index.rb +24 -16
- data/lib/asciidoctor-bibliography/options.rb +65 -32
- data/lib/asciidoctor-bibliography/version.rb +1 -1
- data/lib/citeproc/ruby/formats/adoc.rb +36 -0
- data/lib/csl/styles/tex-citealp-authoryear.csl +117 -0
- data/lib/csl/styles/tex-citealp-numeric.csl +116 -0
- data/lib/csl/styles/tex-citealps-authoryear.csl +117 -0
- data/lib/csl/styles/tex-citealps-numeric.csl +116 -0
- data/lib/csl/styles/tex-citealt-authoryear.csl +119 -0
- data/lib/csl/styles/tex-citealt-numeric.csl +119 -0
- data/lib/csl/styles/tex-citealts-authoryear.csl +119 -0
- data/lib/csl/styles/tex-citealts-numeric.csl +119 -0
- data/lib/csl/styles/tex-citeauthor-authoryear.csl +116 -0
- data/lib/csl/styles/tex-citeauthor-numeric.csl +116 -0
- data/lib/csl/styles/tex-citeauthors-authoryear.csl +116 -0
- data/lib/csl/styles/tex-citeauthors-numeric.csl +116 -0
- data/lib/csl/styles/tex-citep-authoryear.csl +117 -0
- data/lib/csl/styles/tex-citep-numeric.csl +116 -0
- data/lib/csl/styles/tex-citeps-authoryear.csl +117 -0
- data/lib/csl/styles/tex-citeps-numeric.csl +116 -0
- data/lib/csl/styles/tex-citet-authoryear.csl +119 -0
- data/lib/csl/styles/tex-citet-numeric.csl +119 -0
- data/lib/csl/styles/tex-citets-authoryear.csl +119 -0
- data/lib/csl/styles/tex-citets-numeric.csl +119 -0
- data/lib/csl/styles/tex-citeyear-authoryear.csl +116 -0
- data/lib/csl/styles/tex-citeyear-numeric.csl +116 -0
- data/lib/csl/styles/tex-citeyearpar-authoryear.csl +116 -0
- data/lib/csl/styles/tex-citeyearpar-numeric.csl +116 -0
- data/samples/tex/sample-numbers.adoc +1 -1
- data/samples/tex/sample-sort.adoc +1 -1
- data/spec/citation_helper.rb +46 -0
- data/spec/citation_item_spec.rb +0 -2
- data/spec/csl/styles/tex_citealp_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citealp_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citealps_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citealps_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citealt_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citealt_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citealts_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citealts_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citeauthor_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citeauthor_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citeauthors_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citeauthors_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citep_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citep_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citeps_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citeps_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citet_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citet_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citets_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citets_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citeyear_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citeyear_numeric_spec.rb +42 -0
- data/spec/csl/styles/tex_citeyearpar_authoryear_spec.rb +42 -0
- data/spec/csl/styles/tex_citeyearpar_numeric_spec.rb +42 -0
- data/spec/database_spec.rb +20 -1
- data/spec/macros_spec.rb +21 -0
- data/spec/options_spec.rb +105 -1
- metadata +72 -24
- data/lib/asciidoctor-bibliography/formatters/csl.rb +0 -28
- data/lib/asciidoctor-bibliography/formatters/tex.rb +0 -187
- data/lib/asciidoctor-bibliography/helpers.rb +0 -41
- data/spec/helpers_spec.rb +0 -73
metadata
CHANGED
@@ -1,85 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-bibliography
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.5.6
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.5.6
|
27
27
|
- !ruby/object:Gem::Dependency
|
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:
|
33
|
+
version: 1.1.7
|
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:
|
40
|
+
version: 1.1.7
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
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: 1.0.1
|
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: 1.0.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: latex-decode
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.2.2
|
62
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:
|
68
|
+
version: 0.2.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bibtex-ruby
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 4.4.4
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 4.4.4
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: bundler
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -186,11 +186,11 @@ description: |
|
|
186
186
|
* contextual cite `cite[key, page=3]`;
|
187
187
|
* multiple cites `cite:[key1]+[key2]`;
|
188
188
|
* full cite `fullcite:[key]`; and
|
189
|
-
* TeX-compatible macros including `citep:[key]`, `citet:[]
|
189
|
+
* TeX-compatible macros including `citep:[key]`, `citet:[key]` and friends.
|
190
190
|
|
191
191
|
Citation output styles are fully bridged to the CSL library, supporting formats such as IEEE, APA, Chicago, DIN and ISO 690.
|
192
192
|
|
193
|
-
The `bibliography
|
193
|
+
The `bibliography::[]` command generates a full reference list that adheres to your configured citation style.
|
194
194
|
email:
|
195
195
|
- open.source@ribose.com
|
196
196
|
executables: []
|
@@ -220,12 +220,35 @@ files:
|
|
220
220
|
- lib/asciidoctor-bibliography/database.rb
|
221
221
|
- lib/asciidoctor-bibliography/databases/bibtex.rb
|
222
222
|
- lib/asciidoctor-bibliography/errors.rb
|
223
|
-
- lib/asciidoctor-bibliography/
|
224
|
-
- lib/asciidoctor-bibliography/formatters/tex.rb
|
225
|
-
- lib/asciidoctor-bibliography/helpers.rb
|
223
|
+
- lib/asciidoctor-bibliography/formatter.rb
|
226
224
|
- lib/asciidoctor-bibliography/index.rb
|
227
225
|
- lib/asciidoctor-bibliography/options.rb
|
228
226
|
- lib/asciidoctor-bibliography/version.rb
|
227
|
+
- lib/citeproc/ruby/formats/adoc.rb
|
228
|
+
- lib/csl/styles/tex-citealp-authoryear.csl
|
229
|
+
- lib/csl/styles/tex-citealp-numeric.csl
|
230
|
+
- lib/csl/styles/tex-citealps-authoryear.csl
|
231
|
+
- lib/csl/styles/tex-citealps-numeric.csl
|
232
|
+
- lib/csl/styles/tex-citealt-authoryear.csl
|
233
|
+
- lib/csl/styles/tex-citealt-numeric.csl
|
234
|
+
- lib/csl/styles/tex-citealts-authoryear.csl
|
235
|
+
- lib/csl/styles/tex-citealts-numeric.csl
|
236
|
+
- lib/csl/styles/tex-citeauthor-authoryear.csl
|
237
|
+
- lib/csl/styles/tex-citeauthor-numeric.csl
|
238
|
+
- lib/csl/styles/tex-citeauthors-authoryear.csl
|
239
|
+
- lib/csl/styles/tex-citeauthors-numeric.csl
|
240
|
+
- lib/csl/styles/tex-citep-authoryear.csl
|
241
|
+
- lib/csl/styles/tex-citep-numeric.csl
|
242
|
+
- lib/csl/styles/tex-citeps-authoryear.csl
|
243
|
+
- lib/csl/styles/tex-citeps-numeric.csl
|
244
|
+
- lib/csl/styles/tex-citet-authoryear.csl
|
245
|
+
- lib/csl/styles/tex-citet-numeric.csl
|
246
|
+
- lib/csl/styles/tex-citets-authoryear.csl
|
247
|
+
- lib/csl/styles/tex-citets-numeric.csl
|
248
|
+
- lib/csl/styles/tex-citeyear-authoryear.csl
|
249
|
+
- lib/csl/styles/tex-citeyear-numeric.csl
|
250
|
+
- lib/csl/styles/tex-citeyearpar-authoryear.csl
|
251
|
+
- lib/csl/styles/tex-citeyearpar-numeric.csl
|
229
252
|
- samples/latex_macros_in_bibtex/reference.bib
|
230
253
|
- samples/latex_macros_in_bibtex/sample.adoc
|
231
254
|
- samples/standard/biblio.bib
|
@@ -241,12 +264,37 @@ files:
|
|
241
264
|
- samples/tex/sample-numbers.adoc
|
242
265
|
- samples/tex/sample-numbers.html
|
243
266
|
- samples/tex/sample-sort.adoc
|
267
|
+
- spec/citation_helper.rb
|
244
268
|
- spec/citation_item_spec.rb
|
269
|
+
- spec/csl/styles/tex_citealp_authoryear_spec.rb
|
270
|
+
- spec/csl/styles/tex_citealp_numeric_spec.rb
|
271
|
+
- spec/csl/styles/tex_citealps_authoryear_spec.rb
|
272
|
+
- spec/csl/styles/tex_citealps_numeric_spec.rb
|
273
|
+
- spec/csl/styles/tex_citealt_authoryear_spec.rb
|
274
|
+
- spec/csl/styles/tex_citealt_numeric_spec.rb
|
275
|
+
- spec/csl/styles/tex_citealts_authoryear_spec.rb
|
276
|
+
- spec/csl/styles/tex_citealts_numeric_spec.rb
|
277
|
+
- spec/csl/styles/tex_citeauthor_authoryear_spec.rb
|
278
|
+
- spec/csl/styles/tex_citeauthor_numeric_spec.rb
|
279
|
+
- spec/csl/styles/tex_citeauthors_authoryear_spec.rb
|
280
|
+
- spec/csl/styles/tex_citeauthors_numeric_spec.rb
|
281
|
+
- spec/csl/styles/tex_citep_authoryear_spec.rb
|
282
|
+
- spec/csl/styles/tex_citep_numeric_spec.rb
|
283
|
+
- spec/csl/styles/tex_citeps_authoryear_spec.rb
|
284
|
+
- spec/csl/styles/tex_citeps_numeric_spec.rb
|
285
|
+
- spec/csl/styles/tex_citet_authoryear_spec.rb
|
286
|
+
- spec/csl/styles/tex_citet_numeric_spec.rb
|
287
|
+
- spec/csl/styles/tex_citets_authoryear_spec.rb
|
288
|
+
- spec/csl/styles/tex_citets_numeric_spec.rb
|
289
|
+
- spec/csl/styles/tex_citeyear_authoryear_spec.rb
|
290
|
+
- spec/csl/styles/tex_citeyear_numeric_spec.rb
|
291
|
+
- spec/csl/styles/tex_citeyearpar_authoryear_spec.rb
|
292
|
+
- spec/csl/styles/tex_citeyearpar_numeric_spec.rb
|
245
293
|
- spec/database_spec.rb
|
246
294
|
- spec/fixtures/database.bib
|
247
295
|
- spec/fixtures/database.bibtex
|
248
296
|
- spec/fixtures/database.unk
|
249
|
-
- spec/
|
297
|
+
- spec/macros_spec.rb
|
250
298
|
- spec/options_spec.rb
|
251
299
|
- spec/spec_helper.rb
|
252
300
|
- spec/throwaway_spec.rb
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require "citeproc"
|
2
|
-
require "csl/styles"
|
3
|
-
require "yaml"
|
4
|
-
|
5
|
-
module AsciidoctorBibliography
|
6
|
-
module Formatters
|
7
|
-
class CSL < ::CiteProc::Processor
|
8
|
-
def initialize(style)
|
9
|
-
super style: style, format: :html
|
10
|
-
end
|
11
|
-
|
12
|
-
def replace_bibliography_sort(array)
|
13
|
-
new_keys = array.map(&::CSL::Style::Sort::Key.method(:new))
|
14
|
-
new_sort = ::CSL::Style::Sort.new.add_children(*new_keys)
|
15
|
-
|
16
|
-
bibliography = engine.style.find_child("bibliography")
|
17
|
-
bibliography.find_child("sort")&.unlink
|
18
|
-
|
19
|
-
bibliography.add_child new_sort
|
20
|
-
end
|
21
|
-
|
22
|
-
def sort(mode:)
|
23
|
-
# Valid modes are :citation and :bibliography
|
24
|
-
engine.sort! data, engine.style.send(mode).sort_keys if engine.style.send(mode).sort?
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,187 +0,0 @@
|
|
1
|
-
module AsciidoctorBibliography
|
2
|
-
module Formatters
|
3
|
-
# This formatter emulates the behaviour of traditional Bib(La)TeX/NatBib citations.
|
4
|
-
class TeX
|
5
|
-
MACROS = {
|
6
|
-
# NOTE: \citet is equivalent to \cite, so we reserve the latter for CSL styling.
|
7
|
-
"citet" => { type: :textual, bracketed: true, authors: :abbreviated },
|
8
|
-
"citet*" => { type: :textual, bracketed: true, authors: :full },
|
9
|
-
"citealt" => { type: :textual, bracketed: false, authors: :abbreviated },
|
10
|
-
"citealt*" => { type: :textual, bracketed: false, authors: :full },
|
11
|
-
"citep" => { type: :parenthetical, bracketed: true, authors: :abbreviated },
|
12
|
-
"citep*" => { type: :parenthetical, bracketed: true, authors: :full },
|
13
|
-
"citealp" => { type: :parenthetical, bracketed: false, authors: :abbreviated },
|
14
|
-
"citealp*" => { type: :parenthetical, bracketed: false, authors: :full },
|
15
|
-
"citeauthor" => { type: :authors_only, bracketed: false, authors: :abbreviated },
|
16
|
-
"citeauthor*" => { type: :authors_only, bracketed: false, authors: :full },
|
17
|
-
"citeyear" => { type: :years_only, bracketed: false },
|
18
|
-
"citeyearpar" => { type: :years_only, bracketed: true },
|
19
|
-
}.freeze
|
20
|
-
|
21
|
-
attr_accessor :opening_bracket,
|
22
|
-
:closing_bracket,
|
23
|
-
:cites_separator,
|
24
|
-
:style,
|
25
|
-
:author_year_separator,
|
26
|
-
:years_separator
|
27
|
-
|
28
|
-
def initialize(format)
|
29
|
-
if format == "numbers"
|
30
|
-
bibpunct = "{[}{]}{,}{n}{,}{,}"
|
31
|
-
elsif format == "authoryear"
|
32
|
-
bibpunct = "{(}{)}{;}{a}{,}{,}"
|
33
|
-
else
|
34
|
-
raise StandardError, "Unknown TeX citation format: #{format}"
|
35
|
-
end
|
36
|
-
@opening_bracket,
|
37
|
-
@closing_bracket,
|
38
|
-
@cites_separator,
|
39
|
-
@style,
|
40
|
-
@author_year_separator,
|
41
|
-
@years_separator = bibpunct.scan(/{.*?}/).map { |s| s[1..-2] }
|
42
|
-
end
|
43
|
-
|
44
|
-
def import(database)
|
45
|
-
@database = database
|
46
|
-
end
|
47
|
-
|
48
|
-
def render(bibliographer, citation)
|
49
|
-
macro_options = MACROS[citation.macro]
|
50
|
-
output = []
|
51
|
-
case macro_options[:type]
|
52
|
-
# NOTE: deliberately repetitive to improve redability.
|
53
|
-
when :textual
|
54
|
-
citation.citation_items.each do |cite|
|
55
|
-
authors = authors(macro_options[:authors], cite)
|
56
|
-
year = if @style == "n"
|
57
|
-
bibliographer.appearance_index_of(cite.key)
|
58
|
-
else
|
59
|
-
year(cite)
|
60
|
-
end
|
61
|
-
cetera = Helpers.join_nonempty([year].concat(extra(cite)), @years_separator + " ")
|
62
|
-
cetera = bracket(cetera) if macro_options[:bracketed]
|
63
|
-
label = Helpers.join_nonempty([authors, cetera], " ")
|
64
|
-
output << citation.xref(cite.key, label)
|
65
|
-
end
|
66
|
-
output = output.join(@cites_separator + " ")
|
67
|
-
when :parenthetical
|
68
|
-
citation.citation_items.each do |cite|
|
69
|
-
if @style == "n"
|
70
|
-
authors = nil
|
71
|
-
year = bibliographer.appearance_index_of(cite.key)
|
72
|
-
else
|
73
|
-
authors = authors(macro_options[:authors], cite)
|
74
|
-
year = year(cite)
|
75
|
-
end
|
76
|
-
cetera = Helpers.join_nonempty([year].concat(extra(cite)), @years_separator + " ")
|
77
|
-
label = Helpers.join_nonempty([authors, cetera], @author_year_separator + " ")
|
78
|
-
output << citation.xref(cite.key, label)
|
79
|
-
end
|
80
|
-
output = output.join(@cites_separator + " ")
|
81
|
-
output = bracket(output) if macro_options[:bracketed]
|
82
|
-
when :authors_only
|
83
|
-
citation.citation_items.each do |cite|
|
84
|
-
authors = authors(macro_options[:authors], cite)
|
85
|
-
year = nil
|
86
|
-
cetera = Helpers.join_nonempty([year].concat(extra(cite)), @years_separator + " ")
|
87
|
-
label = Helpers.join_nonempty([authors, cetera], @author_year_separator + " ")
|
88
|
-
output << citation.xref(cite.key, label)
|
89
|
-
end
|
90
|
-
output = output.join(@cites_separator + " ")
|
91
|
-
output = bracket(output) if macro_options[:bracketed]
|
92
|
-
when :years_only
|
93
|
-
citation.citation_items.each do |cite|
|
94
|
-
authors = nil
|
95
|
-
year = year(cite)
|
96
|
-
cetera = Helpers.join_nonempty([year].concat(extra(cite)), @years_separator + " ")
|
97
|
-
label = Helpers.join_nonempty([authors, cetera], @author_year_separator + " ")
|
98
|
-
output << citation.xref(cite.key, label)
|
99
|
-
end
|
100
|
-
output = output.join(@cites_separator + " ")
|
101
|
-
output = bracket(output) if macro_options[:bracketed]
|
102
|
-
else
|
103
|
-
raise StandardError, "Unknown TeX citation macro type: #{macro_options[:type]}"
|
104
|
-
end
|
105
|
-
|
106
|
-
output
|
107
|
-
end
|
108
|
-
|
109
|
-
private
|
110
|
-
|
111
|
-
def bracket(string)
|
112
|
-
[@opening_bracket, string, @closing_bracket].compact.join
|
113
|
-
end
|
114
|
-
|
115
|
-
def find_entry(key)
|
116
|
-
entry = @database.detect { |h| h["id"] == key }
|
117
|
-
raise StandardError, "Can't find entry: #{key}" if entry.nil?
|
118
|
-
entry
|
119
|
-
end
|
120
|
-
|
121
|
-
def year(cite)
|
122
|
-
entry = find_entry(cite.key)
|
123
|
-
issued = entry["issued"]
|
124
|
-
|
125
|
-
if issued.nil?
|
126
|
-
warn "asciidoctor-bibliography: citation (#{cite.key}) has no 'issued' information"
|
127
|
-
return ""
|
128
|
-
end
|
129
|
-
|
130
|
-
date_parts = issued["date-parts"]
|
131
|
-
return "" if date_parts.nil?
|
132
|
-
|
133
|
-
return "" if date_parts.first.nil?
|
134
|
-
date_parts.first.first
|
135
|
-
end
|
136
|
-
|
137
|
-
def extra(cite)
|
138
|
-
na = cite.named_attributes
|
139
|
-
extra = []
|
140
|
-
return extra if na.nil?
|
141
|
-
|
142
|
-
Citation::REF_ATTRIBUTES.each do |sym|
|
143
|
-
next if na[sym.to_s].nil?
|
144
|
-
extra << ref_content(sym, na[sym.to_s])
|
145
|
-
end
|
146
|
-
|
147
|
-
extra
|
148
|
-
end
|
149
|
-
|
150
|
-
# TODO: should this be configurable?
|
151
|
-
# TODO RT: Yes, and i18n!
|
152
|
-
def ref_content(sym, content)
|
153
|
-
"#{sym.to_s.capitalize} #{content}"
|
154
|
-
end
|
155
|
-
|
156
|
-
def authors(mode, cite)
|
157
|
-
case mode
|
158
|
-
when :full
|
159
|
-
authors_full(cite)
|
160
|
-
when :abbreviated
|
161
|
-
authors_abbreviated(cite)
|
162
|
-
else
|
163
|
-
raise StandardError, "Unknown TeX citation authors mode: #{mode}"
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def authors_list(cite)
|
168
|
-
entry = find_entry(cite.key)
|
169
|
-
authors = entry["author"]
|
170
|
-
return [] if authors.nil?
|
171
|
-
authors.map { |h| h["family"] }.compact
|
172
|
-
end
|
173
|
-
|
174
|
-
def authors_abbreviated(cite)
|
175
|
-
authors = authors_list(cite)
|
176
|
-
return "" if authors.empty?
|
177
|
-
authors.length > 1 ? "#{authors.first} et al." : authors.first
|
178
|
-
end
|
179
|
-
|
180
|
-
def authors_full(cite)
|
181
|
-
authors = authors_list(cite)
|
182
|
-
return "" if authors.empty?
|
183
|
-
Helpers.to_sentence authors
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module AsciidoctorBibliography
|
2
|
-
module Helpers
|
3
|
-
def self.slice(hash, *array_of_keys)
|
4
|
-
Hash[[array_of_keys, hash.values_at(*array_of_keys)].transpose]
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.join_nonempty(array, separator)
|
8
|
-
array.compact.map(&:to_s).reject(&:empty?).join(separator)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.html_to_asciidoc(string)
|
12
|
-
string.
|
13
|
-
gsub(%r{<\/?i>}, "_").
|
14
|
-
gsub(%r{<\/?b>}, "*").
|
15
|
-
gsub(%r{<\/?span.*?>}, "").
|
16
|
-
gsub(/\{|\}/, "")
|
17
|
-
# TODO: bracket dropping is inappropriate here.
|
18
|
-
end
|
19
|
-
|
20
|
-
# NOTE: mostly stolen from ActiveSupport.
|
21
|
-
def self.to_sentence(array, options = {})
|
22
|
-
default_connectors = {
|
23
|
-
words_connector: ", ",
|
24
|
-
two_words_connector: " and ",
|
25
|
-
last_word_connector: ", and ",
|
26
|
-
}
|
27
|
-
options = default_connectors.merge!(options)
|
28
|
-
|
29
|
-
case array.length
|
30
|
-
when 0
|
31
|
-
""
|
32
|
-
when 1
|
33
|
-
array[0].to_s.dup
|
34
|
-
when 2
|
35
|
-
"#{array[0]}#{options[:two_words_connector]}#{array[1]}"
|
36
|
-
else
|
37
|
-
"#{array[0...-1].join(options[:words_connector])}#{options[:last_word_connector]}#{array[-1]}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|