asciidoctor-bibliography 0.8.0 → 0.9.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: 568b3aeefaaaf19618322048145162faeb1b9d41
4
- data.tar.gz: d87637a8e50c389f004fefa1022ad95d5a2eb405
2
+ SHA256:
3
+ metadata.gz: 712c0be34cc869f4b848ce77298e3244b9a82e13be4c7a9706c51644e58995b9
4
+ data.tar.gz: 8f4feb1dd4a372b1e160b8f0a1f265f09f4aca817a8b1bb9a467c71c8d36cba1
5
5
  SHA512:
6
- metadata.gz: fc4c7d5c15773821a9a0dded3dcda41d34072e3b7f645a683f7bef429dace26e5ec5009f4baceaa7e47d49051127dd9a683b38823efdb33f2beb8c3abbf0f40a
7
- data.tar.gz: 77b89168013c0a5d62a84f1a7a47b49741dc82cab82f740e76ba1665b0b0f6589480d59f2a37f54cc991f3de092950a5fac0e716d3e3d2f8c7e29f360609b1de
6
+ metadata.gz: 8342d233009659444f05076f35c226e61d246d05a9853c993ac73554f47ffb8ebe51ff7984cd53af6188dee2787096e3b1aed13275b2a64a57bc153a5dd7dd2b
7
+ data.tar.gz: 5bbe71d2c51f89f10aaa2de9a3bde81fb2c7a03ce286eca99b976f25fe9294e04c5b92541214beb4effffedc1010ffacbfbff65d4527e55fa97cc9820809b933
@@ -15,7 +15,8 @@ module AsciidoctorBibliography
15
15
  document.bibliographer.database =
16
16
  ::AsciidoctorBibliography::Database.new *expand_db_globs(document)
17
17
 
18
- processed_lines = process_lines reader.read_lines, document.bibliographer
18
+ lines = remove_comments(reader.read_lines)
19
+ processed_lines = process_lines lines, document.bibliographer
19
20
  reader.unshift_lines processed_lines
20
21
  reader
21
22
  end
@@ -31,6 +32,14 @@ module AsciidoctorBibliography
31
32
  render_indices lines, bibliographer
32
33
  end
33
34
 
35
+ def remove_comments(lines)
36
+ # Remove block comments
37
+ ls = lines.join("\n").split(/^\/\/\/\/\n/).
38
+ select.with_index { |_, i| i.even? }.join
39
+ # Remove line comments
40
+ ls.split("\n").reject { |line| line.start_with?("//") }
41
+ end
42
+
34
43
  def fetch_citations(lines, bibliographer)
35
44
  lines.join("\n").gsub(Citation::REGEXP) do
36
45
  citation = Citation.new(*Regexp.last_match.captures)
@@ -16,6 +16,11 @@ module AsciidoctorBibliography
16
16
 
17
17
  def add_citation(citation)
18
18
  citations << citation
19
+
20
+ # NOTE: Since we're rendering the whole (possibly composite) citation as missing - even if
21
+ # NOTE: a single key is nil - we add none of them to the occurring keys to be rendered in indices.
22
+ return if citation.any_missing_id?(self)
23
+
19
24
  citation.citation_items.group_by(&:target).each do |target, citation_items|
20
25
  @occurring_keys[target] ||= []
21
26
  @occurring_keys[target].concat(citation_items.map(&:key)).uniq!
