-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Asciidoctor: Implement beta and experimental (#662)
Implements the `beta[]` and `experimental[]` macros for asciidoctor. It adds integration tests that make sure that we copy the required image even if that is the only admonition in the book. This is an especially good idea here because the code that copies the images for the admonitions is a little sneaky.
- Loading branch information
Showing
11 changed files
with
339 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
= Title | ||
|
||
== Chapter | ||
|
||
beta[] | ||
|
||
Words |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
= Title | ||
|
||
== Chapter | ||
|
||
experimental[] | ||
|
||
Words |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'asciidoctor/extensions' | ||
|
||
## | ||
# Extensions for marking when something as `beta` or `experimental`. | ||
# | ||
# Usage | ||
# | ||
# beta::[] | ||
# experimental::[] | ||
# Foo beta:[] | ||
# Foo experimental:[] | ||
# | ||
class CareAdmonition < Asciidoctor::Extensions::Group | ||
def activate(registry) | ||
[ | ||
[:beta, 'beta'], | ||
[:experimental, 'experimental'], | ||
].each do |(name, role)| | ||
registry.block_macro ChangeAdmonitionBlock.new(role), name | ||
registry.inline_macro ChangeAdmonitionInline.new(role), name | ||
end | ||
end | ||
|
||
## | ||
# Block care admonition. | ||
class ChangeAdmonitionBlock < Asciidoctor::Extensions::BlockMacroProcessor | ||
use_dsl | ||
name_positional_attributes :passtext | ||
|
||
def initialize(role) | ||
super(nil) | ||
@role = role | ||
end | ||
|
||
def process(parent, _target, attrs) | ||
Asciidoctor::Block.new(parent, :admonition, | ||
:source => attrs[:passtext], | ||
:attributes => { | ||
'role' => @role, | ||
'name' => 'warning', | ||
'style' => 'warning', | ||
}) | ||
end | ||
end | ||
|
||
## | ||
# Inline care admonition. | ||
class ChangeAdmonitionInline < Asciidoctor::Extensions::InlineMacroProcessor | ||
use_dsl | ||
name_positional_attributes :text | ||
with_format :short | ||
|
||
def initialize(role) | ||
super(nil) | ||
@role = role | ||
end | ||
|
||
def process(_parent, _target, attrs) | ||
if attrs[:text] | ||
<<~DOCBOOK | ||
<phrase role="#{@role}"> | ||
#{attrs[:text]} | ||
</phrase> | ||
DOCBOOK | ||
else | ||
<<~DOCBOOK | ||
<phrase role="#{@role}"/> | ||
DOCBOOK | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.