asciidoctor-lists 1.0.5 → 1.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91209fcab613ba19c6917659a8b528c0390f35f421e8dca23a39863710ee7fbd
4
- data.tar.gz: 55c77e4a5a78fe415605ea94ce08c29531f7ca9550797fba8c96ddc7b1cd3d35
3
+ metadata.gz: 4e4c385d098f83a5dc7c73e70afe4e09c1a414b5b8e6ceeb1c12aef78f47b372
4
+ data.tar.gz: 8536f12d37553f0c813719d69871c5073378b0aff7fdb973a26c72bd7fde6682
5
5
  SHA512:
6
- metadata.gz: 1c66ea906439d1a2720fa32187d55e4f4e701c4e78e989b4f602787fbb1c68f71447960286bc90f9519018b7e39c267f3f50a37bee8b012e9edd6c3babf52d37
7
- data.tar.gz: 7efe24289f4e643c5f6d424463b0ceeb4222d1e41cdd4508ad53b04cc72428feeefc77629ebd5ea93f851da892b7cec57c51348be8b1bd08918ee7bf5c1067d3
6
+ metadata.gz: 5c1d33f380081b1e4a7e28a64c45298df459e7ec8298a72baa9315beb3bb4088deda57bf76d31414b0e0432eade7ed56620417b11a29b35547da9446208a5931
7
+ data.tar.gz: 327515c647fb79c583011fc2271012a43ae502e5e9bd5919f2c89a647e1024041074ad20973512a74f9b74a602bef8fe2e4a2acff75f9d48880cabf109ae67fe
data/README.adoc CHANGED
@@ -8,7 +8,9 @@ image:https://img.shields.io/github/stars/Alwinator/asciidoctor-lists[Stars, lin
8
8
 
9
9
  An https://asciidoctor.org/[asciidoctor] extension that adds a list of figures, a list of tables, or a list of anything you want!
10
10
 
11
- *Pull Request are always welcome! :)*
11
+ *Pull Requests are always welcome! :)*
12
+
13
+ IMPORTANT: With version 1.0.6 the syntax was changed from `element_list::[element=image]` to `list-of::image[]` to make it more intuitive.
12
14
 
13
15
  == Install
14
16
  [source,asciidoc]
@@ -23,13 +25,13 @@ gem install asciidoctor-lists
23
25
  ...
24
26
 
25
27
  === List of figures
26
- element_list::[element=image]
28
+ list-of::image[]
27
29
 
28
30
  === List of tables
29
- element_list::[element=table]
31
+ list-of::table[]
30
32
 
31
33
  === List of code snippets
32
- element_list::[element=listing]
34
+ list-of::listing[]
33
35
  ----
34
36
 
35
37
  See link:samples/list-sample.adoc[]
@@ -39,15 +41,20 @@ image::img/sample.png[Sample,width=400]
39
41
 
40
42
  == Parameters
41
43
  === element
42
- Specifies the element which should be listed
44
+ Specifies the element to be listed
43
45
 
44
46
  Sample: link:samples/list-sample.adoc[]
45
47
 
46
48
  === enhanced_rendering (experimental)
47
- Allows to render links in the caption
49
+ Allows rendering links in the caption
48
50
 
49
51
  Sample: link:samples/enhanced-rendering.adoc[]
50
52
 
53
+ === hide_empty_section
54
+ Removes the section when no elements are found
55
+
56
+ Sample: link:samples/hide-if-empty-list-sample.adoc[]
57
+
51
58
  == Docker
52
59
  [source,bash]
53
60
  ----
@@ -72,3 +79,6 @@ asciidoctor -r ./lib/asciidoctor-lists.rb samples/list-sample.adoc
72
79
  gem build asciidoctor-lists.gemspec
73
80
  gem install asciidoctor-lists-x.x.x.gem
74
81
  ----
