asciidoctor-bibliography 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.oss-guides.rubocop.yml +14 -8
- data/README.adoc +2 -2
- data/bin/rspec +30 -0
- data/bin/setup +8 -0
- data/lib/asciidoctor-bibliography/asciidoctor/bibliographer_preprocessor.rb +3 -1
- data/lib/asciidoctor-bibliography/citation.rb +19 -2
- data/lib/asciidoctor-bibliography/databases/rfc.rb +3 -3
- data/lib/asciidoctor-bibliography/options.rb +1 -1
- data/lib/asciidoctor-bibliography/version.rb +1 -1
- data/lib/citeproc/ruby/formats/adoc.rb +6 -2
- data/spec/citation_helper.rb +6 -2
- data/spec/citeproc/ruby/formats/adoc_spec.rb +0 -1
- data/spec/end_to_end_spec.rb +58 -0
- data/spec/fixtures/database-issue84.bib +50 -0
- data/spec/macros_spec.rb +10 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5f4c3c1adb3bab1871b0aca0401e8b2400389952ac1aa6879982d37759e0309
|
4
|
+
data.tar.gz: 4eb784aa9204c2bd4b34784511f1e549d3ab7f94e1079f27ff9898e3baa2a55a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 905cd2e676a6a66d893163c8f9f01cc60f7a4798536a9976ec9bf1d8e130257f05adcbc7de155a74a2dbe9a074302180ceb2cfe80b2b0daa409ab8aeda32c910
|
7
|
+
data.tar.gz: 2b45d610368bd5ac57f83a47d5d517756844f3b6387e06c9bd2a45feaca4d8e51bfad15296701281da3388c0fbb63dafcfc3608c2645779d80a769ed7b16b8fd
|
data/.oss-guides.rubocop.yml
CHANGED
@@ -124,7 +124,6 @@ Style/IfUnlessModifier:
|
|
124
124
|
Description: Favor modifier if/unless usage when you have a single-line body.
|
125
125
|
StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
|
126
126
|
Enabled: false
|
127
|
-
MaxLineLength: 80
|
128
127
|
Style/LambdaCall:
|
129
128
|
Description: Use lambda.call(...) instead of lambda.(...).
|
130
129
|
StyleGuide: https://github.com/bbatsov/ruby-style-guide#proc-call
|
@@ -276,14 +275,22 @@ Style/SymbolProc:
|
|
276
275
|
Enabled: true
|
277
276
|
IgnoredMethods:
|
278
277
|
- respond_to
|
279
|
-
Style/
|
280
|
-
Description: Checks for trailing comma in parameter lists
|
278
|
+
Style/TrailingCommaInArrayLiteral:
|
279
|
+
Description: Checks for trailing comma in parameter lists.
|
281
280
|
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
|
282
281
|
Enabled: true
|
283
282
|
EnforcedStyleForMultiline: comma
|
284
283
|
SupportedStylesForMultiline:
|
285
284
|
- comma
|
286
285
|
- no_comma
|
286
|
+
Style/TrailingCommaInHashLiteral:
|
287
|
+
Description: Checks for trailing comma in parameter hashes.
|
288
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
|
289
|
+
Enabled: true
|
290
|
+
EnforcedStyleForMultiline: no_comma
|
291
|
+
SupportedStylesForMultiline:
|
292
|
+
- comma
|
293
|
+
- no_comma
|
287
294
|
Style/TrailingCommaInArguments:
|
288
295
|
Description: Checks for trailing comma in parameter lists and literals.
|
289
296
|
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
|
@@ -329,7 +336,6 @@ Style/WhileUntilModifier:
|
|
329
336
|
Description: Favor modifier while/until usage when you have a single-line body.
|
330
337
|
StyleGuide: https://github.com/bbatsov/ruby-style-guide#while-as-a-modifier
|
331
338
|
Enabled: false
|
332
|
-
MaxLineLength: 80
|
333
339
|
Style/WordArray:
|
334
340
|
Description: Use %w or %W for arrays of words.
|
335
341
|
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-w
|
@@ -392,14 +398,14 @@ Lint/AssignmentInCondition:
|
|
392
398
|
StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
|
393
399
|
Enabled: false
|
394
400
|
AllowSafeAssignment: true
|
395
|
-
|
401
|
+
Layout/EndAlignment:
|
396
402
|
Description: Align ends correctly.
|
397
403
|
Enabled: true
|
398
404
|
EnforcedStyleAlignWith: keyword
|
399
405
|
SupportedStylesAlignWith:
|
400
406
|
- keyword
|
401
407
|
- variable
|
402
|
-
|
408
|
+
Layout/DefEndAlignment:
|
403
409
|
Description: Align ends corresponding to defs correctly.
|
404
410
|
Enabled: true
|
405
411
|
EnforcedStyleAlignWith: start_of_line
|
@@ -956,10 +962,10 @@ Lint/AmbiguousRegexpLiteral:
|
|
956
962
|
Description: Checks for ambiguous regexp literals in the first argument of a method
|
957
963
|
invocation without parenthesis.
|
958
964
|
Enabled: false
|
959
|
-
|
965
|
+
Layout/BlockAlignment:
|
960
966
|
Description: Align block ends correctly.
|
961
967
|
Enabled: true
|
962
|
-
|
968
|
+
Layout/ConditionPosition:
|
963
969
|
Description: Checks for condition placed in a confusing position relative to the
|
964
970
|
keyword.
|
965
971
|
StyleGuide: https://github.com/bbatsov/ruby-style-guide#same-line-condition
|
data/README.adoc
CHANGED
@@ -344,7 +344,7 @@ You can set their style in the header:
|
|
344
344
|
Accepted values are `authoryear` (default) and `numeric`.
|
345
345
|
|
346
346
|
IMPORTANT: The `cite` macro and the `cite...` macros described in this section are completely
|
347
|
-
independent mechanisms. The former is styled with `:bibliography-style:` (thousands of styles available)
|
347
|
+
independent mechanisms. The former, along with the bibliography, is styled with `:bibliography-style:` (thousands of styles available)
|
348
348
|
while the latter is styled with with `:bibliography-tex-style:` (much more limited, only has the
|
349
349
|
styles listed above).
|
350
350
|
|
@@ -381,7 +381,7 @@ Values given in such way will take highest priority.
|
|
381
381
|
== Development
|
382
382
|
|
383
383
|
We follow Sandi Metz's Rules for this gem, you can read the
|
384
|
-
|
384
|
+
https://thoughtbot.com/blog/sandi-metz-rules-for-developers[description of the rules here].
|
385
385
|
All new code should follow these rules. If you make
|
386
386
|
changes in a file that already violates these rules, you should fix the
|
387
387
|
violations as part of your contribution.
|
data/bin/rspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path(
|
13
|
+
"../../Gemfile", Pathname.new(__FILE__).realpath
|
14
|
+
)
|
15
|
+
|
16
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
17
|
+
|
18
|
+
if File.file?(bundle_binstub)
|
19
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
20
|
+
load(bundle_binstub)
|
21
|
+
else
|
22
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
23
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
require "rubygems"
|
28
|
+
require "bundler/setup"
|
29
|
+
|
30
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/setup
ADDED
@@ -42,7 +42,9 @@ module AsciidoctorBibliography
|
|
42
42
|
|
43
43
|
def fetch_citations(lines, bibliographer)
|
44
44
|
lines.join("\n").gsub(Citation::REGEXP) do
|
45
|
-
|
45
|
+
macro_name, macro_pars = Regexp.last_match.captures
|
46
|
+
target_and_attributes_list_pairs = macro_pars.scan(Citation::MACRO_PARAMETERS_REGEXP)
|
47
|
+
citation = Citation.new(macro_name, *target_and_attributes_list_pairs)
|
46
48
|
bibliographer.add_citation(citation)
|
47
49
|
citation.uuid
|
48
50
|
end.lines.map(&:chomp)
|
@@ -11,7 +11,24 @@ module AsciidoctorBibliography
|
|
11
11
|
|
12
12
|
MACRO_NAME_REGEXP = TEX_MACROS.dup.concat(%w[cite fullcite]).
|
13
13
|
map { |s| Regexp.escape s }.join("|").freeze
|
14
|
-
|
14
|
+
|
15
|
+
REGEXP = /
|
16
|
+
\\? (#{MACRO_NAME_REGEXP}) # macro name
|
17
|
+
(
|
18
|
+
(?: : (?:\S*?) \[(?:|.*?[^\\])\] ) # first target with attributes list
|
19
|
+
(?: \+ (?:\S*?) \[(?:|.*?[^\\])\] )* # other targets with wttributes lists
|
20
|
+
)
|
21
|
+
/x
|
22
|
+
|
23
|
+
MACRO_PARAMETERS_REGEXP = /
|
24
|
+
\G # restart metching from here
|
25
|
+
(?:
|
26
|
+
[:+] # separator
|
27
|
+
(\S*?) # optional target
|
28
|
+
\[(|.*?[^\\])\] # attributes list
|
29
|
+
)
|
30
|
+
/x
|
31
|
+
|
15
32
|
REF_ATTRIBUTES = %i[chapter page section clause].freeze
|
16
33
|
|
17
34
|
MISSING_ID_MARK = "*??*".freeze
|
@@ -22,7 +39,7 @@ module AsciidoctorBibliography
|
|
22
39
|
@uuid = SecureRandom.uuid
|
23
40
|
@macro = macro
|
24
41
|
@citation_items = []
|
25
|
-
target_and_attributes_list_pairs.
|
42
|
+
target_and_attributes_list_pairs.each do |target, attribute_list|
|
26
43
|
@citation_items << CitationItem.new do |cite|
|
27
44
|
cite.target = target.to_s.empty? ? "default" : target
|
28
45
|
cite.parse_attribute_list attribute_list
|
@@ -22,10 +22,10 @@ module AsciidoctorBibliography
|
|
22
22
|
"author" => get_author_list(reference_tag),
|
23
23
|
"title" => reference_tag.xpath("//title").first&.text&.strip,
|
24
24
|
"issued" => {
|
25
|
-
"date-parts" => get_date_parts(reference_tag)
|
25
|
+
"date-parts" => get_date_parts(reference_tag)
|
26
26
|
},
|
27
27
|
# NOTE: we keep the original XML to re-render it when needed
|
28
|
-
"note" => reference_tag.to_xml
|
28
|
+
"note" => reference_tag.to_xml
|
29
29
|
}
|
30
30
|
end
|
31
31
|
|
@@ -43,7 +43,7 @@ module AsciidoctorBibliography
|
|
43
43
|
author_tags.map do |author_tag|
|
44
44
|
{
|
45
45
|
"family" => author_tag&.attr("surname"),
|
46
|
-
"given" => author_tag&.attr("initials")
|
46
|
+
"given" => author_tag&.attr("initials")
|
47
47
|
}
|
48
48
|
end
|
49
49
|
end
|
@@ -15,7 +15,7 @@ module AsciidoctorBibliography
|
|
15
15
|
"bibliography-tex-style" => "authoryear",
|
16
16
|
"bibliography-sort" => nil,
|
17
17
|
"bibliography-prepend-empty" => "true",
|
18
|
-
"bibliography-passthrough" => "false"
|
18
|
+
"bibliography-passthrough" => "false"
|
19
19
|
}.freeze
|
20
20
|
|
21
21
|
def initialize
|
@@ -35,8 +35,12 @@ module CiteProc
|
|
35
35
|
private
|
36
36
|
|
37
37
|
def aligned_first_field?
|
38
|
-
return
|
39
|
-
|
38
|
+
return node.root.bibliography.layout.children.first == node if aligned_first_accessible?
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
def aligned_first_accessible?
|
43
|
+
!(node.root.is_a? CSL::Locale) && node.root.bibliography["second-field-align"]
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|
data/spec/citation_helper.rb
CHANGED
@@ -24,7 +24,9 @@ def formatted_citation(macro, options: {})
|
|
24
24
|
bibliographer = init_bibliographer options: options
|
25
25
|
|
26
26
|
macro.gsub(AsciidoctorBibliography::Citation::REGEXP) do
|
27
|
-
|
27
|
+
macro_name, macro_pars = Regexp.last_match.captures
|
28
|
+
target_and_attributes_list_pairs = macro_pars.scan(AsciidoctorBibliography::Citation::MACRO_PARAMETERS_REGEXP)
|
29
|
+
citation = AsciidoctorBibliography::Citation.new(macro_name, *target_and_attributes_list_pairs)
|
28
30
|
bibliographer.add_citation(citation)
|
29
31
|
citation.render bibliographer
|
30
32
|
end
|
@@ -33,7 +35,9 @@ end
|
|
33
35
|
def formatted_bibliography(macro, options: {})
|
34
36
|
bibliographer = init_bibliographer options: options
|
35
37
|
macro.gsub(AsciidoctorBibliography::Citation::REGEXP) do
|
36
|
-
|
38
|
+
macro_name, macro_pars = Regexp.last_match.captures
|
39
|
+
target_and_attributes_list_pairs = macro_pars.scan(AsciidoctorBibliography::Citation::MACRO_PARAMETERS_REGEXP)
|
40
|
+
citation = AsciidoctorBibliography::Citation.new(macro_name, *target_and_attributes_list_pairs)
|
37
41
|
bibliographer.add_citation(citation)
|
38
42
|
# citation.render bibliographer
|
39
43
|
index = AsciidoctorBibliography::Index.new("bibliography", "", "")
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require "asciidoctor-bibliography"
|
4
|
+
require "asciidoctor-bibliography/asciidoctor/bibliographer_preprocessor"
|
5
|
+
|
6
|
+
describe "an asciidoctor document with bibliography usage" do
|
7
|
+
let(:document) do
|
8
|
+
input = <<~'ASCIIDOC'
|
9
|
+
= This is the document title
|
10
|
+
:doctype: book
|
11
|
+
:bibliography-database: ./spec/fixtures/database-issue84.bib
|
12
|
+
:bibliography-style: university-of-york-mla
|
13
|
+
== Section 1
|
14
|
+
The Advanced Research Projects Agency Network (ARPANET),
|
15
|
+
an early network connecting many major universities and
|
16
|
+
research institutions in the USA,
|
17
|
+
was first demonstrated publicly in October 1972
|
18
|
+
cite:[roberts_arpanet_1986, page=3].
|
19
|
+
It was initially funded by the United States
|
20
|
+
Department of Defense during the cold war as a part of
|
21
|
+
"the command and control assignment" of the ARPA program
|
22
|
+
cite:[lukasik_why_2011, page=10].
|
23
|
+
The ((ARPANET)) was designed to be "as distributed as possible,"
|
24
|
+
because its routing algorithm was adapted from an article by Paul Baran,
|
25
|
+
written at the time he was at the RAND Corporation researching
|
26
|
+
on highly survivable communication networks "in the thermonuclear era"
|
27
|
+
cite:[baran_distributed_1964, page=18].
|
28
|
+
With the support of the US National Science Foundation, ARPANET gradually
|
29
|
+
"evolved into a commercial, worldwide open network" -- the Internet
|
30
|
+
cite:[dommering_internet:_2015, page=13].
|
31
|
+
[bibliography]
|
32
|
+
== Bibliography
|
33
|
+
bibliography::[]
|
34
|
+
ASCIIDOC
|
35
|
+
document = ::Asciidoctor::Document.new(input)
|
36
|
+
document.parse
|
37
|
+
document
|
38
|
+
end
|
39
|
+
|
40
|
+
it "creates a valid internal bibliographer state" do
|
41
|
+
expect(document.bibliographer.occurring_keys["default"]).
|
42
|
+
to eq ["roberts_arpanet_1986",
|
43
|
+
"lukasik_why_2011",
|
44
|
+
"baran_distributed_1964",
|
45
|
+
"dommering_internet:_2015"]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "generates the correct mla bibliography" do
|
49
|
+
expect(document.catalog[:refs]["_bibliography"].blocks[0].lines[0]).
|
50
|
+
to include("Baran, Paul.")
|
51
|
+
expect(document.catalog[:refs]["_bibliography"].blocks[1].lines[0]).
|
52
|
+
to include("Dommering, E., et al.")
|
53
|
+
expect(document.catalog[:refs]["_bibliography"].blocks[2].lines[0]).
|
54
|
+
to include("Lukasik, Stephen.")
|
55
|
+
expect(document.catalog[:refs]["_bibliography"].blocks[3].lines[0]).
|
56
|
+
to include("Roberts, Larry.")
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
@article{baran_distributed_1964,
|
3
|
+
title = {On distributed communications networks},
|
4
|
+
volume = {12},
|
5
|
+
issn = {0096-1965},
|
6
|
+
number = {1},
|
7
|
+
journal = {IEEE transactions on Communications Systems},
|
8
|
+
author = {Baran, Paul},
|
9
|
+
year = {1964},
|
10
|
+
pages = {1--9},
|
11
|
+
file = {Bar64.pdf:https://www.rand.org/pubs/papers/P2626.html:text/html}
|
12
|
+
}
|
13
|
+
|
14
|
+
@article{lukasik_why_2011,
|
15
|
+
title = {Why the {Arpanet} {Was} {Built}},
|
16
|
+
volume = {33},
|
17
|
+
issn = {1058-6180},
|
18
|
+
url = {http://ieeexplore.ieee.org/document/5432117/},
|
19
|
+
doi = {10.1109/MAHC.2010.11},
|
20
|
+
language = {en},
|
21
|
+
number = {3},
|
22
|
+
urldate = {2019-02-20},
|
23
|
+
journal = {IEEE Annals of the History of Computing},
|
24
|
+
author = {Lukasik, Stephen},
|
25
|
+
month = mar,
|
26
|
+
year = {2011},
|
27
|
+
pages = {4--21},
|
28
|
+
file = {Lukasik - 2011 - Why the Arpanet Was Built.pdf:application/pdf}
|
29
|
+
}
|
30
|
+
|
31
|
+
@inproceedings{roberts_arpanet_1986,
|
32
|
+
title = {The {Arpanet} and computer networks},
|
33
|
+
isbn = {0-89791-176-8},
|
34
|
+
publisher = {ACM},
|
35
|
+
author = {Roberts, Larry},
|
36
|
+
year = {1986},
|
37
|
+
pages = {51--58},
|
38
|
+
file = {p51-roberts.pdf:application/pdf}
|
39
|
+
}
|
40
|
+
|
41
|
+
@article{dommering_internet:_2015,
|
42
|
+
title = {The {Internet}: a global free space with limited state control},
|
43
|
+
shorttitle = {The {Internet}},
|
44
|
+
url = {https://dare.uva.nl/search?identifier=8672fb24-0825-4bdb-98ac-989e370446ae},
|
45
|
+
language = {en},
|
46
|
+
urldate = {2019-02-20},
|
47
|
+
author = {Dommering, E. and van Ginkel, B. and de Goede, M. and Koops, B. J. and Plooij-van Gorsel, E. and Verrijn Stuart, H. and Smallenbroek, J.},
|
48
|
+
year = {2015},
|
49
|
+
file = {THE INTERNET A GLOBAL FREE SPACE WITH LIMITED STAT.pdf:application/pdf}
|
50
|
+
}
|
data/spec/macros_spec.rb
CHANGED
@@ -41,3 +41,13 @@ describe "cite macro using an unknown key" do
|
|
41
41
|
to eq "*??*"
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
describe "cite macro using more than two keys" do
|
46
|
+
it "formats all cited keys" do
|
47
|
+
expect(formatted_citation("cite:[Lane12a]+[Lane12b]+[Erdos65]+[Einstein35]",
|
48
|
+
options: { "bibliography-style" => "apa",
|
49
|
+
"bibliography-database" => "database.bib",
|
50
|
+
"bibliography-hyperlinks" => "true" })).
|
51
|
+
to eq "(xref:bibliography-default-Einstein35[Einstein, Podolsky, & Rosen, 1935]; xref:bibliography-default-Erdos65[Erdős, Heyting, & Brouwer, 1965]; xref:bibliography-default-Lane12a[Lane, 2000]; xref:bibliography-default-Lane12b[Mane & Smith, 2000])"
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-bibliography
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
@@ -210,6 +210,8 @@ files:
|
|
210
210
|
- Rakefile
|
211
211
|
- SYNTAX.adoc
|
212
212
|
- asciidoctor-bibliography.gemspec
|
213
|
+
- bin/rspec
|
214
|
+
- bin/setup
|
213
215
|
- lib/asciidoctor-bibliography.rb
|
214
216
|
- lib/asciidoctor-bibliography/asciidoctor.rb
|
215
217
|
- lib/asciidoctor-bibliography/asciidoctor/bibliographer_preprocessor.rb
|
@@ -298,6 +300,8 @@ files:
|
|
298
300
|
- spec/csl/styles/tex_citeyearpar_authoryear_spec.rb
|
299
301
|
- spec/csl/styles/tex_citeyearpar_numeric_spec.rb
|
300
302
|
- spec/database_spec.rb
|
303
|
+
- spec/end_to_end_spec.rb
|
304
|
+
- spec/fixtures/database-issue84.bib
|
301
305
|
- spec/fixtures/database.bib
|
302
306
|
- spec/fixtures/database.bibtex
|
303
307
|
- spec/fixtures/database.rfc.xml
|