asciidoctor-foodogsquared-extensions 1.0.1 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ManInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
4
- use_dsl
5
-
6
- named :man
7
- name_positional_attributes 'volnum'
8
- default_attributes 'service' => 'debian'
9
-
10
- def process(parent, target, attrs)
11
- doc = parent.document
12
- text = manname = target
13
- suffix = (volnum = attrs['volnum']) ? %((#{volnum})) : ''
14
-
15
- if doc.basebackend? 'html'
16
- domain = case attrs['service']
17
- when 'debian'
18
- 'https://manpages.debian.org'
19
- when 'arch'
20
- 'https://man.archlinux.org/man'
21
- when 'opensuse'
22
- 'https://manpages.opensuse.org'
23
- when 'voidlinux'
24
- 'https://man.voidlinux.org'
25
- when 'none'
26
- nil
27
- else
28
- raise "no available manpage service #{attrs['service']}"
29
- end
30
-
31
- if !domain.nil?
32
- target = %(#{domain}/#{manname}.#{volnum})
33
- doc.register :links, target
34
- node = create_anchor parent, text, type: :link, target: target
35
- else
36
- node = create_inline parent, :quoted, manname
37
- end
38
- elsif doc.backend == 'manpage'
39
- node = create_inline parent, :quoted, manname, type: :strong
40
- else
41
- node = create_inline parent, :quoted, manname
42
- end
43
- create_inline parent, :quoted, %(#{node.convert}#{suffix})
44
- end
45
- end
@@ -1,45 +0,0 @@
1
- = Musicbrainz link inline macro
2
- :toc:
3
-
4
-
5
- An inline macro for easily linking objects from link:https://musicbrainz.org/doc/MusicBrainz_Database[Musicbrainz database].
6
-
7
-
8
- == Synopsis
9
-
10
- [source, asciidoc]
11
- ----
12
- musicbrainz:$ID[$CAPTION, $TYPE]
13
- ----
14
-
15
- - `$ID` is the database identifier for that object (e.g., `9adcff14-7dba-4ccf-a6a6-298bcde3dd46`).
16
-
17
- - `$CAPTION` is the link text.
18
- By default, it will be the name of the database object (if valid).
19
- Take note it will use the MusicBrainz API to query the title/name of the object.
20
- In other words, it costs an additional network request.
21
-
22
- - `$TYPE` is the database object type.
23
- It defaults to 'Release' object type.
24
-
25
-
26
- == Attributes
27
-
28
- The macro can also accept some attributes.
29
-
30
- - `caption` is the link text to be used.
31
- This can be used instead of the first positional attribute.
32
-
33
- - `type` is the database object type to be queried.
34
- This can be used instead of the second positional attribute.
35
-
36
-
37
- == Example usage
38
-
39
- - `musicbrainz:9adcff14-7dba-4ccf-a6a6-298bcde3dd46[]` should have a link to the link:https://musicbrainz.org/release/9adcff14-7dba-4ccf-a6a6-298bcde3dd46[Musicbrainz page for The Bindings of Isaac Rebirth] with 'The Bindings of Isaac: Rebirth' as the link caption.
40
-
41
- - `musicbrainz:9adcff14-7dba-4ccf-a6a6-298bcde3dd46[Ridiculon's Rebirth soundtrack]` same as above but with the link text replaced with 'Ridiculon's Rebirth Soundtrack'.
42
-
43
- - `musicbrainz:b7c7f603-4c42-45a4-b364-3ddba82da412[type=release-group]` links to the link:https://musicbrainz.org/release-group/b7c7f603-4c42-45a4-b364-3ddba82da412[Musicbrainz page for The Bindings of Isaac Rebirth release group] with 'The Bindings of Isaac: Rebirth' as the link text.
44
-
45
- - `musicbrainz:f07c6afe-ee84-4cd5-9b11-5c541d1dff3b[type=artist]` links to link:https://musicbrainz.org/artist/f07c6afe-ee84-4cd5-9b11-5c541d1dff3b[Musicbrainz page for Ridiculon] with their name as the caption.
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
- require 'open-uri'
5
- require 'uri'
6
-
7
- class MusicBrainzLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
8
- use_dsl
9
-
10
- named :musicbrainz
11
- name_positional_attributes 'caption', 'type'
12
- default_attributes 'type' => 'release'
13
-
14
- def process(parent, target, attrs)
15
- doc = parent.document
16
- root_endpoint = 'https://musicbrainz.org/ws/2'
17
-
18
- begin
19
- headers = {
20
- 'Accept' => 'application/json',
21
- 'User-Agent' => ::Asciidoctor::FoodogsquaredCustomExtensions::USER_AGENT
22
- }
23
-
24
- uri = %(#{root_endpoint}/#{attrs['type']}/#{target})
25
-
26
- if attrs['caption'].nil?
27
- metadata = OpenURI.open_uri(uri, headers) { |f| JSON.parse(f.read) }
28
- attrs['caption'] ||= case attrs['type']
29
- when 'artist', 'area', 'events', 'genre', 'instrument', 'label', 'place', 'series'
30
- metadata['name']
31
- when 'recording', 'release-group', 'release', 'cdstub', 'work'
32
- metadata['title']
33
- when 'url'
34
- metadata['resource']
35
- end
36
- end
37
-
38
- target = %(https://musicbrainz.org/#{attrs['type']}/#{target})
39
- doc.register :links, target
40
- create_anchor parent, attrs['caption'], type: :link, target: target
41
- rescue
42
- warning = %(error while getting Musicbrainz database object '#{target}: #{e}')
43
- warn_or_raise doc, warning
44
- reader.push_include warning, target, target, 1, attrs
45
- end
46
- end
47
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # I'm fairly sure this could be programmed since Ruby has nice metaprogramming
4
- # capabilities. Though, we'll be keeping it manually defining classes for now
5
- # for initial versions since there could be additional features for each macro.
6
-
7
- class CtanLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
8
- use_dsl
9
-
10
- named :ctan
11
- name_positional_attributes 'caption'
12
-
13
- def process(parent, target, attrs)
14
- doc = parent.document
15
- text = attrs['caption'] || target
16
- url = %(https://ctan.org/pkg/#{target})
17
-
18
- doc.register :links, url
19
-
20
- create_anchor parent, text, type: :link, target: url
21
- end
22
- end
23
-
24
- class PypiLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
25
- use_dsl
26
-
27
- named :pypi
28
- name_positional_attributes 'caption'
29
-
30
- def process(parent, target, attrs)
31
- doc = parent.document
32
- text = attrs['caption'] || target
33
- url = %(https://pypi.org/project/#{target})
34
-
35
- doc.register :links, url
36
-
37
- create_anchor parent, text, type: :link, target: url
38
- end
39
- end
40
-
41
- class CratesIOLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
42
- use_dsl
43
-
44
- named :cratesio
45
- name_positional_attributes 'caption'
46
-
47
- def process(parent, target, attrs)
48
- doc = parent.document
49
- text = attrs['caption'] || target
50
- url = %(https://crates.io/crates/#{target})
51
-
52
- doc.register :links, url
53
-
54
- create_anchor parent, text, type: :link, target: url
55
- end
56
- end
@@ -1,27 +0,0 @@
1
- = Repology link inline macro
2
- :toc:
3
-
4
-
5
- An inline macro for shorthands Repology links.
6
-
7
-
8
- == Synopsis
9
-
10
- [source, asciidoc]
11
- ----
12
- repology:$PROJECT[$CAPTION]
13
- ----
14
-
15
- Where...
16
-
17
- - `$PROJECT` is the project name listed in link:https://repology.org/projects/[Repology's project list].
18
-
19
- - `$CAPTION` is the link text to be used.
20
- By default, it will use the project name.
21
-
22
-
23
- == Example usage
24
-
25
- - `repology:beets[]` should link to the link:https://repology.org/project/beets/[Beets project page in Repology] with `beets` as the link text.
26
-
27
- - `repology:beets[widely available in Linux distributions]` is the same as the previous item but with the link text replaced to `widely available in Linux distributions`.
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class RepologyLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
4
- use_dsl
5
-
6
- named :repology
7
- name_positional_attributes 'caption'
8
-
9
- def process(parent, target, attrs)
10
- doc = parent.document
11
- text = attrs['caption'] || target
12
- url = %(https://repology.org/project/#{target})
13
-
14
- doc.register :links, url
15
-
16
- create_anchor parent, text, type: :link, target: url
17
- end
18
- end
@@ -1,44 +0,0 @@
1
- = SWHID include processor
2
- :toc:
3
-
4
-
5
- This is an include processor extension for easily fetching SWHIDs, only with the `cnt` schema type.
6
-
7
-
8
- == Synopsis
9
-
10
- [source, asciidoc]
11
- ----
12
- \include::$SWHID[]
13
- ----
14
-
15
- Where `$SWHID` is a link:https://docs.softwareheritage.org/devel/swh-model/persistent-identifiers.html[SWHID].
16
- This could accept SWHIDs with qualifiers.
17
-
18
- Take note this include processor will only give the raw content with the `cnt` schema type.
19
- Anything else will be skipped and log a warning instead.
20
-
21
-
22
-
23
- == Extra notes
24
-
25
- [source, asciidoc]
26
- ----
27
- = doctitle
28
- :swhid-gpl3: swh:1:cnt:94a9ed024d3859793618152ea559a168bbcbb5e2
29
-
30
- \include::{swhid-nixpkgs}[]
31
- ----
32
-
33
- This include processor also respects the safe mode setting.
34
- This means in order to permit including by SWHID, you have to permit link:https://docs.asciidoctor.org/asciidoc/latest/directives/include-uri/[includes by URIs].
35
-
36
- Lastly, this include processor uses the Software Heritage API which includes a limitation.
37
- You could create authorized requests by setting `SWH_API_BEARER_TOKEN` environment variable with a token.
38
-
39
-
40
- == Example usage
41
-
42
- - SWHID with a bare core identifier: `include::swh:1:cnt:94a9ed024d3859793618152ea559a168bbcbb5e2[]`.
43
-
44
- - SWHID with full contextual information: `include::swh:1:cnt:4c6ad635164b25b9bc2ebe17d2c3b7c0835f6035;origin=https://github.com/NixOS/nixpkgs;visit=swh:1:snp:6ea7d28dfd4789609e0be2b64179fc9c12931beb;anchor=swh:1:rev:7f5639fa3b68054ca0b062866dc62b22c3f11505;path=/README.md`.
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
- require 'open-uri'
5
- require 'uri'
6
-
7
- class SWHIDIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
8
- def handles?(target)
9
- target.start_with? 'swh:'
10
- end
11
-
12
- def process(doc, reader, target, attributes)
13
- swhid = target
14
- swhid_core_identifier = swhid.split(';').at(0)
15
- swhid_object_type = (swhid_core_identifier.split ':').at 2
16
-
17
- unless (doc.safe <= Asciidoctor::SafeMode::SERVER) && (doc.attr? 'allow-uri-read')
18
- raise %('swh:' include cannot be used in safe mode level > SERVER and without attribute 'allow-uri-read')
19
- end
20
-
21
- # We're already going to throw out anything that is not content object type
22
- # just to make the later pipelines easier to construct.
23
- if swhid_object_type != 'cnt'
24
- warn %(SWHID '#{swhid_core_identifier}' is not of 'cnt' type; ignoring)
25
- return reader
26
- end
27
-
28
- version = '1'
29
-
30
- content = begin
31
- uri = URI.parse %(https://archive.softwareheritage.org/api/#{version}/resolve/#{target}/)
32
-
33
- headers = {
34
- 'Accept' => 'application/json'
35
- }
36
-
37
- headers['Authorization'] = "Bearer #{ENV['SWH_API_BEARER_TOKEN']}" if ENV['SWH_API_BEARER_TOKEN']
38
-
39
- metadata = OpenURI.open_uri(uri, headers) { |f| JSON.parse(f.read) }
40
- object_hash = metadata['object_id']
41
-
42
- uri = URI.parse %(https://archive.softwareheritage.org/api/#{version}/content/sha1_git:#{object_hash}/raw/)
43
- OpenURI.open_uri(uri, headers, &:read)
44
- rescue OpenURI::HTTPError => e
45
- warning = %(error while getting '#{swhid_core_identifier}': #{e})
46
- warn warning
47
- warning
48
- end
49
-
50
- reader.push_include content, target, target, 1, attributes
51
- reader
52
- end
53
- end
@@ -1,54 +0,0 @@
1
- = SWHID inline macro extension
2
- :toc:
3
-
4
-
5
- An inline macro for easily linking link:https://docs.softwareheritage.org/devel/swh-model/persistent-identifiers.html[SWHIDs].
6
-
7
-
8
- == Synopsis
9
-
10
- [source, asciidoc]
11
- ----
12
- swh:$SWHID[$CAPTION]
13
- ----
14
-
15
- If no caption is given, the link text will be the core identifier of the SWHID.
16
-
17
-
18
- == Attributes
19
-
20
- You can configure certain behavior of the macro with the link:https://docs.asciidoctor.org/asciidoc/latest/attributes/options/[options attribute].
21
- Here's a list of them...
22
-
23
- - `full` will make the entire SWHID as the default link text.
24
-
25
-
26
- == Extra notes
27
-
28
- You would use like in the following form `swh:swh:1:snp:6ea7d28dfd4789609e0be2b64179fc9c12931beb[]` but you could also cut off `swh:` from the SWHID if you want to (i.e., `swh:1:snp:6ea7d28dfd4789609e0be2b64179fc9c12931beb[]`) to make it aesthetically pleasing.
29
-
30
- Whatever your preference is, the best practice for dealing with linking SWHIDs with this macro is setting attributes containing the SWHIDs.
31
-
32
- [source, asciidoc]
33
- ----
34
- = doctitle
35
- :swhid-nixpkgs: swh:1:dir:2885ecf76632a83610d8e95f0eb3383109a7c90a
36
-
37
- {swhid-nixpkgs}[this revision of nixpkgs]
38
- or
39
- swh:{swhid-nixpkgs}[that revision of nixpkgs]
40
- ----
41
-
42
-
43
- == Example usage
44
-
45
- This should work with the following types of SWHIDs.
46
-
47
- - A SWHID with only the core identifier: `swh:1:snp:6ea7d28dfd4789609e0be2b64179fc9c12931beb[]`.
48
-
49
- - A SWHID with only one qualifier with a link caption: `swh:1:cnt:ce4dd1988d2d5dfcec48252757a6fea94339ac38;lines=3-4[some code text]`
50
-
51
- - A SWHID with full contextual information.
52
- This is as depicted from the recommended practice for writings (i.e., blog posts, technical documentation, research papers) when referring to one of the objects in the archive.
53
- +
54
- `swh:1:dir:2885ecf76632a83610d8e95f0eb3383109a7c90a;origin=https://github.com/NixOS/nixpkgs;visit=swh:1:snp:6ea7d28dfd4789609e0be2b64179fc9c12931beb;anchor=swh:1:rev:b7ee21d0ced814d07b7d5aca334dfe018ceafaa5[]`
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class SWHInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
4
- use_dsl
5
-
6
- named :swh
7
- name_positional_attributes 'caption'
8
-
9
- def process(parent, target, attrs)
10
- doc = parent.document
11
-
12
- # We're only considering `swh:` starting with the scheme version. Also, it
13
- # looks nice aesthetically.
14
- swhid = target.start_with?('swh:') ? target : %(swh:#{target})
15
- default_caption = if attrs.key? 'full-option'
16
- swhid
17
- else
18
- swhid.split(';').at(0)
19
- end
20
- text = attrs['caption'] || default_caption
21
- target = %(https://archive.softwareheritage.org/#{swhid})
22
-
23
- doc.register :links, target
24
- create_anchor parent, text, type: :link, target: target
25
- end
26
- end
@@ -1,30 +0,0 @@
1
- = Wikipedia inline macro
2
- :toc:
3
-
4
-
5
- An inline macro for easily creating Wikipedia links (i.e., `wikipedia.org`).
6
-
7
-
8
- == Synopsis
9
-
10
- [source, asciidoc]
11
- ----
12
- wikipedia:PAGE[$CAPTION]
13
- ----
14
-
15
- Where if `$CAPTION` is present, it will be used as the link text.
16
- Otherwise, it will just be the page.
17
-
18
-
19
- == Attributes
20
-
21
- - `lang` is the language domain to be linked into.
22
- By default, it is set to `en`.
23
-
24
-
25
- == Example usage
26
-
27
- - `wikipedia:Diff[]` should link to the link:https://en.wikipedia.org/wiki/Diff[Diff page on English Wikipedia].
28
- - `wikipedia:Diff[lang=ja]` should link to the link:https://ja.wikipedia.org/wiki/Diff[Diff page on Japanese Wikipedia].
29
- - `wikipedia:Photosynthesis[lang=simple]` should link to the link:https://simple.wikipedia.org/wiki/Photosynthesis[Photosynthesis page on Simple English Wikipedia].
30
- - `wikipedia:Diff[diff in Japanese Wikipedia, lang=ja]` should link to the link:https://ja.wikipedia.org/wiki/Diff[Diff page on Japanese Wikipedia] with the `diff in Japanese Wikipedia` as the link text.
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'uri'
4
-
5
- class WikipediaInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
6
- use_dsl
7
-
8
- named :wikipedia
9
- name_positional_attributes 'caption'
10
- default_attributes 'lang' => 'en'
11
-
12
- def process(parent, target, attrs)
13
- caption = attrs['caption'] || target
14
- parser = URI::Parser.new
15
- page = parser.escape target
16
- link = %(https://#{attrs['lang']}.wikipedia.org/wiki/#{page})
17
- node = create_anchor parent, caption, type: :link, target: link
18
-
19
- create_inline parent, :quoted, node.convert
20
- end
21
- end