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.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +23 -4
  3. data/asciidoctor-bibliography.gemspec +8 -8
  4. data/lib/asciidoctor-bibliography.rb +6 -0
  5. data/lib/asciidoctor-bibliography/asciidoctor/bibliographer_preprocessor.rb +35 -23
  6. data/lib/asciidoctor-bibliography/bibliographer.rb +0 -15
  7. data/lib/asciidoctor-bibliography/citation.rb +29 -22
  8. data/lib/asciidoctor-bibliography/databases/bibtex.rb +4 -1
  9. data/lib/asciidoctor-bibliography/formatter.rb +28 -0
  10. data/lib/asciidoctor-bibliography/index.rb +24 -16
  11. data/lib/asciidoctor-bibliography/options.rb +65 -32
  12. data/lib/asciidoctor-bibliography/version.rb +1 -1
  13. data/lib/citeproc/ruby/formats/adoc.rb +36 -0
  14. data/lib/csl/styles/tex-citealp-authoryear.csl +117 -0
  15. data/lib/csl/styles/tex-citealp-numeric.csl +116 -0
  16. data/lib/csl/styles/tex-citealps-authoryear.csl +117 -0
  17. data/lib/csl/styles/tex-citealps-numeric.csl +116 -0
  18. data/lib/csl/styles/tex-citealt-authoryear.csl +119 -0
  19. data/lib/csl/styles/tex-citealt-numeric.csl +119 -0
  20. data/lib/csl/styles/tex-citealts-authoryear.csl +119 -0
  21. data/lib/csl/styles/tex-citealts-numeric.csl +119 -0
  22. data/lib/csl/styles/tex-citeauthor-authoryear.csl +116 -0
  23. data/lib/csl/styles/tex-citeauthor-numeric.csl +116 -0
  24. data/lib/csl/styles/tex-citeauthors-authoryear.csl +116 -0
  25. data/lib/csl/styles/tex-citeauthors-numeric.csl +116 -0
  26. data/lib/csl/styles/tex-citep-authoryear.csl +117 -0
  27. data/lib/csl/styles/tex-citep-numeric.csl +116 -0
  28. data/lib/csl/styles/tex-citeps-authoryear.csl +117 -0
  29. data/lib/csl/styles/tex-citeps-numeric.csl +116 -0
  30. data/lib/csl/styles/tex-citet-authoryear.csl +119 -0
  31. data/lib/csl/styles/tex-citet-numeric.csl +119 -0
  32. data/lib/csl/styles/tex-citets-authoryear.csl +119 -0
  33. data/lib/csl/styles/tex-citets-numeric.csl +119 -0
  34. data/lib/csl/styles/tex-citeyear-authoryear.csl +116 -0
  35. data/lib/csl/styles/tex-citeyear-numeric.csl +116 -0
  36. data/lib/csl/styles/tex-citeyearpar-authoryear.csl +116 -0
  37. data/lib/csl/styles/tex-citeyearpar-numeric.csl +116 -0
  38. data/samples/tex/sample-numbers.adoc +1 -1
  39. data/samples/tex/sample-sort.adoc +1 -1
  40. data/spec/citation_helper.rb +46 -0
  41. data/spec/citation_item_spec.rb +0 -2
  42. data/spec/csl/styles/tex_citealp_authoryear_spec.rb +42 -0
  43. data/spec/csl/styles/tex_citealp_numeric_spec.rb +42 -0
  44. data/spec/csl/styles/tex_citealps_authoryear_spec.rb +42 -0
  45. data/spec/csl/styles/tex_citealps_numeric_spec.rb +42 -0
  46. data/spec/csl/styles/tex_citealt_authoryear_spec.rb +42 -0
  47. data/spec/csl/styles/tex_citealt_numeric_spec.rb +42 -0
  48. data/spec/csl/styles/tex_citealts_authoryear_spec.rb +42 -0
  49. data/spec/csl/styles/tex_citealts_numeric_spec.rb +42 -0
  50. data/spec/csl/styles/tex_citeauthor_authoryear_spec.rb +42 -0
  51. data/spec/csl/styles/tex_citeauthor_numeric_spec.rb +42 -0
  52. data/spec/csl/styles/tex_citeauthors_authoryear_spec.rb +42 -0
  53. data/spec/csl/styles/tex_citeauthors_numeric_spec.rb +42 -0
  54. data/spec/csl/styles/tex_citep_authoryear_spec.rb +42 -0
  55. data/spec/csl/styles/tex_citep_numeric_spec.rb +42 -0
  56. data/spec/csl/styles/tex_citeps_authoryear_spec.rb +42 -0
  57. data/spec/csl/styles/tex_citeps_numeric_spec.rb +42 -0
  58. data/spec/csl/styles/tex_citet_authoryear_spec.rb +42 -0
  59. data/spec/csl/styles/tex_citet_numeric_spec.rb +42 -0
  60. data/spec/csl/styles/tex_citets_authoryear_spec.rb +42 -0
  61. data/spec/csl/styles/tex_citets_numeric_spec.rb +42 -0
  62. data/spec/csl/styles/tex_citeyear_authoryear_spec.rb +42 -0
  63. data/spec/csl/styles/tex_citeyear_numeric_spec.rb +42 -0
  64. data/spec/csl/styles/tex_citeyearpar_authoryear_spec.rb +42 -0
  65. data/spec/csl/styles/tex_citeyearpar_numeric_spec.rb +42 -0
  66. data/spec/database_spec.rb +20 -1
  67. data/spec/macros_spec.rb +21 -0
  68. data/spec/options_spec.rb +105 -1
  69. metadata +72 -24
  70. data/lib/asciidoctor-bibliography/formatters/csl.rb +0 -28
  71. data/lib/asciidoctor-bibliography/formatters/tex.rb +0 -187
  72. data/lib/asciidoctor-bibliography/helpers.rb +0 -41
  73. data/spec/helpers_spec.rb +0 -73
@@ -0,0 +1,116 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="never">
3
+ <info>
4
+ <title>TeX style for macro citeyearpar with numeric style</title>
5
+ <id>tex-citeyearpar-numeric</id>
6
+ </info>
7
+ <macro name="author-long">
8
+ <names variable="author">
9
+ <name form="short" and="text" initialize="false" sort-separator=""/>
10
+ </names>
11
+ </macro>
12
+ <macro name="author-short">
13
+ <names variable="author">
14
+ <name form="short" and="text" et-al-min="2" et-al-use-first="1" et-al-subsequent-min="2" et-al-subsequent-use-first="1"/>
15
+ </names>
16
+ </macro>
17
+ <macro name="locators">
18
+ <choose>
19
+ <if type="article-journal article-magazine" match="any">
20
+ <group prefix=", " delimiter=", ">
21
+ <group>
22
+ <text variable="volume" font-style="italic"/>
23
+ <text variable="issue" prefix="(" suffix=")"/>
24
+ </group>
25
+ <text variable="page"/>
26
+ </group>
27
+ <choose>
28
+ <if variable="issued">
29
+ <choose>
30
+ <if variable="page issue" match="none">
31
+ <text variable="status" prefix=". "/>
32
+ </if>
33
+ </choose>
34
+ </if>
35
+ </choose>
36
+ </if>
37
+ <else-if type="article-newspaper">
38
+ <group delimiter=" " prefix=", ">
39
+ <label variable="page" form="short"/>
40
+ <text variable="page"/>
41
+ </group>
42
+ </else-if>
43
+ <else-if type="book graphic motion_picture report song chapter paper-conference entry-encyclopedia entry-dictionary" match="any">
44
+ <group prefix=" (" suffix=")" delimiter=", ">
45
+ <choose>
46
+ <if type="report" match="none">
47
+ <text macro="edition"/>
48
+ </if>
49
+ </choose>
50
+ <choose>
51
+ <if variable="volume" match="any">
52
+ <group>
53
+ <text term="volume" form="short" text-case="capitalize-first" suffix=" "/>
54
+ <number variable="volume" form="numeric"/>
55
+ </group>
56
+ </if>
57
+ <else>
58
+ <group>
59
+ <text term="volume" form="short" plural="true" text-case="capitalize-first" suffix=" "/>
60
+ <number variable="number-of-volumes" form="numeric" prefix="1–"/>
61
+ </group>
62
+ </else>
63
+ </choose>
64
+ <group>
65
+ <label variable="page" form="short" suffix=" "/>
66
+ <text variable="page"/>
67
+ </group>
68
+ </group>
69
+ </else-if>
70
+ <else-if type="legal_case">
71
+ <group prefix=" (" suffix=")" delimiter=" ">
72
+ <text variable="authority"/>
73
+ <choose>
74
+ <if variable="container-title" match="any">
75
+ <date variable="issued" form="numeric" date-parts="year"/>
76
+ </if>
77
+ <else>
78
+ <date variable="issued" form="text"/>
79
+ </else>
80
+ </choose>
81
+ </group>
82
+ </else-if>
83
+ <else-if type="bill legislation" match="any">
84
+ <date variable="issued" prefix=" (" suffix=")">
85
+ <date-part name="year"/>
86
+ </date>
87
+ </else-if>
88
+ </choose>
89
+ </macro>
90
+ <macro name="citation-locator">
91
+ <group>
92
+ <choose>
93
+ <if locator="chapter">
94
+ <label variable="locator" form="long" text-case="capitalize-first"/>
95
+ </if>
96
+ <else>
97
+ <label variable="locator" form="short"/>
98
+ </else>
99
+ </choose>
100
+ <text variable="locator" prefix=" "/>
101
+ </group>
102
+ </macro>
103
+ <citation>
104
+ <layout delimiter=", " prefix="[" suffix="]">
105
+ <group>
106
+ <text variable="prefix" suffix=" "/>
107
+ <group delimiter=", ">
108
+ <date date-parts="year" form="numeric" variable="issued"/>
109
+ <text macro="citation-locator"/>
110
+ </group>
111
+ <text variable="suffix" prefix=", "/>
112
+ </group>
113
+ </layout>
114
+ </citation>
115
+ <bibliography/>
116
+ </style>
@@ -1,6 +1,6 @@
1
1
  = Sample usage of asciidoctor-bibliography
2
2
  :bibliography-database: biblio.bib
3
- :bibliography-tex-style: numbers
3
+ :bibliography-tex-style: numeric
4
4
  :bibliography-style: ieee
5
5
 
6
6
 
@@ -1,6 +1,6 @@
1
1
  = Sample usage of asciidoctor-bibliography
2
2
  :bibliography-database: biblio.bib
3
- :bibliography-tex-style: numbers
3
+ :bibliography-tex-style: numeric
4
4
  :bibliography-style: ieee
5
5
  :bibliography-sort: { macro: author, sort: descending }
6
6
 
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+
3
+ require "asciidoctor-bibliography"
4
+
5
+ TEST_BIBTEX_DATABASE = <<~BIBTEX.freeze
6
+ @article{Erdos65,
7
+ title = {Some very hard sums},
8
+ journal={Difficult Maths Today},
9
+ author={Paul Erdős and Arend Heyting and Luitzen Egbertus Brouwer},
10
+ year={1965},
11
+ pages={30}
12
+ }
13
+
14
+ @article{Einstein35,
15
+ title={Can quantum-mechanical description of physical reality be considered complete?},
16
+ author={Einstein, Albert and Podolsky, Boris and Rosen, Nathan},
17
+ journal={Physical review},
18
+ volume={47},
19
+ number={10},
20
+ pages={777},
21
+ year={1935},
22
+ publisher={APS}
23
+ }
24
+ BIBTEX
25
+
26
+ def init_bibliographer(options)
27
+ bibliographer = AsciidoctorBibliography::Bibliographer.new
28
+
29
+ bibliographer.options = AsciidoctorBibliography::Options.new.
30
+ merge("bibliography-hyperlinks" => "false").merge(options)
31
+
32
+ bibliographer.database = AsciidoctorBibliography::Database.new.
33
+ concat(::BibTeX.parse(TEST_BIBTEX_DATABASE).to_citeproc)
34
+
35
+ bibliographer
36
+ end
37
+
38
+ def formatted_citation(macro, options: {})
39
+ bibliographer = init_bibliographer options
40
+
41
+ macro.gsub(AsciidoctorBibliography::Citation::REGEXP) do
42
+ citation = AsciidoctorBibliography::Citation.new(*Regexp.last_match.captures)
43
+ bibliographer.add_citation(citation)
44
+ citation.render bibliographer
45
+ end.gsub(/^{empty}/, "")
46
+ end
@@ -1,5 +1,3 @@
1
- require "asciidoctor-bibliography/helpers"
2
-
3
1
  describe AsciidoctorBibliography::CitationItem do
4
2
  describe ".new" do
5
3
  it "can be mutely initialized" do
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ require_relative "../../citation_helper"
4
+
5
+ describe "citealp macro with authoryear style" do
6
+ let(:options) { { "bibliography-tex-style" => "authoryear" } }
7
+
8
+ it "formats a single citation" do
9
+ expect(formatted_citation("citealp:[Erdos65]", options: options)).
10
+ to eq "Erdős et al., 1965"
11
+ end
12
+
13
+ it "formats a grouped citation" do
14
+ expect(formatted_citation("citealp:[Erdos65]+[Einstein35]", options: options)).
15
+ to eq "Erdős et al., 1965; Einstein et al., 1935"
16
+ end
17
+
18
+ it "formats a single citation with a prefix" do
19
+ expect(formatted_citation("citealp:[Erdos65, prefix=see]", options: options)).
20
+ to eq "see Erdős et al., 1965"
21
+ end
22
+
23
+ it "formats a single citation with a suffix" do
24
+ expect(formatted_citation("citealp:[Erdos65, suffix=new edition]", options: options)).
25
+ to eq "Erdős et al., 1965, new edition"
26
+ end
27
+
28
+ it "formats a single citation with both a prefix and a suffix" do
29
+ expect(formatted_citation("citealp:[Erdos65, prefix=see, suffix=new edition]", options: options)).
30
+ to eq "see Erdős et al., 1965, new edition"
31
+ end
32
+
33
+ it "formats a single citation with a standard locator" do
34
+ expect(formatted_citation("citealp:[Erdos65, page=41-43]", options: options)).
35
+ to eq "Erdős et al., 1965, pp. 41-43"
36
+ end
37
+
38
+ it "formats a single citation with a custom locator" do
39
+ expect(formatted_citation("citealp:[Erdos65, locator=somewhere]", options: options)).
40
+ to eq "Erdős et al., 1965, somewhere"
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ require_relative "../../citation_helper"
4
+
5
+ describe "citealp macro with numeric style" do
6
+ let(:options) { { "bibliography-tex-style" => "numeric" } }
7
+
8
+ it "formats a single citation" do
9
+ expect(formatted_citation("citealp:[Erdos65]", options: options)).
10
+ to eq "1"
11
+ end
12
+
13
+ it "formats a grouped citation" do
14
+ expect(formatted_citation("citealp:[Erdos65]+[Einstein35]", options: options)).
15
+ to eq "1, 2"
16
+ end
17
+
18
+ it "formats a single citation with a prefix" do
19
+ expect(formatted_citation("citealp:[Erdos65, prefix=see]", options: options)).
20
+ to eq "see 1"
21
+ end
22
+
23
+ it "formats a single citation with a suffix" do
24
+ expect(formatted_citation("citealp:[Erdos65, suffix=new edition]", options: options)).
25
+ to eq "1, new edition"
26
+ end
27
+
28
+ it "formats a single citation with both a prefix and a suffix" do
29
+ expect(formatted_citation("citealp:[Erdos65, prefix=see, suffix=new edition]", options: options)).
30
+ to eq "see 1, new edition"
31
+ end
32
+
33
+ it "formats a single citation with a standard locator" do
34
+ expect(formatted_citation("citealp:[Erdos65, page=41-43]", options: options)).
35
+ to eq "1, pp. 41-43"
36
+ end
37
+
38
+ it "formats a single citation with a custom locator" do
39
+ expect(formatted_citation("citealp:[Erdos65, locator=somewhere]", options: options)).
40
+ to eq "1, somewhere"
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ require_relative "../../citation_helper"
4
+
5
+ describe "citealp* macro with authoryear style" do
6
+ let(:options) { { "bibliography-tex-style" => "authoryear" } }
7
+
8
+ it "formats a single citation" do
9
+ expect(formatted_citation("citealp*:[Erdos65]", options: options)).
10
+ to eq "Erdős, Heyting, and Brouwer, 1965"
11
+ end
12
+
13
+ it "formats a grouped citation" do
14
+ expect(formatted_citation("citealp*:[Erdos65]+[Einstein35]", options: options)).
15
+ to eq "Erdős, Heyting, and Brouwer, 1965; Einstein, Podolsky, and Rosen, 1935"
16
+ end
17
+
18
+ it "formats a single citation with a prefix" do
19
+ expect(formatted_citation("citealp*:[Erdos65, prefix=see]", options: options)).
20
+ to eq "see Erdős, Heyting, and Brouwer, 1965"
21
+ end
22
+
23
+ it "formats a single citation with a suffix" do
24
+ expect(formatted_citation("citealp*:[Erdos65, suffix=new edition]", options: options)).
25
+ to eq "Erdős, Heyting, and Brouwer, 1965, new edition"
26
+ end
27
+
28
+ it "formats a single citation with both a prefix and a suffix" do
29
+ expect(formatted_citation("citealp*:[Erdos65, prefix=see, suffix=new edition]", options: options)).
30
+ to eq "see Erdős, Heyting, and Brouwer, 1965, new edition"
31
+ end
32
+
33
+ it "formats a single citation with a standard locator" do
34
+ expect(formatted_citation("citealp*:[Erdos65, page=41-43]", options: options)).
35
+ to eq "Erdős, Heyting, and Brouwer, 1965, pp. 41-43"
36
+ end
37
+
38
+ it "formats a single citation with a custom locator" do
39
+ expect(formatted_citation("citealp*:[Erdos65, locator=somewhere]", options: options)).
40
+ to eq "Erdős, Heyting, and Brouwer, 1965, somewhere"
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ require_relative "../../citation_helper"
4
+
5
+ describe "citealp* macro with numeric style" do
6
+ let(:options) { { "bibliography-tex-style" => "numeric" } }
7
+
8
+ it "formats a single citation" do
9
+ expect(formatted_citation("citealp*:[Erdos65]", options: options)).
10
+ to eq "1"
11
+ end
12
+
13
+ it "formats a grouped citation" do
14
+ expect(formatted_citation("citealp*:[Erdos65]+[Einstein35]", options: options)).
15
+ to eq "1, 2"
16
+ end
17
+
18
+ it "formats a single citation with a prefix" do
19
+ expect(formatted_citation("citealp*:[Erdos65, prefix=see]", options: options)).
20
+ to eq "see 1"
21
+ end
22
+
23
+ it "formats a single citation with a suffix" do
24
+ expect(formatted_citation("citealp*:[Erdos65, suffix=new edition]", options: options)).
25
+ to eq "1, new edition"
26
+ end
27
+
28
+ it "formats a single citation with both a prefix and a suffix" do
29
+ expect(formatted_citation("citealp*:[Erdos65, prefix=see, suffix=new edition]", options: options)).
30
+ to eq "see 1, new edition"
31
+ end
32
+
33
+ it "formats a single citation with a standard locator" do
34
+ expect(formatted_citation("citealp*:[Erdos65, page=41-43]", options: options)).
35
+ to eq "1, pp. 41-43"
36
+ end
37
+
38
+ it "formats a single citation with a custom locator" do
39
+ expect(formatted_citation("citealp*:[Erdos65, locator=somewhere]", options: options)).
40
+ to eq "1, somewhere"
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ require_relative "../../citation_helper"
4
+
5
+ describe "citealt macro with authoryear style" do
6
+ let(:options) { { "bibliography-tex-style" => "authoryear" } }
7
+
8
+ it "formats a single citation" do
9
+ expect(formatted_citation("citealt:[Erdos65]", options: options)).
10
+ to eq "Erdős et al. 1965"
11
+ end
12
+
13
+ it "formats a grouped citation" do
14
+ expect(formatted_citation("citealt:[Erdos65]+[Einstein35]", options: options)).
15
+ to eq "Erdős et al. 1965; Einstein et al. 1935"
16
+ end
17
+
18
+ it "formats a single citation with a prefix" do
19
+ expect(formatted_citation("citealt:[Erdos65, prefix=see]", options: options)).
20
+ to eq "Erdős et al. see 1965"
21
+ end
22
+
23
+ it "formats a single citation with a suffix" do
24
+ expect(formatted_citation("citealt:[Erdos65, suffix=new edition]", options: options)).
25
+ to eq "Erdős et al. 1965, new edition"
26
+ end
27
+
28
+ it "formats a single citation with both a prefix and a suffix" do
29
+ expect(formatted_citation("citealt:[Erdos65, prefix=see, suffix=new edition]", options: options)).
30
+ to eq "Erdős et al. see 1965, new edition"
31
+ end
32
+
33
+ it "formats a single citation with a standard locator" do
34
+ expect(formatted_citation("citealt:[Erdos65, page=41-43]", options: options)).
35
+ to eq "Erdős et al. 1965, pp. 41-43"
36
+ end
37
+
38
+ it "formats a single citation with a custom locator" do
39
+ expect(formatted_citation("citealt:[Erdos65, locator=somewhere]", options: options)).
40
+ to eq "Erdős et al. 1965, somewhere"
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ require_relative "../../citation_helper"
4
+
5
+ describe "citealt macro with numeric style" do
6
+ let(:options) { { "bibliography-tex-style" => "numeric" } }
7
+
8
+ it "formats a single citation" do
9
+ expect(formatted_citation("citealt:[Erdos65]", options: options)).
10
+ to eq "Erdős et al. 1"
11
+ end
12
+
13
+ it "formats a grouped citation" do
14
+ expect(formatted_citation("citealt:[Erdos65]+[Einstein35]", options: options)).
15
+ to eq "Erdős et al. 1, Einstein et al. 2"
16
+ end
17
+
18
+ it "formats a single citation with a prefix" do
19
+ expect(formatted_citation("citealt:[Erdos65, prefix=see]", options: options)).
20
+ to eq "Erdős et al. see 1"
21
+ end
22
+
23
+ it "formats a single citation with a suffix" do
24
+ expect(formatted_citation("citealt:[Erdos65, suffix=new edition]", options: options)).
25
+ to eq "Erdős et al. 1, new edition"
26
+ end
27
+
28
+ it "formats a single citation with both a prefix and a suffix" do
29
+ expect(formatted_citation("citealt:[Erdos65, prefix=see, suffix=new edition]", options: options)).
30
+ to eq "Erdős et al. see 1, new edition"
31
+ end
32
+
33
+ it "formats a single citation with a standard locator" do
34
+ expect(formatted_citation("citealt:[Erdos65, page=41-43]", options: options)).
35
+ to eq "Erdős et al. 1, pp. 41-43"
36
+ end
37
+
38
+ it "formats a single citation with a custom locator" do
39
+ expect(formatted_citation("citealt:[Erdos65, locator=somewhere]", options: options)).
40
+ to eq "Erdős et al. 1, somewhere"
41
+ end
42
+ end