asciidoctor-lists 1.0.6 → 1.0.7

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
2
  SHA256:
3
- metadata.gz: b9cdb3021862916257b05b2690050744ccbd65af0a872e94b67b1b2c13df5391
4
- data.tar.gz: '059ab2fb1d8ce26edaa8768d98b9d8fea1e720e4212980a40127ab01bb0c8be3'
3
+ metadata.gz: ac525c818bc5254204312158fee82493102b5d61477c3d17e8f6d4a1b6049ebd
4
+ data.tar.gz: cc8dd13be8fbc15c04627733a0784c2963ddbad3689a2d180af25a15c2b1ef45
5
5
  SHA512:
6
- metadata.gz: e3e0da424fe5aa1c14338ee7bc92c3af8e088883494845381b9ef66e46447a962ad0397626aa50f6ee0f57b6410679ce76697dead5f9015d4c6337a9c463abf5
7
- data.tar.gz: 15770d886027bd2a790839a07993d35d7705472221decee9213e59feee2cd43fd58f5443098ff3bf0009cad06b06686388cdaa7d9eb6be2dd5afed23475b0427
6
+ metadata.gz: c6c3a5fd8b0ff322ad297070ed7796d758e4ad0c4d5efb1e285272f12b7b0b9323e90417852f3196aa700cdedb4ae9b5213192598b6f456c59bc55cc6ce4056c
7
+ data.tar.gz: 8677b62b1edbf1e6024f91422e6ca8670eff647258ac1ced4d8db03f3af9749685f5c1179da3cfbe7dcdf36598b4233ac1ee7b7a7ccfcce2ab1c6d0c39fb2f37
data/README.adoc CHANGED
@@ -8,7 +8,7 @@ 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
12
 
13
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.
14
14
 
@@ -41,15 +41,20 @@ image::img/sample.png[Sample,width=400]
41
41
 
42
42
  == Parameters
43
43
  === element
44
- Specifies the element which should be listed
44
+ Specifies the element to be listed
45
45
 
46
46
  Sample: link:samples/list-sample.adoc[]
47
47
 
48
48
  === enhanced_rendering (experimental)
49
- Allows to render links in the caption
49
+ Allows rendering links in the caption
50
50
 
51
51
  Sample: link:samples/enhanced-rendering.adoc[]
52
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
+
53
58
  == Docker
54
59
  [source,bash]
55
60
  ----
@@ -12,12 +12,14 @@ module AsciidoctorLists
12
12
  use_dsl
13
13
  named :"list-of"
14
14
  name_positional_attributes 'enhanced_rendering'
15
+ name_positional_attributes 'hide_empty_section'
15
16
 
16
17
  def process(parent, target, attrs)
17
18
  uuid = SecureRandom.uuid
18
19
  ListMacroAttributes[uuid] = {
19
20
  element: target,
20
- enhanced_rendering: attrs['enhanced_rendering']
21
+ enhanced_rendering: attrs['enhanced_rendering'],
22
+ hide_empty_section: attrs['hide_empty_section']
21
23
  }
22
24
  create_paragraph parent, uuid, {}
23
25
  end
@@ -36,28 +38,34 @@ module AsciidoctorLists
36
38
 
37
39
  params = ListMacroAttributes[block.lines[0]]
38
40
  enhanced_rendering = params[:enhanced_rendering]
41
+ hide_empty_section = params[:hide_empty_section]
39
42
 
40
- document.find_by(context: params[:element].to_sym).each do |element|
43
+ elements = document.find_by(context: params[:element].to_sym)
44
+ if elements.length > 0
45
+ elements.each do |element|
41
46
 
42
- if element.caption or element.title
43
- unless element.id
44
- element.id = SecureRandom.uuid
45
- end
47
+ if element.caption or element.title
48
+ unless element.id
49
+ element.id = SecureRandom.uuid
50
+ end
46
51
 
47
- if enhanced_rendering
48
- if element.caption
49
- references_asciidoc << %(xref:#{element.id}[#{element.caption}]#{element.instance_variable_get(:@title)} +)
50
- else element.caption
51
- 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}] +)
52
63
  end
53
- else
54
- if element.caption
55
- references_asciidoc << %(xref:#{element.id}[#{element.caption}]#{element.title} +)
56
- else element.caption
57
- references_asciidoc << %(xref:#{element.id}[#{element.title}] +)
58
64
  end
59
65
  end
60
66
  end
67
+ elsif hide_empty_section
68
+ block.parent.parent.blocks.delete block.parent
61
69
  end
62
70
 
63
71
  block_index = block.parent.blocks.index do |b|
@@ -1,3 +1,3 @@
1
1
  module AsciidoctorLists
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.7'
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.6
4
+ version: 1.0.7
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-17 00:00:00.000000000 Z
11
+ date: 2022-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor