asciidoctor-lists 0.0.1 → 1.0.0

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: 58e02dec63f52918b2ee0c8f5062d14eb451ef8c8847f07014e6d826c1c28a95
4
- data.tar.gz: cefa380ff2daf11a8bffd28c6e5e957a3ec95e16bdb619d3f514c5f9ce0fd212
3
+ metadata.gz: c74f8ace24bdf759b089f51c96bdd3e8762d89d8e57ab8ebfa383ba953f61df3
4
+ data.tar.gz: acc23cc76d994d3d1c52e07c452e708aab39fa48518e998a3caec94a29fb4646
5
5
  SHA512:
6
- metadata.gz: 5e96c24f4090ae29d3cfbaa9d95167bd8435a0510fcd3231b47cd822352a7fe603f933660eaa7b1aec12f8689f3217353b14d3e27ac566b40cc837e40ec9ca77
7
- data.tar.gz: ad010ae3a5c0803d4431c702e1cb02d825aa76253d903c50540455fa450ecb20cbbc546192de71c14973efbbbbe0a2f9849633664564e831ae828bc06699e201
6
+ metadata.gz: 7669ee5f782c0f0ac76a872733a762568e1587dc88a57b96f4aa338244211d4cf5073a2702dbd8c8309e3744dac906a742b17b56b3af33796a836e8b34fad9f7
7
+ data.tar.gz: 59128a63e22e7af55146a9e19e94e0e112deb00c24b303bcd9953c4b2f6e1fc06c25a33851407b41fae6aceb4e19df79c0cd54590206a512da9ee8f28e43bd7c
data/README.adoc CHANGED
@@ -1,41 +1,72 @@
1
- = asciidoctor-lists (WIP)
2
- :toc: macro
3
- :toclevels: 1
1
+ = asciidoctor-lists
4
2
 
3
+ image:https://github.com/Alwinator/asciidoctor-lists/actions/workflows/test.yml/badge.svg[Test, link=https://github.com/Alwinator/asciidoctor-lists/actions/workflows/test.yml]
4
+ image:https://github.com/Alwinator/asciidoctor-lists/actions/workflows/publish_gem.yml/badge.svg[Build, link=https://github.com/Alwinator/asciidoctor-lists/actions/workflows/publish_gem.yml]
5
5
  image:https://img.shields.io/gem/v/asciidoctor-lists.svg[Latest Release, link=https://rubygems.org/gems/asciidoctor-lists]
6
- Adds a list of figures, list of tables (WIP) or list of anything you want!
6
+
7
+ An https://asciidoctor.org/[asciidoctor] extension that adds a list of figures, a list of tables, or a list of anything you want!
8
+
9
+ *Pull Request are always welcome! :)*
7
10
 
8
11
  == Install
9
- WIP :)
12
+ [source,asciidoc]
13
+ ----
14
+ gem install asciidoctor-lists
15
+ ----
10
16
 
11
17
  == Sample
12
18
  === Code
13
19
  [source,asciidoc]
14
20
  ----
15
- == Test the List of Figures Macro
21
+ ...
22
+
23
+ .And this is the second one
24
+ |===
25
+ |Column 1, Header Row |Column 2, Header Row
26
+
27
+ |Cell in column 1, row 1
28
+ |Cell in column 2, row 1
29
+
30
+ |Cell in column 1, row 2
31
+ |Cell in column 2, row 2
32
+ |===
16
33
 
17
- .The wonderful linux logo
18
- image::https://upload.wikimedia.org/wikipedia/commons/3/35/Tux.svg[Linux Logo,100,100]
19
34
 
20
35
  .Another wikipedia SVG image
21
36
  image::https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/SVG_Logo.svg/400px-SVG_Logo.svg.png[SVG,100,100]
22
37
 
23
38
  === List of figures
39
+ element_list::[element=image]
24
40
 
25
- tof::[]
41
+ === List of tables
42
+ element_list::[element=table]
26
43
 
27
44
  ----
28
45
 
29
46
  === Rendered
30
- image::https://user-images.githubusercontent.com/39517491/139903592-84e9e6cd-c1a8-45ec-acb7-52f37e366ddc.png[Sample,width=400]
47
+ image::img/sample.png[Sample,width=400]
31
48
 
32
- == What is planned next?
33
- * Link between image/table/element and list
34
- * Make generic (Also allow list of tables, or list of x)
49
+ == Docker
50
+ [source,bash]
51
+ ----
52
+ # Build container
53
+ docker build -t asciidoctor-lists .
54
+ # Run Docker
55
+ docker run -it --rm -v $(pwd):/work asciidoctor-lists
56
+ # Build sample
57
+ asciidoctor-pdf -r asciidoctor-lists samples/list-sample.adoc
58
+ ----
35
59
 
36
60
  == Dev setup
61
+ === Run
62
+ [source,bash]
63
+ ----
64
+ asciidoctor -r ./lib/asciidoctor-lists.rb samples/list-sample.adoc
65
+ ----
66
+
67
+ === Install Gem
37
68
  [source,bash]
38
69
  ----
39
70
  gem build asciidoctor-lists.gemspec
40
- gem install asciidoctor-lists-0.0.1.gem
71
+ gem install asciidoctor-lists-x.x.x.gem
41
72
  ----
@@ -1,74 +1,65 @@
1
1
  require 'asciidoctor'
2
2
  require 'asciidoctor/extensions'
3
+ require 'securerandom'
3
4
 
4
5
  module AsciidoctorLists
5
6
  module Asciidoctor
6
- # An macro that adds a list of all figures
7
- # It only uses images that have a caption!
8
- #
9
- # Usage
10
- """
11
- == Test the List of Figures Macro
12
7
 
13
- .The wonderful linux logo
14
- image::https://upload.wikimedia.org/wikipedia/commons/3/35/Tux.svg[Linux Logo,100,100]
15
-
16
- .Another wikipedia SVG image
17
- image::https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/SVG_Logo.svg/400px-SVG_Logo.svg.png[SVG,100,100]
18
-
19
- === List of figures
20
-
21
- tof::[]
22
- """
23
- ListOfFiguresMacroPlaceholder = %(9d9711cf-0e95-4230-9973-78559fe928db)
8
+ MacroPlaceholder = Hash.new
24
9
 
25
10
  # Replaces tof::[] with ListOfFiguresMacroPlaceholder
26
- class ListOfFiguresMacro < ::Extensions::BlockMacroProcessor
11
+ class ListOfFiguresMacro < ::Asciidoctor::Extensions::BlockMacroProcessor
27
12
  use_dsl
28
- named :tof
13
+ named :element_list
14
+ name_positional_attributes 'element'
29
15
 
30
- def process(parent, target, attrs)
31
- create_paragraph parent, ListOfFiguresMacroPlaceholder, {}
16
+ def process(parent, _target, attrs)
17
+ uuid = SecureRandom.uuid
18
+ MacroPlaceholder[uuid] = {element: attrs['element']}
19
+ create_paragraph parent, uuid, {}
32
20
  end
33
21
  end
34
22
  # Searches for the figures and replaced ListOfFiguresMacroPlaceholder with the list of figures
35
23
  # Inspired by https://github.com/asciidoctor/asciidoctor-bibtex/blob/master/lib/asciidoctor-bibtex/extensions.rb#L162
36
24
  class ListOfFiguresTreeprocessor < ::Asciidoctor::Extensions::Treeprocessor
37
- def process document
25
+ def process(document)
26
+ tof_blocks = document.find_by do |b|
27
+ # for fast search (since most searches shall fail)
28
+ (b.content_model == :simple) && (b.lines.size == 1) \
29
+ && (MacroPlaceholder.keys.include?(b.lines[0]))
30
+ end
31
+ tof_blocks.each do |block|
38
32
  references_asciidoc = []
39
- document.find_by(context: :image).each do |image|
33
+ element_name = ":" + MacroPlaceholder[block.lines[0]][:element]
34
+ document.find_by(context: eval(element_name)).each do |element|
40
35
 
41
- if image.caption
42
- references_asciidoc << %(#{image.caption}#{image.title} +)
43
- end
44
- end
45
- tof_blocks = document.find_by do |b|
46
- # for fast search (since most searches shall fail)
47
- (b.content_model == :simple) && (b.lines.size == 1) \
48
- && (b.lines[0] == ListOfFiguresMacroPlaceholder)
49
- end
50
- tof_blocks.each do |block|
51
- block_index = block.parent.blocks.index do |b|
52
- b == block
53
- end
54
- reference_blocks = parse_asciidoc block.parent, references_asciidoc
55
- reference_blocks.reverse.each do |b|
56
- block.parent.blocks.insert block_index, b
57
- end
58
- block.parent.blocks.delete_at block_index + reference_blocks.size
59
- end
60
- end
36
+ if element.caption
37
+ element.id = SecureRandom.uuid
38
+ references_asciidoc << %(xref:#{element.id}[#{element.caption}]#{element.title} +)
39
+ end
40
+ end
41
+
42
+ block_index = block.parent.blocks.index do |b|
43
+ b == block
44
+ end
45
+ reference_blocks = parse_asciidoc block.parent, references_asciidoc
46
+ reference_blocks.reverse.each do |b|
47
+ block.parent.blocks.insert block_index, b
48
+ end
49
+ block.parent.blocks.delete_at block_index + reference_blocks.size
50
+ end
51
+ end
61
52
  # This is an adapted version of Asciidoctor::Extension::parse_content,
62
53
  # where resultant blocks are returned as a list instead of attached to
63
54
  # the parent.
64
55
  def parse_asciidoc(parent, content, attributes = {})
65
- result = []
66
- reader = ::Asciidoctor::Reader.new content
67
- while reader.has_more_lines?
68
- block = ::Asciidoctor::Parser.next_block reader, parent, attributes
69
- result << block if block
70
- end
71
- result
56
+ result = []
57
+ reader = ::Asciidoctor::Reader.new content
58
+ while reader.has_more_lines?
59
+ block = ::Asciidoctor::Parser.next_block reader, parent, attributes
60
+ result << block if block
61
+ end
62
+ result
72
63
  end
73
64
  end
74
65
  end
@@ -1,3 +1,3 @@
1
1
  module AsciidoctorLists
2
- VERSION = '0.0.1'
2
+ VERSION = '1.0.0'
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: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alwin Schuster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-03 00:00:00.000000000 Z
11
+ date: 2021-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  requirements: []
56
- rubygems_version: 3.2.5
56
+ rubygems_version: 3.1.2
57
57
  signing_key:
58
58
  specification_version: 4
59
59
  summary: An Asciidoctor extension that adds bibtex integration to AsciiDoc