asciidoctor-foodogsquared-extensions 1.0.1 → 1.2.1

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +52 -0
  3. data/asciidoctor-foodogsquared-extensions.gemspec +3 -1
  4. data/lib/asciidoctor/foodogsquared/converter.rb +31 -0
  5. data/lib/asciidoctor/foodogsquared/extensions/chat-block.rb +26 -0
  6. data/lib/asciidoctor/foodogsquared/extensions/fdroid-inline-macro.rb +28 -0
  7. data/lib/asciidoctor/foodogsquared/extensions/flathub-inline-macro.rb +35 -0
  8. data/lib/asciidoctor/foodogsquared/extensions/git-blob-include-processor.rb +68 -0
  9. data/lib/asciidoctor/foodogsquared/extensions/github-include-processor.rb +70 -0
  10. data/lib/asciidoctor/foodogsquared/extensions/github-inline-macro.rb +38 -0
  11. data/lib/asciidoctor/foodogsquared/extensions/gitlab-include-processor.rb +60 -0
  12. data/lib/asciidoctor/foodogsquared/extensions/gitlab-inline-macro.rb +39 -0
  13. data/lib/asciidoctor/foodogsquared/extensions/ietf-rfc-inline-macro.rb +18 -0
  14. data/lib/asciidoctor/foodogsquared/extensions/man-inline-macro.rb +54 -0
  15. data/lib/asciidoctor/foodogsquared/extensions/musicbrainz-inline-macro.rb +47 -0
  16. data/lib/asciidoctor/foodogsquared/extensions/package-indices-macro.rb +58 -0
  17. data/lib/asciidoctor/foodogsquared/extensions/repology-inline-macro.rb +20 -0
  18. data/lib/asciidoctor/foodogsquared/extensions/swhid-include-processor.rb +55 -0
  19. data/lib/asciidoctor/foodogsquared/extensions/swhid-inline-macro.rb +28 -0
  20. data/lib/asciidoctor/foodogsquared/extensions/wikipedia-inline-macro.rb +23 -0
  21. data/lib/asciidoctor/foodogsquared/extensions.rb +56 -0
  22. data/lib/asciidoctor/foodogsquared/helpers.rb +26 -0
  23. data/lib/asciidoctor-foodogsquared-extensions.rb +2 -1
  24. metadata +35 -35
  25. data/lib/asciidoctor/chat-block-processor/README.adoc +0 -115
  26. data/lib/asciidoctor/chat-block-processor/extension.rb +0 -57
  27. data/lib/asciidoctor/fdroid-link-inline-macro/README.adoc +0 -36
  28. data/lib/asciidoctor/fdroid-link-inline-macro/extension.rb +0 -28
  29. data/lib/asciidoctor/flathub-link-inline-macro/README.adoc +0 -28
  30. data/lib/asciidoctor/flathub-link-inline-macro/extension.rb +0 -35
  31. data/lib/asciidoctor/foodogsquared-extensions.rb +0 -56
  32. data/lib/asciidoctor/git-blob-include-processor/README.adoc +0 -68
  33. data/lib/asciidoctor/git-blob-include-processor/extension.rb +0 -79
  34. data/lib/asciidoctor/github-link-inline-macro/README.adoc +0 -49
  35. data/lib/asciidoctor/github-link-inline-macro/extension.rb +0 -36
  36. data/lib/asciidoctor/github-raw-content-include-processor/README.adoc +0 -40
  37. data/lib/asciidoctor/github-raw-content-include-processor/extension.rb +0 -68
  38. data/lib/asciidoctor/gitlab-link-inline-macro/README.adoc +0 -37
  39. data/lib/asciidoctor/gitlab-link-inline-macro/extension.rb +0 -31
  40. data/lib/asciidoctor/gitlab-raw-content-include-processor/README.adoc +0 -44
  41. data/lib/asciidoctor/gitlab-raw-content-include-processor/extension.rb +0 -66
  42. data/lib/asciidoctor/helpers.rb +0 -20
  43. data/lib/asciidoctor/ietf-rfc-link-inline-macro/README.adoc +0 -27
  44. data/lib/asciidoctor/ietf-rfc-link-inline-macro/extension.rb +0 -16
  45. data/lib/asciidoctor/man-inline-macro/README.adoc +0 -51
  46. data/lib/asciidoctor/man-inline-macro/extension.rb +0 -45
  47. data/lib/asciidoctor/musicbrainz-link-inline-macro/README.adoc +0 -45
  48. data/lib/asciidoctor/musicbrainz-link-inline-macro/extension.rb +0 -47
  49. data/lib/asciidoctor/package-indices-link-macro/extension.rb +0 -56
  50. data/lib/asciidoctor/repology-link-inline-macro/README.adoc +0 -27
  51. data/lib/asciidoctor/repology-link-inline-macro/extension.rb +0 -18
  52. data/lib/asciidoctor/swhid-include-processor/README.adoc +0 -44
  53. data/lib/asciidoctor/swhid-include-processor/extension.rb +0 -53
  54. data/lib/asciidoctor/swhid-inline-macro/README.adoc +0 -54
  55. data/lib/asciidoctor/swhid-inline-macro/extension.rb +0 -26
  56. data/lib/asciidoctor/wikipedia-inline-macro/README.adoc +0 -30
  57. data/lib/asciidoctor/wikipedia-inline-macro/extension.rb +0 -21
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Asciidoctor::Foodogsquared::Extensions
4
+ class RepologyInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
5
+ use_dsl
6
+
7
+ named :repology
8
+ name_positional_attributes 'caption'
9
+
10
+ def process(parent, target, attrs)
11
+ doc = parent.document
12
+ text = attrs['caption'] || target
13
+ url = %(https://repology.org/project/#{target})
14
+
15
+ doc.register :links, url
16
+
17
+ create_anchor parent, text, type: :link, target: url
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'open-uri'
5
+ require 'uri'
6
+
7
+ module Asciidoctor::Foodogsquared::Extensions
8
+ class SWHIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
9
+ def handles?(target)
10
+ target.start_with? 'swh:'
11
+ end
12
+
13
+ def process(doc, reader, target, attributes)
14
+ swhid = target
15
+ swhid_core_identifier = swhid.split(';').at(0)
16
+ swhid_object_type = (swhid_core_identifier.split ':').at 2
17
+
18
+ unless (doc.safe <= Asciidoctor::SafeMode::SERVER) && (doc.attr? 'allow-uri-read')
19
+ raise %('swh:' include cannot be used in safe mode level > SERVER and without attribute 'allow-uri-read')
20
+ end
21
+
22
+ # We're already going to throw out anything that is not content object type
23
+ # just to make the later pipelines easier to construct.
24
+ if swhid_object_type != 'cnt'
25
+ warn %(SWHID '#{swhid_core_identifier}' is not of 'cnt' type; ignoring)
26
+ return reader
27
+ end
28
+
29
+ version = '1'
30
+
31
+ content = begin
32
+ uri = URI.parse %(https://archive.softwareheritage.org/api/#{version}/resolve/#{target}/)
33
+
34
+ headers = {
35
+ 'Accept' => 'application/json'
36
+ }
37
+
38
+ headers['Authorization'] = "Bearer #{ENV['SWH_API_BEARER_TOKEN']}" if ENV['SWH_API_BEARER_TOKEN']
39
+
40
+ metadata = OpenURI.open_uri(uri, headers) { |f| JSON.parse(f.read) }
41
+ object_hash = metadata['object_id']
42
+
43
+ uri = URI.parse %(https://archive.softwareheritage.org/api/#{version}/content/sha1_git:#{object_hash}/raw/)
44
+ OpenURI.open_uri(uri, headers, &:read)
45
+ rescue OpenURI::HTTPError => e
46
+ warning = %(error while getting '#{swhid_core_identifier}': #{e})
47
+ warn warning
48
+ warning
49
+ end
50
+
51
+ reader.push_include content, target, target, 1, attributes
52
+ reader
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Asciidoctor::Foodogsquared::Extensions
4
+ class SWHInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
5
+ use_dsl
6
+
7
+ named :swh
8
+ name_positional_attributes 'caption'
9
+
10
+ def process(parent, target, attrs)
11
+ doc = parent.document
12
+
13
+ # We're only considering `swh:` starting with the scheme version. Also, it
14
+ # looks nice aesthetically.
15
+ swhid = target.start_with?('swh:') ? target : %(swh:#{target})
16
+ default_caption = if attrs.key? 'full-option'
17
+ swhid
18
+ else
19
+ swhid.split(';').at(0)
20
+ end
21
+ text = attrs['caption'] || default_caption
22
+ target = %(https://archive.softwareheritage.org/#{swhid})
23
+
24
+ doc.register :links, target
25
+ create_anchor parent, text, type: :link, target: target
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+
5
+ module Asciidoctor::Foodogsquared::Extensions
6
+ class WikipediaInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
7
+ use_dsl
8
+
9
+ named :wikipedia
10
+ name_positional_attributes 'caption'
11
+ default_attributes 'lang' => 'en'
12
+
13
+ def process(parent, target, attrs)
14
+ caption = attrs['caption'] || target
15
+ parser = URI::Parser.new
16
+ page = parser.escape target
17
+ link = %(https://#{attrs['lang']}.wikipedia.org/wiki/#{page})
18
+ node = create_anchor parent, caption, type: :link, target: link
19
+
20
+ create_inline parent, :quoted, node.convert
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'asciidoctor'
4
+ require 'asciidoctor/extensions'
5
+
6
+ require_relative 'helpers'
7
+
8
+ require_relative 'extensions/man-inline-macro'
9
+ require_relative 'extensions/swhid-inline-macro'
10
+ require_relative 'extensions/swhid-include-processor'
11
+ require_relative 'extensions/github-inline-macro'
12
+ require_relative 'extensions/github-include-processor'
13
+ require_relative 'extensions/gitlab-inline-macro'
14
+ require_relative 'extensions/gitlab-include-processor'
15
+ require_relative 'extensions/chat-block'
16
+ require_relative 'extensions/git-blob-include-processor'
17
+ require_relative 'extensions/wikipedia-inline-macro'
18
+ require_relative 'extensions/package-indices-macro'
19
+ require_relative 'extensions/fdroid-inline-macro'
20
+ require_relative 'extensions/musicbrainz-inline-macro'
21
+ require_relative 'extensions/flathub-inline-macro'
22
+ require_relative 'extensions/repology-inline-macro'
23
+ require_relative 'extensions/ietf-rfc-inline-macro'
24
+
25
+ include Asciidoctor::Foodogsquared::Extensions
26
+ Asciidoctor::Extensions.register do
27
+ inline_macro ManInlineMacro
28
+ inline_macro IETFRFCInlineMacro
29
+ block ChatBlock if @document.basebackend? 'html'
30
+
31
+ inline_macro SWHInlineMacro
32
+ include_processor SWHIncludeProcessor
33
+
34
+ inline_macro GitHubInlineMacro
35
+ include_processor GitHubIncludeProcessor
36
+
37
+ inline_macro GitLabInlineMacro
38
+ include_processor GitLabIncludeProcessor
39
+
40
+ include_processor GitBlobIncludeProcessor
41
+
42
+ inline_macro WikipediaInlineMacro
43
+
44
+ # Package indices
45
+ inline_macro CtanInlineMacro
46
+ inline_macro PypiInlineMacro
47
+ inline_macro CratesIOInlineMacro
48
+
49
+ # App stores
50
+ inline_macro FDroidInlineMacro
51
+ inline_macro FlathubInlineMacro
52
+
53
+ # Databases
54
+ inline_macro MusicBrainzInlineMacro
55
+ inline_macro RepologyInlineMacro
56
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ def to_kebab
5
+ self.gsub(/\s+/, '-') # Replace all spaces with dashes.
6
+ .gsub(/[^a-zA-Z0-9-]/, '') # Remove all non-alphanumerical (and dashes) characters.
7
+ .gsub(/-+/, '-') # Reduce all dashes into only one.
8
+ .gsub(/^-|-+$/, '') # Remove all leading and trailing dashes.
9
+ .downcase
10
+ end
11
+ end
12
+
13
+ # The namespace for storing Asciidoctor. This is the entry point for the
14
+ # entirety of this project.
15
+ module Asciidoctor::Foodogsquared
16
+ NAME = 'asciidoctor-foodogsquared-custom-extensions'
17
+ VERSION = '1.2.1'
18
+ CONTACT_EMAIL = 'foodogsquared@foodogsquared.one'
19
+ USER_AGENT = "#{NAME}/#{VERSION} ( #{CONTACT_EMAIL} )".freeze
20
+
21
+ def warn_or_raise(doc, warning)
22
+ return raise warning if (doc.safe > Asciidoctor::SafeMode::SERVER) && !(doc.attr? 'allow-uri-read')
23
+
24
+ warn warning
25
+ end
26
+ end
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'asciidoctor/foodogsquared-extensions'
3
+ require 'asciidoctor/foodogsquared/extensions'
4
+ require 'asciidoctor/foodogsquared/converter'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-foodogsquared-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Arazas
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
41
55
  description: |2
42
56
  foo-dogsquared's set of Asciidoctor extensions as a Gem. This is where I
43
57
  implemented several pet features that will most likely never be a part of
@@ -52,39 +66,25 @@ files:
52
66
  - README.adoc
53
67
  - asciidoctor-foodogsquared-extensions.gemspec
54
68
  - lib/asciidoctor-foodogsquared-extensions.rb
55
- - lib/asciidoctor/chat-block-processor/README.adoc
56
- - lib/asciidoctor/chat-block-processor/extension.rb
57
- - lib/asciidoctor/fdroid-link-inline-macro/README.adoc
58
- - lib/asciidoctor/fdroid-link-inline-macro/extension.rb
59
- - lib/asciidoctor/flathub-link-inline-macro/README.adoc
60
- - lib/asciidoctor/flathub-link-inline-macro/extension.rb
61
- - lib/asciidoctor/foodogsquared-extensions.rb
62
- - lib/asciidoctor/git-blob-include-processor/README.adoc
63
- - lib/asciidoctor/git-blob-include-processor/extension.rb
64
- - lib/asciidoctor/github-link-inline-macro/README.adoc
65
- - lib/asciidoctor/github-link-inline-macro/extension.rb
66
- - lib/asciidoctor/github-raw-content-include-processor/README.adoc
67
- - lib/asciidoctor/github-raw-content-include-processor/extension.rb
68
- - lib/asciidoctor/gitlab-link-inline-macro/README.adoc
69
- - lib/asciidoctor/gitlab-link-inline-macro/extension.rb
70
- - lib/asciidoctor/gitlab-raw-content-include-processor/README.adoc
71
- - lib/asciidoctor/gitlab-raw-content-include-processor/extension.rb
72
- - lib/asciidoctor/helpers.rb
73
- - lib/asciidoctor/ietf-rfc-link-inline-macro/README.adoc
74
- - lib/asciidoctor/ietf-rfc-link-inline-macro/extension.rb
75
- - lib/asciidoctor/man-inline-macro/README.adoc
76
- - lib/asciidoctor/man-inline-macro/extension.rb
77
- - lib/asciidoctor/musicbrainz-link-inline-macro/README.adoc
78
- - lib/asciidoctor/musicbrainz-link-inline-macro/extension.rb
79
- - lib/asciidoctor/package-indices-link-macro/extension.rb
80
- - lib/asciidoctor/repology-link-inline-macro/README.adoc
81
- - lib/asciidoctor/repology-link-inline-macro/extension.rb
82
- - lib/asciidoctor/swhid-include-processor/README.adoc
83
- - lib/asciidoctor/swhid-include-processor/extension.rb
84
- - lib/asciidoctor/swhid-inline-macro/README.adoc
85
- - lib/asciidoctor/swhid-inline-macro/extension.rb
86
- - lib/asciidoctor/wikipedia-inline-macro/README.adoc
87
- - lib/asciidoctor/wikipedia-inline-macro/extension.rb
69
+ - lib/asciidoctor/foodogsquared/converter.rb
70
+ - lib/asciidoctor/foodogsquared/extensions.rb
71
+ - lib/asciidoctor/foodogsquared/extensions/chat-block.rb
72
+ - lib/asciidoctor/foodogsquared/extensions/fdroid-inline-macro.rb
73
+ - lib/asciidoctor/foodogsquared/extensions/flathub-inline-macro.rb
74
+ - lib/asciidoctor/foodogsquared/extensions/git-blob-include-processor.rb
75
+ - lib/asciidoctor/foodogsquared/extensions/github-include-processor.rb
76
+ - lib/asciidoctor/foodogsquared/extensions/github-inline-macro.rb
77
+ - lib/asciidoctor/foodogsquared/extensions/gitlab-include-processor.rb
78
+ - lib/asciidoctor/foodogsquared/extensions/gitlab-inline-macro.rb
79
+ - lib/asciidoctor/foodogsquared/extensions/ietf-rfc-inline-macro.rb
80
+ - lib/asciidoctor/foodogsquared/extensions/man-inline-macro.rb
81
+ - lib/asciidoctor/foodogsquared/extensions/musicbrainz-inline-macro.rb
82
+ - lib/asciidoctor/foodogsquared/extensions/package-indices-macro.rb
83
+ - lib/asciidoctor/foodogsquared/extensions/repology-inline-macro.rb
84
+ - lib/asciidoctor/foodogsquared/extensions/swhid-include-processor.rb
85
+ - lib/asciidoctor/foodogsquared/extensions/swhid-inline-macro.rb
86
+ - lib/asciidoctor/foodogsquared/extensions/wikipedia-inline-macro.rb
87
+ - lib/asciidoctor/foodogsquared/helpers.rb
88
88
  homepage:
89
89
  licenses:
90
90
  - MIT
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  requirements: []
108
- rubygems_version: 3.4.14
108
+ rubygems_version: 3.4.20
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: foo-dogsquared's custom Asciidoctor extensions
@@ -1,115 +0,0 @@
1
- = Chat block processor
2
- :toc:
3
-
4
-
5
- A link:https://docs.asciidoctor.org/asciidoctor/latest/extensions/block-processor/[block processor] that adds a a dialog box style to the block.
6
- Exclusive to the HTML backend.
7
-
8
-
9
- == Synopsis
10
-
11
- ....
12
- [chat, $AVATARNAME, $AVATARSTATE, $ATTRS...]
13
- ====
14
- $CONTENT
15
- ====
16
- ....
17
-
18
- The avatar name is the name of the folder to be retrieved from the `avatarsdir` attribute.
19
- The directory enforces a certain structure which can be seen in <<extra-notes>>.
20
-
21
- Both the avatar name and the state are to be converted to snake case (e.g., `El Pablo` to `el_pablo`) for the image path.
22
-
23
-
24
- == Attributes
25
-
26
- * `avatarsdir` is the folder containing the avatars' stickers.
27
- This is explained in detail from the <<extra-notes>> section.
28
-
29
- * `avatarstype` is similar to `icontype` attribute except this is used for the avatar stickers.
30
- The default value is `webp`.
31
-
32
- * `state` is the sticker to be retrieved from the avatars directory.
33
- It has a default value of `default`.
34
- You could also use this attribute instead of the `$AVATARSTATE` positional argument for whatever reason.
35
-
36
- * `name` is the canonical name of the avatar.
37
- This is used for titles and alts in the internal image block.
38
- By default, this is the same as the given avatar.
39
-
40
-
41
- [#extra-notes]
42
- == Extra notes
43
-
44
- This component has some prerequisites for this to fully work specifically with `avatarsdir` attribute that contains a list of avatars and their stickers.
45
- By default, this value is at the `avatars` subdirectory of the `iconsdir` attribute.
46
- It is recommended to set this value yourself.
47
- +
48
- --
49
- This enforces a certain structure where the root directory contains a list of folders representing the avatar with each of the folder containing stickers which represents their state.
50
- For example, here's what `avatarsdir` could contain following the expected structure.
51
-
52
- [source]
53
- ----
54
- ./static/icons/avatars/
55
- ├── ezran/
56
- │ ├── crisis.webp
57
- │ ├── default.webp
58
- │ ├── sad.webp
59
- │ └── shocked.webp
60
- └── foodogsquared/
61
- ├── crisis.webp
62
- ├── default.webp
63
- ├── sad.webp
64
- └── shocked.webp
65
- ----
66
- --
67
-
68
-
69
- == Example usage
70
-
71
- Let's assume `avatarsdir` is set to the `static/icons/avatars` with the following file structure.
72
-
73
- [source]
74
- ----
75
- ./static/icons/avatars/
76
- ├── ezran/
77
- │ ├── crisis.webp
78
- │ ├── default.webp
79
- │ ├── sad.webp
80
- │ └── shocked.webp
81
- ├── el-pablo/
82
- │ ├── crisis.webp
83
- │ ├── default.webp
84
- │ ├── ghastly.webp
85
- │ ├── melodramatic.webp
86
- │ ├── sad.webp
87
- │ └── shocked.webp
88
- └── foodogsquared/
89
- ├── crisis.webp
90
- ├── default.webp
91
- ├── sad.webp
92
- └── shocked.webp
93
- ----
94
-
95
- - The following block should get the default image for `foodogsquared` which is in `./static/icons/avatars/foodogsquared/default.webp`.
96
- +
97
- ....
98
- [chat, foodogsquared]
99
- ====
100
- Hello there!
101
- ====
102
- ....
103
-
104
- - The following block should contain El Pablo's melodramatic dialog state.
105
- Take note of the resulting path for the image which is in kebab-case.
106
- +
107
- ....
108
- [chat, El Pablo, state=melodramatic]
109
- ====
110
- What tragedy is happening here!
111
- I couldn't take it.
112
-
113
- __Please__.
114
- ====
115
- ....
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ChatBlock < Asciidoctor::Extensions::BlockProcessor
4
- use_dsl
5
-
6
- named :chat
7
- on_context :example
8
- name_positional_attributes 'avatar', 'state'
9
- default_attributes 'state' => 'default'
10
-
11
- def process(parent, reader, attrs)
12
- block = create_block parent, :pass, nil, attrs, content_model: :compound
13
- block.add_role('dialogblock')
14
-
15
- # You can think of this section as a pipeline constructing the HTML
16
- # component for this block. Specifically, we're building one component that
17
- # contains two output: the dialog image of our avatar and its content.
18
- attrs['name'] ||= attrs['avatar']
19
-
20
- block << (create_html_fragment block, %(
21
- <div role="figure" class="dialogblock dialogblock__box dialogblock__avatar--#{attrs['avatar']} #{attrs['role']}">
22
- <div class="dialogblock dialogblock__avatar">
23
- ))
24
-
25
- attrs['avatarsdir'] ||= File.expand_path('./avatars', attrs['iconsdir'])
26
- attrs['avatarstype'] ||= 'avif'
27
-
28
- avatar_sticker = "#{attrs['avatar'].to_kebab}/#{attrs['state'].to_kebab}.#{attrs['avatarstype']}"
29
- avatar_img_attrs = {
30
- 'target' => parent.image_uri(avatar_sticker, 'avatarsdir'),
31
- 'alt' => attrs['name']
32
- }
33
- avatar_imgblock = create_image_block block, avatar_img_attrs
34
-
35
- block << avatar_imgblock
36
- block << (create_html_fragment block, %(
37
- </div>
38
- <div class="dialogblock dialogblock__text">
39
- <small class="dialogblock dialogblock__avatar-name">#{attrs['name']}</small>
40
- ))
41
-
42
- parse_content block, reader
43
-
44
- block << (create_html_fragment block, %(
45
- </div>
46
- </div>
47
- ))
48
-
49
- block
50
- end
51
-
52
- private
53
-
54
- def create_html_fragment(parent, html, attributes = nil)
55
- create_block parent, :pass, html, attributes
56
- end
57
- end
@@ -1,36 +0,0 @@
1
- = F-droid link inline macro
2
- :toc:
3
-
4
-
5
- An inline macro as a shorthand for F-droid links.
6
-
7
-
8
- == Synopsis
9
-
10
- [source, asciidoc]
11
- ----
12
- fdroid:$APP_ID[$CAPTION]
13
- ----
14
-
15
- Where...
16
-
17
- - `$APP_ID` is the application ID of the program (e.g., `org.moire.ultrasonic`).
18
-
19
- - `$CAPTION` is the link text.
20
- By default, it will use the display name of the application from its link:https://gitlab.com/fdroid/fdroiddata/[metadata repository].
21
- In other words, it will create an additional network request.
22
-
23
-
24
- == Attributes
25
-
26
- - `lang` is the language page to be linked.
27
- By default, it links to the English page of `en`.
28
-
29
-
30
- == Example usage
31
-
32
- - `fdroid:org.moire.ultrasonic[]` should link to the link:https://f-droid.org/en/packages/org.moire.ultrasonic/[F-Droid page for Ultrasonic] with the link text 'Ultrasonic'.
33
-
34
- - `fdroid:org.moire.ultrasonic[Hello there]` is the same as previous item but with the link text replaced with 'Hello there'.
35
-
36
- - `fdroid:org.moire.ultrasonic[lang=it]` is the same as the first list item but links to the link:https://f-droid.org/it/packages/org.moire.ultrasonic/[Italian page].
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'open-uri'
4
- require 'yaml'
5
-
6
- class FDroidLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
7
- use_dsl
8
-
9
- named :fdroid
10
- name_positional_attributes 'caption'
11
- default_attributes 'lang' => 'en'
12
-
13
- def process(parent, target, attrs)
14
- doc = parent.document
15
-
16
- app_id = target
17
- app_metadata_uri = %(https://gitlab.com/fdroid/fdroiddata/-/raw/master/metadata/#{app_id}.yml)
18
-
19
- if attrs['caption'].nil?
20
- metadata = OpenURI.open_uri(app_metadata_uri) { |f| YAML.safe_load(f.read) }
21
- attrs['caption'] = metadata['AutoName']
22
- end
23
-
24
- url = %(https://f-droid.org/#{attrs['lang']}/packages/#{app_id})
25
- doc.register :links, url
26
- create_anchor parent, attrs['caption'], type: :link, target: url
27
- end
28
- end
@@ -1,28 +0,0 @@
1
- = Flathub link inline macro
2
- :toc:
3
-
4
-
5
- A shorthand for linking applications from link:https://flathub.org[FlatHub].
6
-
7
-
8
- == Synopsis
9
-
10
- [source, asciidoc]
11
- ----
12
- flathub:$APP_ID[$CAPTION]
13
- ----
14
-
15
- Where...
16
-
17
- - `$APP_ID` is the application ID of the program on Flathub.
18
-
19
- - `$CAPTION` is the link text to be used.
20
- By default, it will get the appstream metadata from FlatHub and use the display name.
21
- Take note it creates an additional network request to get the name.
22
-
23
-
24
- == Example usage
25
-
26
- - `flathub:org.gnome.design.IconLibrary[]` links to the link:https://flathub.org/apps/org.gnome.design.IconLibrary[FlatHub page of GNOME Icon Library] with `Icon Library` as the link text.
27
-
28
- - `flathub:org.gnome.design.IconLibrary[GNOME Icon Library]` is the same as the previous list item but with its link text replaced with `GNOME Icon Library`.
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
- require 'open-uri'
5
-
6
- class FlathubLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
7
- use_dsl
8
-
9
- named :flathub
10
- name_positional_attributes 'caption'
11
-
12
- def process(parent, target, attrs)
13
- doc = parent.document
14
-
15
- # FlatHub API seems to have no documentation aside from the source code.
16
- # You can easily infer the API with its source code at
17
- # https://github.com/flathub/website.
18
- app_id = target
19
- app_metadata_uri = %(https://flathub.org/api/v2/appstream/#{app_id})
20
-
21
- headers = {
22
- 'Accept' => 'application/json',
23
- 'User-Agent' => ::Asciidoctor::FoodogsquaredCustomExtensions::USER_AGENT
24
- }
25
-
26
- if attrs['caption'].nil?
27
- metadata = OpenURI.open_uri(app_metadata_uri, headers) { |f| JSON.parse(f.read) }
28
- attrs['caption'] = metadata['name']
29
- end
30
-
31
- url = %(https://flathub.org/apps/#{app_id})
32
- doc.register :links, url
33
- create_anchor parent, attrs['caption'], type: :link, target: url
34
- end
35
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'asciidoctor'
4
- require 'asciidoctor/extensions'
5
-
6
- require_relative 'helpers'
7
-
8
- require_relative 'man-inline-macro/extension'
9
- require_relative 'swhid-inline-macro/extension'
10
- require_relative 'swhid-include-processor/extension'
11
- require_relative 'github-link-inline-macro/extension'
12
- require_relative 'github-raw-content-include-processor/extension'
13
- require_relative 'gitlab-link-inline-macro/extension'
14
- require_relative 'gitlab-raw-content-include-processor/extension'
15
- require_relative 'chat-block-processor/extension'
16
- require_relative 'git-blob-include-processor/extension'
17
- require_relative 'wikipedia-inline-macro/extension'
18
- require_relative 'package-indices-link-macro/extension'
19
- require_relative 'fdroid-link-inline-macro/extension'
20
- require_relative 'musicbrainz-link-inline-macro/extension'
21
- require_relative 'flathub-link-inline-macro/extension'
22
- require_relative 'repology-link-inline-macro/extension'
23
- require_relative 'ietf-rfc-link-inline-macro/extension'
24
-
25
- Asciidoctor::Extensions.register do
26
- inline_macro ManInlineMacro
27
- inline_macro IETFRFCLinkInlineMacro
28
- block ChatBlock if @document.basebackend? 'html'
29
-
30
- inline_macro SWHInlineMacro
31
- include_processor SWHIDIncludeProcessor
32
-
33
- inline_macro GitHubLinkInlineMacro
34
- include_processor GitHubRawIncludeProcessor
35
-
36
- inline_macro GitLabLinkInlineMacro
37
- include_processor GitLabRawIncludeProcessor
38
-
39
- include_processor GitBlobIncludeProcessor
40
- preprocessor GitContentBranchAttributePreprocessor
41
-
42
- inline_macro WikipediaInlineMacro
43
-
44
- # Package indices
45
- inline_macro CtanLinkInlineMacro
46
- inline_macro PypiLinkInlineMacro
47
- inline_macro CratesIOLinkInlineMacro
48
-
49
- # App stores
50
- inline_macro FDroidLinkInlineMacro
51
- inline_macro FlathubLinkInlineMacro
52
-
53
- # Databases
54
- inline_macro MusicBrainzLinkInlineMacro
55
- inline_macro RepologyLinkInlineMacro
56
- end