@@ -14,6 +14,8 @@ module AsciidoctorBibliography
14
14
  REGEXP = /\\?(#{MACRO_NAME_REGEXP}):(?:(\S*?)?\[(|.*?[^\\])\])(?:\+(\S*?)?\[(|.*?[^\\])\])*/
15
15
  REF_ATTRIBUTES = %i[chapter page section clause].freeze
16
16
 
17
+ MISSING_ID_MARK = "*??*".freeze
18
+
17
19
  attr_reader :macro, :citation_items
18
20
 
19
21
  def initialize(macro, *target_and_attributes_list_pairs)
@@ -29,19 +31,41 @@ module AsciidoctorBibliography
29
31
  # rubocop:enable Performance/HashEachMethods
30
32
  end
31
33
 
34
+ def missing_ids(bibliographer)
35
+ m_ids = (@citation_items.map(&:key) - bibliographer.database.map { |entry| entry["id"] })
36
+ m_ids.map! { |id| id.nil? ? "" : id }
37
+ end
38
+
39
+ def any_missing_id?(bibliographer)
40
+ # NOTE: do not use :any? since it ignores nil
41
+ not missing_ids(bibliographer).empty?
42
+ end
43
+
32
44
  def render(bibliographer)
33
- formatted_citation =
34
- case macro
35
- when "cite"
36
- render_citation_with_csl(bibliographer)
37
- when "fullcite"
38
- render_fullcite_with_csl(bibliographer)
39
- when *TEX_MACROS
40
- render_texmacro_with_csl(bibliographer)
41
- end
45
+ # NOTE: If there is any blank key we must render the entire (possibly composite)
46
+ # NOTE: citation as missing, as we don't have that kind of control over CSL styles.
47
+ if any_missing_id?(bibliographer)
48
+ warn "Warning: I didn't find a database entry for #{missing_ids(bibliographer)}."
49
+ # TODO: It would be cool to have the title attribute show the missing keys
50
+ # TODO: as a popup above *??* but it does not work on inline quoted text.
51
+ return MISSING_ID_MARK
52
+ end
53
+
54
+ formatted_citation = render_with_csl(bibliographer)
42
55
  wrap_up_citation citation: formatted_citation, bibliographer: bibliographer
43
56
  end
44
57
 
58
+ def render_with_csl(bibliographer)
59
+ case macro
60
+ when "cite"
61
+ render_citation_with_csl(bibliographer)
62
+ when "fullcite"
63
+ render_fullcite_with_csl(bibliographer)
64
+ when *TEX_MACROS
65
+ render_texmacro_with_csl(bibliographer)
66
+ end
67
+ end
68
+
45
69
  def wrap_up_citation(citation:, bibliographer:)
46
70
  text = citation.dup
47
71
  # TODO: handle hyperlinks here, maybe?
@@ -49,9 +49,12 @@ module AsciidoctorBibliography
49
49
  end
50
50
 
51
51
  def prepare_filtered_db(bibliographer)
52
- bibliographer.occurring_keys[target].
53
- map { |id| bibliographer.database.find_entry_by_id(id) }.
54
- map { |entry| prepare_entry_metadata bibliographer, entry }
52
+ if bibliographer.occurring_keys.include? target
53
+ bibliographer.occurring_keys[target].
54
+ map { |id| bibliographer.database.find_entry_by_id(id) }.
55
+ map { |entry| prepare_entry_metadata bibliographer, entry }
56
+ else {}
57
+ end
55
58
  end
56
59
 
57
60
  def prepare_entry_metadata(bibliographer, entry)
@@ -1,3 +1,3 @@
1
1
  module AsciidoctorBibliography
2
- VERSION = "0.8.0".freeze
2
+ VERSION = "0.9.0".freeze
3
3
  end
@@ -0,0 +1,15 @@
1
+ # coding: utf-8
2
+
3
+ require_relative "citation_helper"
4
+
5
+ describe AsciidoctorBibliography::Index do
6
+ describe ".render" do
7
+ subject { described_class.new([], "default", "") }
8
+
9
+ it "does not fail when no citations occur in the document" do
10
+ options = { "bibliography-style" => "ieee", "bibliography-database" => "database.bibtex", "bibliography-passthrough" => "true", "bibliography-prepend-empty" => "false" }
11
+ bibliographer = init_bibliographer options: options
12
+ expect { subject.render bibliographer}.to_not raise_exception
13
+ end
14
+ end
15
+ end
data/spec/macros_spec.rb CHANGED
@@ -31,3 +31,13 @@ describe "fullcite macro with apa style" do
31
31
  to eq "Erdős, P., Heyting, A., & Brouwer, L. E. (1965). Some very hard sums. _Difficult Maths Today_, 30."
32
32
  end
33
33
  end
34
+
35
+ describe "cite macro using an unknown key" do
36
+ it "formats bold question marks" do
37
+ expect(formatted_citation("cite:[Erdos65]+[foobar]",
38
+ options: { "bibliography-style" => "apa",
39
+ "bibliography-database" => "database.bib",
40
+ "bibliography-hyperlinks" => "true" })).
41
+ to eq "*??*"
42
+ end
43
+ end
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.8.0
4
+ version: 0.9.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: 2018-04-07 00:00:00.000000000 Z
11
+ date: 2019-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -302,6 +302,7 @@ files:
302
302
  - spec/fixtures/database.bibtex
303
303
  - spec/fixtures/database.rfc.xml
304
304
  - spec/fixtures/database.unk
305
+ - spec/index_spec.rb
305
306
  - spec/macros_spec.rb
306
307
  - spec/options_spec.rb
307
308
  - spec/sanity_spec.rb
@@ -326,8 +327,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
326
327
  - !ruby/object:Gem::Version
327
328
  version: '0'
328
329
  requirements: []
329
- rubyforge_project:
330
- rubygems_version: 2.6.14
330
+ rubygems_version: 3.0.3
331
331
  signing_key:
332
332
  specification_version: 4
333
333
  summary: Citations and bibliography the "asciidoctor-way"