82
+
83
+ == Docker Image
84
+ - Support in official asciidoctor Docker image is waiting for approval (See https://github.com/asciidoctor/docker-asciidoctor/pull/262)
@@ -5,61 +5,67 @@ require 'securerandom'
5
5
  module AsciidoctorLists
6
6
  module Asciidoctor
7
7
 
8
- MacroPlaceholder = Hash.new
8
+ ListMacroAttributes = Hash.new
9
9
 
10
- # Replaces element_list::[element=...] with ListOfFiguresMacroPlaceholder
11
- class ListOfFiguresMacro < ::Asciidoctor::Extensions::BlockMacroProcessor
10
+ # Replaces list-of::element[] with UUID and saves attributes in ListMacroPlaceholder
11
+ class ListMacro < ::Asciidoctor::Extensions::BlockMacroProcessor
12
12
  use_dsl
13
- named :element_list
14
- name_positional_attributes 'element'
13
+ named :"list-of"
15
14
  name_positional_attributes 'enhanced_rendering'
15
+ name_positional_attributes 'hide_empty_section'
16
16
 
17
- def process(parent, _target, attrs)
17
+ def process(parent, target, attrs)
18
18
  uuid = SecureRandom.uuid
19
- MacroPlaceholder[uuid] = {
20
- element: attrs['element'],
21
- enhanced_rendering: attrs['enhanced_rendering']
19
+ ListMacroAttributes[uuid] = {
20
+ element: target,
21
+ enhanced_rendering: attrs['enhanced_rendering'],
22
+ hide_empty_section: attrs['hide_empty_section']
22
23
  }
23
24
  create_paragraph parent, uuid, {}
24
25
  end
25
26
  end
26
- # Searches for the figures and replaced ListOfFiguresMacroPlaceholder with the list of figures
27
+ # Searches for the elements and replaced the UUIDs with the lists
27
28
  # Inspired by https://github.com/asciidoctor/asciidoctor-bibtex/blob/master/lib/asciidoctor-bibtex/extensions.rb#L162
28
- class ListOfFiguresTreeprocessor < ::Asciidoctor::Extensions::Treeprocessor
29
+ class ListTreeprocessor < ::Asciidoctor::Extensions::Treeprocessor
29
30
  def process(document)
30
31
  tof_blocks = document.find_by do |b|
31
32
  # for fast search (since most searches shall fail)
32
33
  (b.content_model == :simple) && (b.lines.size == 1) \
33
- && (MacroPlaceholder.keys.include?(b.lines[0]))
34
+ && (ListMacroAttributes.keys.include?(b.lines[0]))
34
35
  end
35
36
  tof_blocks.each do |block|
36
37
  references_asciidoc = []
37
38
 
38
- params = MacroPlaceholder[block.lines[0]]
39
- element_name = ":" + params[:element]
39
+ params = ListMacroAttributes[block.lines[0]]
40
40
  enhanced_rendering = params[:enhanced_rendering]
41
+ hide_empty_section = params[:hide_empty_section]
41
42
 
42
- document.find_by(context: eval(element_name)).each do |element|
43
+ elements = document.find_by(traverse_documents: true, context: params[:element].to_sym)
44
+ if elements.length > 0
45
+ elements.each do |element|
43
46
 
44
- if element.caption or element.title
45
- unless element.id
46
- element.id = SecureRandom.uuid
47
- end
47
+ if element.caption or element.title
48
+ unless element.id
49
+ element.id = SecureRandom.uuid
50
+ end
48
51
 
49
- if enhanced_rendering
50
- if element.caption
51
- references_asciidoc << %(xref:#{element.id}[#{element.caption}]#{element.instance_variable_get(:@title)} +)
52
- else element.caption
53
- references_asciidoc << %(xref:#{element.id}[#{element.instance_variable_get(:@title)}] +)
52
+ if enhanced_rendering
53
+ if element.caption
54
+ references_asciidoc << %(xref:#{element.id}[#{element.caption}]#{element.instance_variable_get(:@title)} +)
55
+ else element.caption
56
+ references_asciidoc << %(xref:#{element.id}[#{element.instance_variable_get(:@title)}] +)
57
+ end
58
+ else
59
+ if element.caption
60
+ references_asciidoc << %(xref:#{element.id}[#{element.caption}]#{element.title} +)
61
+ else element.caption
62
+ references_asciidoc << %(xref:#{element.id}[#{element.title}] +)
54
63
  end
55
- else
56
- if element.caption
57
- references_asciidoc << %(xref:#{element.id}[#{element.caption}]#{element.title} +)
58
- else element.caption
59
- references_asciidoc << %(xref:#{element.id}[#{element.title}] +)
60
64
  end
61
65
  end
62
66
  end
67
+ elsif hide_empty_section
68
+ block.parent.parent.blocks.delete block.parent
63
69
  end
64
70
 
65
71
  block_index = block.parent.blocks.index do |b|
@@ -90,6 +96,6 @@ end
90
96
 
91
97
  # Register the extensions to asciidoctor
92
98
  Asciidoctor::Extensions.register do
93
- block_macro AsciidoctorLists::Asciidoctor::ListOfFiguresMacro
94
- tree_processor AsciidoctorLists::Asciidoctor::ListOfFiguresTreeprocessor
99
+ block_macro AsciidoctorLists::Asciidoctor::ListMacro
100
+ tree_processor AsciidoctorLists::Asciidoctor::ListTreeprocessor
95
101
  end
@@ -1,3 +1,3 @@
1
1
  module AsciidoctorLists
2
- VERSION = '1.0.5'
2
+ VERSION = '1.0.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-lists
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alwin Schuster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-16 00:00:00.000000000 Z
11
+ date: 2022-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor