asciidoctor-bibliography 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5a347f15409faab328c514fa0f6e63e3f583af11
4
- data.tar.gz: 0b6b7cba4b713bb56415d847f3d4ef385d0bb85e
2
+ SHA256:
3
+ metadata.gz: 61e7b49f2a7f0748b403572c395888484d08fbd839c2b1936cd1b481b5ea6e55
4
+ data.tar.gz: 4082bfb58062751ae7f51da843513a941d7f1ed156c77cc31fffe42257c6ba03
5
5
  SHA512:
6
- metadata.gz: 19c0a0935001b19eccf5b76e9b0453e9ac81888e27fbdfffc47929bde2d0580ae7cd80b4ec19a7e8c82ec62c06261d694371fe5f30ec9c4c47dc1b9d86e2848a
7
- data.tar.gz: 1c6f3ca017bd84ffd4ac2a649717a57abab9882c3aa1995e743563988c3c350a511e794d2941b6b155cf6859bb77b9ee69d889c56c3de405d1b5de99d454c19e
6
+ metadata.gz: c998f87e682d397e64da720491651556eb320bd7227162827fb3297b352635a5ecc874f33f62373939f9eae440d263bf565013f2b534a5ad61c60f7387573410
7
+ data.tar.gz: 139fe43a494d4cbbe0b2c616a9d89342169f03241c422dc0bc7d965418277ff0d712b90a0a26858b645ef94ff03a26df8856971de2473cb92c62041eeb6457ba
data/README.adoc CHANGED
@@ -150,6 +150,29 @@ To render the bibliography you simply use the following block macro:
150
150
  bibliography::[]
151
151
  ----
152
152
 
153
+ You can handle multiple bibliographies by providing a target parameter to
154
+ citation macros:
155
+
156
+ [source,asciidoc]
157
+ ----
158
+ cite:foo[Aa2017]+bar[Bb2017]
159
+ ----
160
+
161
+ You can then render all citations targeting a specific bibliography
162
+ by using the target parameter again:
163
+
164
+ [source,asciidoc]
165
+ ----
166
+ ## Index of Foos
167
+
168
+ bibliography::foo[]
169
+
170
+ ## Index of Bars
171
+
172
+ bibliography::bar[]
173
+ ----
174
+
175
+ Giving no target is equivalent to using `default` as a target.
153
176
 
154
177
  === Databases
155
178
 
@@ -11,16 +11,19 @@ module AsciidoctorBibliography
11
11
  @citations = []
12
12
  @indices = []
13
13
  @database = nil
14
- @occurring_keys = []
14
+ @occurring_keys = Hash.new([])
15
15
  end
16
16
 
17
17
  def add_citation(citation)
18
18
  citations << citation
19
- @occurring_keys.concat(citation.citation_items.map(&:key)).uniq!
19
+ citation.citation_items.group_by(&:target).each do |target, citation_items|
20
+ @occurring_keys[target] ||= []
21
+ @occurring_keys[target].concat(citation_items.map(&:key)).uniq!
22
+ end
20
23
  end
21
24
 
22
- def appearance_index_of(id)
23
- @occurring_keys.index(id) + 1
25
+ def appearance_index_of(target, id)
26
+ @occurring_keys[target].index(id) + 1
24
27
  end
25
28
  end
26
29
  end
@@ -21,9 +21,9 @@ module AsciidoctorBibliography
21
21
  @macro = macro
22
22
  @citation_items = []
23
23
  # rubocop:disable Performance/HashEachMethods
24
- target_and_attributes_list_pairs.compact.each_slice(2).each do |_target, attribute_list|
24
+ target_and_attributes_list_pairs.compact.each_slice(2).each do |target, attribute_list|
25
25
  @citation_items << CitationItem.new do |cite|
26
- # NOTE: we're not doing anything with targets right now.
26
+ cite.target = target.to_s.empty? ? "default" : target
27
27
  cite.parse_attribute_list attribute_list
28
28
  end
29
29
  end
@@ -81,7 +81,7 @@ module AsciidoctorBibliography
81
81
 
82
82
  def prepare_metadata(bibliographer, cite, affix: false)
83
83
  bibliographer.database.find_entry_by_id(cite.key).
84
- merge 'citation-number': bibliographer.appearance_index_of(cite.key),
84
+ merge 'citation-number': bibliographer.appearance_index_of(cite.target, cite.key),
85
85
  'citation-label': cite.key, # TODO: smart label generators
86
86
  'locator': cite.locator.nil? ? nil : " ",
87
87
  'prefix': affix ? cite.prefix : nil,
@@ -93,7 +93,8 @@ module AsciidoctorBibliography
93
93
  # TODO: hyperlink, suppress_author and only_author options
94
94
  ci = citation_items.detect { |c| c.key == item.id }
95
95
  wrap_item item, ci.prefix, ci.suffix if affix
96
- wrap_item item, "xref:#{xref_id(item.id)}{{{", "}}}" if options.hyperlinks?
96
+ id = xref_id "bibliography", ci.target, item.id
97
+ wrap_item item, "xref:#{id}{{{", "}}}" if options.hyperlinks?
97
98
  item.label, item.locator = ci.locator
98
99
  end
99
100
 
@@ -106,12 +107,8 @@ module AsciidoctorBibliography
106
107
  ":#{@uuid}:"
107
108
  end
108
109
 
109
- def xref_id(key)
110
- ["bibliography", key].compact.join("-")
111
- end
112
-
113
- def xref(key, label)
114
- "xref:#{xref_id(key)}[#{label.gsub(']', '\]')}]"
110
+ def xref_id(*fragments)
111
+ fragments.compact.join("-")
115
112
  end
116
113
  end
117
114
  end
@@ -9,7 +9,7 @@ module AsciidoctorBibliography
9
9
 
10
10
  def initialize(macro, target, attributes)
11
11
  @macro = macro
12
- @target = target
12
+ @target = target.to_s.empty? ? "default" : target
13
13
  @attributes = ::Asciidoctor::AttributeList.new(attributes).parse
14
14
  end
15
15
 
@@ -19,7 +19,8 @@ module AsciidoctorBibliography
19
19
  lines = []
20
20
  formatter.bibliography.each_with_index do |reference, index|
21
21
  line = "{empty}"
22
- line << "anchor:#{anchor_id(formatter.data[index].id)}[]"
22
+ id = anchor_id "bibliography", target, formatter.data[index].id
23
+ line << "anchor:#{id}[]"
23
24
  line << reference
24
25
  lines << line
25
26
  end
@@ -43,27 +44,19 @@ module AsciidoctorBibliography
43
44
  end
44
45
 
45
46
  def prepare_filtered_db(bibliographer)
46
- bibliographer.occurring_keys.
47
+ bibliographer.occurring_keys[target].
47
48
  map { |id| bibliographer.database.find_entry_by_id(id) }.
48
49
  map { |entry| prepare_entry_metadata bibliographer, entry }
49
50
  end
50
51
 
51
52
  def prepare_entry_metadata(bibliographer, entry)
52
53
  entry.
53
- merge('citation-number': bibliographer.appearance_index_of(entry["id"])).
54
+ merge('citation-number': bibliographer.appearance_index_of(target, entry["id"])).
54
55
  merge('citation-label': entry["id"]) # TODO: smart label generators
55
56
  end
56
57
 
57
- def anchor_id(target)
58
- ["bibliography", target].compact.join("-")
59
- end
60
-
61
- def render_entry_label(target, formatter)
62
- formatter.render(:bibliography, id: target).join
63
- end
64
-
65
- def render_entry(target, formatter)
66
- "anchor:#{anchor_id(target)}[]#{render_entry_label(target, formatter)}"
58
+ def anchor_id(*fragments)
59
+ fragments.compact.join("-")
67
60
  end
68
61
  end
69
62
  end
@@ -1,3 +1,3 @@
1
1
  module AsciidoctorBibliography
