asciidoctor-lists 0.0.3 → 0.0.4

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: df21d7405e2bd61684ae02680874f92be4f0101a4cf270c27b64213326d43574
4
- data.tar.gz: 7bf4131455afd55c97435dcb824556a9e58fd29fba57a4adaf1451409a47e732
3
+ metadata.gz: 0eaca66a3f98bc4f707f3a74344f8c6dac71c8d67d4058cc5d2252a526d311cf
4
+ data.tar.gz: 4869f786e928690b0abdcbcd0f8b04817776de5ccc91db26a17c67ed782eac63
5
5
  SHA512:
6
- metadata.gz: 91ad039018f2c9efae5670dd242e92cd091885c4b00403320e588a79dab4ca5bd736becf8adbaf4ade4efb8deb49b5e5fd3add8eed3ad06cc81b54e9e01a4a16
7
- data.tar.gz: e2756b56f60d202d7e4cc7e595a8b4e4800228f5015ddf10a6a2a39122581d19214b8c5af5420c0268f14793ee6d9583a9de6bea6c5a65847692e17b5dff39ab
6
+ metadata.gz: 6693ed6dde5dea42bd91ddbb002f3e4885260af5dbb5ff4d5c9147660b2c3e03f153d3b227777ca01e4464a521f612797f43c60ae86323cc49cea3221fb8e838
7
+ data.tar.gz: bfcd636f140795aaba03d0a44df02a44c32d5a5906c35c668808cdc9422ff94e1c2cbb03abbb3f8659685840ae5f0602a19c3b7116021d9a37b24ce28b4d5764
data/README.adoc CHANGED
@@ -1,11 +1,12 @@
1
- = asciidoctor-lists (WIP)
1
+ = asciidoctor-lists
2
2
  :toc: macro
3
3
  :toclevels: 1
4
4
 
5
+ 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]
5
6
  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]
6
7
  image:https://img.shields.io/gem/v/asciidoctor-lists.svg[Latest Release, link=https://rubygems.org/gems/asciidoctor-lists]
7
8
 
8
- Adds a list of figures, list of tables (WIP) or list of anything you want!
9
+ An https://asciidoctor.org/[asciidoctor] extension which adds a list of figures, list of tables or list of anything you want!
9
10
 
10
11
  == Install
11
12
  [source,asciidoc]
@@ -17,41 +18,51 @@ gem install asciidoctor-lists
17
18
  === Code
18
19
  [source,asciidoc]
19
20
  ----
20
- == 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
+ |===
21
33
 
22
- .The wonderful linux logo
23
- image::https://upload.wikimedia.org/wikipedia/commons/3/35/Tux.svg[Linux Logo,100,100]
24
34
 
25
35
  .Another wikipedia SVG image
26
36
  image::https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/SVG_Logo.svg/400px-SVG_Logo.svg.png[SVG,100,100]
27
37
 
28
38
  === List of figures
39
+ element_list::[element=image]
29
40
 
30
- tof::[]
41
+ === List of tables
42
+ element_list::[element=table]
31
43
 
32
44
  ----
33
45
 
34
46
  === Rendered
35
- 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]
36
48
 
37
49
  == What is planned next?
38
50
  * Link between image/table/element and list
39
- * Make generic (Also allow list of tables, or list of x)
40
51
 
41
52
  == Docker
42
53
  [source,bash]
43
54
  ----
44
55
  # Build container
45
- docker build -t asciidoctor-lists .
56
+ docker build --no-cache -t asciidoctor-lists .
46
57
  # Run Docker
47
- docker run -it --rm -v $(pwd):/work asciidoctor-lists:latest
58
+ docker run -it --rm -v $(pwd):/work asciidoctor-lists
48
59
  # Build sample
49
- asciidoctor-pdf -r asciidoctor-lists samples/list-of-figures.adoc
60
+ asciidoctor-pdf -r asciidoctor-lists samples/list-sample.adoc
50
61
  ----
51
62
 
52
63
  == Dev setup
53
64
  [source,bash]
54
65
  ----
55
66
  gem build asciidoctor-lists.gemspec
56
- gem install asciidoctor-lists-0.0.2.gem
67
+ gem install asciidoctor-lists-x.x.x.gem
57
68
  ----
@@ -1,53 +1,43 @@
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
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
25
  def process document
38
- references_asciidoc = []
39
- document.find_by(context: :image).each do |image|
40
-
41
- if image.caption
42
- references_asciidoc << %(#{image.caption}#{image.title} +)
43
- end
44
- end
45
- tof_blocks = document.find_by do |b|
26
+ tof_blocks = document.find_by do |b|
46
27
  # for fast search (since most searches shall fail)
47
28
  (b.content_model == :simple) && (b.lines.size == 1) \
48
- && (b.lines[0] == ListOfFiguresMacroPlaceholder)
29
+ && (MacroPlaceholder.keys.include?(b.lines[0]))
49
30
  end
50
31
  tof_blocks.each do |block|
32
+ references_asciidoc = []
33
+ element_name = ":" + MacroPlaceholder[block.lines[0]][:element]
34
+ document.find_by(context: eval(element_name)).each do |element|
35
+
36
+ if element.caption
37
+ references_asciidoc << %(#{element.caption}#{element.title} +)
38
+ end
39
+ end
40
+
51
41
  block_index = block.parent.blocks.index do |b|
52
42
  b == block
53
43
  end
@@ -62,13 +52,13 @@ module AsciidoctorLists
62
52
  # where resultant blocks are returned as a list instead of attached to
63
53
  # the parent.
64
54
  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
55
+ result = []
56
+ reader = ::Asciidoctor::Reader.new content
57
+ while reader.has_more_lines?
58
+ block = ::Asciidoctor::Parser.next_block reader, parent, attributes
59
+ result << block if block
60
+ end
61
+ result
72
62
  end
73
63
  end
74
64
  end
@@ -1,3 +1,3 @@
1
1
  module AsciidoctorLists
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-lists
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alwin Schuster