asciidoctor-foodogsquared-extensions 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.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/asciidoctor-foodogsquared-extensions.gemspec +22 -0
  3. data/lib/asciidoctor/chat-block-processor/README.adoc +115 -0
  4. data/lib/asciidoctor/chat-block-processor/extension.rb +56 -0
  5. data/lib/asciidoctor/fdroid-link-inline-macro/README.adoc +36 -0
  6. data/lib/asciidoctor/fdroid-link-inline-macro/extension.rb +28 -0
  7. data/lib/asciidoctor/flathub-link-inline-macro/README.adoc +28 -0
  8. data/lib/asciidoctor/flathub-link-inline-macro/extension.rb +35 -0
  9. data/lib/asciidoctor/foodogsquared-extensions.rb +56 -0
  10. data/lib/asciidoctor/git-blob-include-processor/README.adoc +68 -0
  11. data/lib/asciidoctor/git-blob-include-processor/extension.rb +79 -0
  12. data/lib/asciidoctor/github-link-inline-macro/README.adoc +49 -0
  13. data/lib/asciidoctor/github-link-inline-macro/extension.rb +36 -0
  14. data/lib/asciidoctor/github-raw-content-include-processor/README.adoc +40 -0
  15. data/lib/asciidoctor/github-raw-content-include-processor/extension.rb +68 -0
  16. data/lib/asciidoctor/gitlab-link-inline-macro/README.adoc +37 -0
  17. data/lib/asciidoctor/gitlab-link-inline-macro/extension.rb +31 -0
  18. data/lib/asciidoctor/gitlab-raw-content-include-processor/README.adoc +44 -0
  19. data/lib/asciidoctor/gitlab-raw-content-include-processor/extension.rb +66 -0
  20. data/lib/asciidoctor/helpers.rb +20 -0
  21. data/lib/asciidoctor/ietf-rfc-link-inline-macro/README.adoc +27 -0
  22. data/lib/asciidoctor/ietf-rfc-link-inline-macro/extension.rb +16 -0
  23. data/lib/asciidoctor/man-inline-macro/README.adoc +51 -0
  24. data/lib/asciidoctor/man-inline-macro/extension.rb +45 -0
  25. data/lib/asciidoctor/musicbrainz-link-inline-macro/README.adoc +45 -0
  26. data/lib/asciidoctor/musicbrainz-link-inline-macro/extension.rb +47 -0
  27. data/lib/asciidoctor/package-indices-link-macro/extension.rb +56 -0
  28. data/lib/asciidoctor/repology-link-inline-macro/README.adoc +27 -0
  29. data/lib/asciidoctor/repology-link-inline-macro/extension.rb +18 -0
  30. data/lib/asciidoctor/swhid-include-processor/README.adoc +44 -0
  31. data/lib/asciidoctor/swhid-include-processor/extension.rb +53 -0
  32. data/lib/asciidoctor/swhid-inline-macro/README.adoc +54 -0
  33. data/lib/asciidoctor/swhid-inline-macro/extension.rb +26 -0
  34. data/lib/asciidoctor/wikipedia-inline-macro/README.adoc +30 -0
  35. data/lib/asciidoctor/wikipedia-inline-macro/extension.rb +21 -0
  36. data/lib/asciidoctor-foodogsquared-extensions.rb +3 -0
  37. metadata +109 -0
@@ -0,0 +1,53 @@
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
@@ -0,0 +1,54 @@
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[]`
@@ -0,0 +1,26 @@
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
@@ -0,0 +1,30 @@
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.
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'asciidoctor/foodogsquared-extensions'
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asciidoctor-foodogsquared-extensions
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Arazas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 1980-01-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: asciidoctor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rugged
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description: |2
42
+ foo-dogsquared's custom Asciidoctor extensions as a Gem. This is not meant
43
+ to be used in production or as a public Gem. This is used since Hugo
44
+ doesn't allow loading Asciidoctor extensions with path separators.
45
+ email: foodogsquared@foodogsquared.one
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - asciidoctor-foodogsquared-extensions.gemspec
51
+ - lib/asciidoctor-foodogsquared-extensions.rb
52
+ - lib/asciidoctor/chat-block-processor/README.adoc
53
+ - lib/asciidoctor/chat-block-processor/extension.rb
54
+ - lib/asciidoctor/fdroid-link-inline-macro/README.adoc
55
+ - lib/asciidoctor/fdroid-link-inline-macro/extension.rb
56
+ - lib/asciidoctor/flathub-link-inline-macro/README.adoc
57
+ - lib/asciidoctor/flathub-link-inline-macro/extension.rb
58
+ - lib/asciidoctor/foodogsquared-extensions.rb
59
+ - lib/asciidoctor/git-blob-include-processor/README.adoc
60
+ - lib/asciidoctor/git-blob-include-processor/extension.rb
61
+ - lib/asciidoctor/github-link-inline-macro/README.adoc
62
+ - lib/asciidoctor/github-link-inline-macro/extension.rb
63
+ - lib/asciidoctor/github-raw-content-include-processor/README.adoc
64
+ - lib/asciidoctor/github-raw-content-include-processor/extension.rb
65
+ - lib/asciidoctor/gitlab-link-inline-macro/README.adoc
66
+ - lib/asciidoctor/gitlab-link-inline-macro/extension.rb
67
+ - lib/asciidoctor/gitlab-raw-content-include-processor/README.adoc
68
+ - lib/asciidoctor/gitlab-raw-content-include-processor/extension.rb
69
+ - lib/asciidoctor/helpers.rb
70
+ - lib/asciidoctor/ietf-rfc-link-inline-macro/README.adoc
71
+ - lib/asciidoctor/ietf-rfc-link-inline-macro/extension.rb
72
+ - lib/asciidoctor/man-inline-macro/README.adoc
73
+ - lib/asciidoctor/man-inline-macro/extension.rb
74
+ - lib/asciidoctor/musicbrainz-link-inline-macro/README.adoc
75
+ - lib/asciidoctor/musicbrainz-link-inline-macro/extension.rb
76
+ - lib/asciidoctor/package-indices-link-macro/extension.rb
77
+ - lib/asciidoctor/repology-link-inline-macro/README.adoc
78
+ - lib/asciidoctor/repology-link-inline-macro/extension.rb
79
+ - lib/asciidoctor/swhid-include-processor/README.adoc
80
+ - lib/asciidoctor/swhid-include-processor/extension.rb
81
+ - lib/asciidoctor/swhid-inline-macro/README.adoc
82
+ - lib/asciidoctor/swhid-inline-macro/extension.rb
83
+ - lib/asciidoctor/wikipedia-inline-macro/README.adoc
84
+ - lib/asciidoctor/wikipedia-inline-macro/extension.rb
85
+ homepage:
86
+ licenses:
87
+ - MIT
88
+ metadata:
89
+ source_code_uri: https://github.com/foo-dogsquared/foo-dogsquared.github.io
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 3.0.0
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubygems_version: 3.4.14
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: foo-dogsquared's custom Asciidoctor extensions
109
+ test_files: []