2
- VERSION = "0.4.4".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
@@ -0,0 +1,25 @@
1
+ = Sample usage of asciidoctor-bibliography
2
+ :bibliography-database: biblio.bib
3
+ :bibliography-hyperlinks: true
4
+
5
+ ## Standard
6
+
7
+ cite:[Lane12a]
8
+
9
+ cite:foo[Anderson04]
10
+
11
+ cite:bar[Lane12a]+foo[Lane12b]
12
+
13
+ ## Bibliographies
14
+
15
+ ### Default
16
+
17
+ bibliography::default[]
18
+
19
+ ### Foo
20
+
21
+ bibliography::foo[]
22
+
23
+ ### Bar
24
+
25
+ bibliography::bar[]
data/spec/macros_spec.rb CHANGED
@@ -7,8 +7,8 @@ describe "cite macro with apa style" do
7
7
  expect(formatted_citation("cite:[Erdos65, prefix=see]+[Einstein35, page=41-43]",
8
8
  options: { "bibliography-style" => "apa",
9
9
  "bibliography-hyperlinks" => "true" })).
10
- to eq "(xref:bibliography-Einstein35[Einstein, Podolsky, & Rosen, 1935, pp. 41-43]; " +
11
- "xref:bibliography-Erdos65[seeErdős, Heyting, & Brouwer, 1965])"
10
+ to eq "(xref:bibliography-default-Einstein35[Einstein, Podolsky, & Rosen, 1935, pp. 41-43]; " +
11
+ "xref:bibliography-default-Erdos65[seeErdős, Heyting, & Brouwer, 1965])"
12
12
  end
13
13
  end
14
14
 
data/spec/sanity_spec.rb CHANGED
@@ -42,6 +42,13 @@ describe "asciidoctor integration" do
42
42
  publisher = {Publisher},
43
43
  year = {2000}
44
44
  }
45
+
46
+ @article{Qux00,
47
+ author = {Qux Zot},
48
+ title = {Title},
49
+ publisher = {Publisher},
50
+ year = {3000}
51
+ }
45
52
  BIBTEX
46
53
 
47
54
  describe "testing procedure" do
@@ -75,10 +82,10 @@ describe "asciidoctor integration" do
75
82
  expect(File.read(output_path)).to include <<~'BODY'
76
83
  <div id="content">
77
84
  <div class="paragraph">
78
- <p>Hello World. (<a href="#bibliography-Foo00">Bar, 2000</a>)</p>
85
+ <p>Hello World. (<a href="#bibliography-default-Foo00">Bar, 2000</a>)</p>
79
86
  </div>
80
87
  <div class="paragraph">
81
- <p><a id="bibliography-Foo00"></a>Bar, F. (2000). Title.</p>
88
+ <p><a id="bibliography-default-Foo00"></a>Bar, F. (2000). Title.</p>
82
89
  </div>
83
90
  </div>
84
91
  BODY
@@ -105,13 +112,101 @@ describe "asciidoctor integration" do
105
112
  expect(File.read(output_path)).to include <<~'BODY'
106
113
  <div id="content">
107
114
  <div class="paragraph">
108
- <p>Hello World. (<a href="#bibliography-Foo00">Bar, 2000</a>)</p>
115
+ <p>Hello World. (<a href="#bibliography-default-Foo00">Bar, 2000</a>)</p>
109
116
  </div>
110
117
  <div class="paragraph">
111
- <p>This is content from a nested file. (<a href="#bibliography-Foo00">Bar, 2000</a>)</p>
118
+ <p>This is content from a nested file. (<a href="#bibliography-default-Foo00">Bar, 2000</a>)</p>
112
119
  </div>
113
120
  <div class="paragraph">
114
- <p><a id="bibliography-Foo00"></a>Bar, F. (2000). Title.</p>
121
+ <p><a id="bibliography-default-Foo00"></a>Bar, F. (2000). Title.</p>
122
+ </div>
123
+ </div>
124
+ BODY
125
+ end
126
+ end
127
+
128
+ describe "multiple bibliographies usage" do
129
+ it "works with a single file and multiple bibliographies" do
130
+ setup_file tmpdir, "nested.adoc", <<~ADOC
131
+ This is content from a nested file. cite:[Foo00]
132
+
133
+ bibliography::[]
134
+ ADOC
135
+
136
+ input_path, output_path = setup_main_document tmpdir, <<~ADOC
137
+ :bibliography-database: #{bibliography_path}
138
+
139
+ ## Citations
140
+
141
+ cite:[Foo00]
142
+
143
+ cite:first[Qux00]
144
+
145
+ cite:first[Foo00]+last[Qux00]
146
+
147
+ ## Bibliographies
148
+
149
+ ### Default
150
+
151
+ bibliography::[]
152
+
153
+ ### First
154
+
155
+ bibliography::first[]
156
+
157
+ ### Last
158
+
159
+ bibliography::last[]
160
+ ADOC
161
+
162
+ expect { `asciidoctor -r asciidoctor-bibliography #{input_path} --trace` }.to_not raise_exception
163
+ expect(File.read(output_path)).to include <<~'BODY'
164
+ <div id="content">
165
+ <div class="sect1">
166
+ <h2 id="_citations">Citations</h2>
167
+ <div class="sectionbody">
168
+ <div class="paragraph">
169
+ <p>(<a href="#bibliography-default-Foo00">Bar, 2000</a>)</p>
170
+ </div>
171
+ <div class="paragraph">
172
+ <p>(<a href="#bibliography-first-Qux00">Zot, 3000</a>)</p>
173
+ </div>
174
+ <div class="paragraph">
175
+ <p>(<a href="#bibliography-first-Foo00">Bar, 2000</a>; <a href="#bibliography-last-Qux00">Zot, 3000</a>)</p>
176
+ </div>
177
+ </div>
178
+ </div>
179
+ <div class="sect1">
180
+ <h2 id="_bibliographies">Bibliographies</h2>
181
+ <div class="sectionbody">
182
+ <div class="sect2">
183
+ <h3 id="_default">Default</h3>
184
+ <div class="paragraph">
185
+ <p><a id="bibliography-default-Foo00"></a>Bar, F. (2000). Title.</p>
186
+ </div>
187
+ <div class="paragraph">
188
+ <p><a id="bibliography-default-Qux00"></a>Zot, Q. (3000). Title.</p>
189
+ </div>
190
+ </div>
191
+ <div class="sect2">
192
+ <h3 id="_first">First</h3>
193
+ <div class="paragraph">
194
+ <p><a id="bibliography-first-Foo00"></a>Bar, F. (2000). Title.</p>
195
+ </div>
196
+ <div class="paragraph">
197
+ <p><a id="bibliography-first-Qux00"></a>Zot, Q. (3000). Title.</p>
198
+ </div>
199
+ </div>
200
+ <div class="sect2">
201
+ <h3 id="_last">Last</h3>
202
+ <div class="paragraph">
203
+ <p><a id="bibliography-last-Foo00"></a>Bar, F. (2000). Title.</p>
204
+ </div>
205
+ <div class="paragraph">
206
+ <p><a id="bibliography-last-Qux00"></a>Zot, Q. (3000). Title.</p>
207
+ </div>
208
+ </div>
209
+ </div>
115
210
  </div>
116
211
  </div>
117
212
  BODY
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-bibliography
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.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-11-01 00:00:00.000000000 Z
11
+ date: 2019-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -258,6 +258,7 @@ files:
258
258
  - samples/standard/sample-din.html
259
259
  - samples/standard/sample-ieee.adoc
260
260
  - samples/standard/sample-ieee.html
261
+ - samples/standard/sample-targets.adoc
261
262
  - samples/tex/biblio.bib
262
263
  - samples/tex/sample-authoryear.adoc
263
264
  - samples/tex/sample-authoryear.html
@@ -319,8 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
319
320
  - !ruby/object:Gem::Version
320
321
  version: '0'
321
322
  requirements: []
322
- rubyforge_project:
323
- rubygems_version: 2.5.2
323
+ rubygems_version: 3.0.3
324
324
  signing_key:
325
325
  specification_version: 4
326
326
  summary: Citations and bibliography the "asciidoctor-way"