-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Asciidoctor: Remaining change admonishments #573
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
resources/asciidoctor/lib/change_admonishment/extension.rb
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,78 @@ | ||
require 'asciidoctor/extensions' | ||
|
||
include Asciidoctor | ||
|
||
## | ||
# Extensions for marking when something was added, when it *will* be added, or | ||
# when it was deprecated. | ||
# | ||
# Usage | ||
# | ||
# added::[6.0.0-beta1] | ||
# coming::[6.0.0-beta1] | ||
# deprecated::[6.0.0-beta1] | ||
# Foo added:[6.0.0-beta1] | ||
# Foo coming:[6.0.0-beta1] | ||
# Foo deprecated:[6.0.0-beta1] | ||
# | ||
class ChangeAdmonishment < Extensions::Group | ||
def activate registry | ||
[ | ||
[:added, 'added'], | ||
[:coming, 'changed'], | ||
[:deprecated, 'deleted'], | ||
].each { |(name, revisionflag)| | ||
registry.block_macro ChangeAdmonishmentBlock.new(revisionflag), name | ||
registry.inline_macro ChangeAdmonishmentInline.new(revisionflag), name | ||
} | ||
end | ||
|
||
class ChangeAdmonishmentBlock < Extensions::BlockMacroProcessor | ||
use_dsl | ||
name_positional_attributes :version, :passtext | ||
|
||
def initialize(revisionflag) | ||
super | ||
@revisionflag = revisionflag | ||
end | ||
|
||
def process parent, target, attrs | ||
version = attrs[:version] | ||
# We can *almost* go through the standard :admonition conversion but | ||
# that won't render the revisionflag or the revision. So we have to | ||
# go with this funny compound pass thing. | ||
note = Block.new(parent, :pass, :content_model => :compound) | ||
note << Block.new(note, :pass, | ||
:source => "<note revisionflag=\"#{@revisionflag}\" revision=\"#{version}\">") | ||
note << Block.new(note, :paragraph, | ||
:source => attrs[:passtext], | ||
:subs => Substitutors::NORMAL_SUBS) | ||
note << Block.new(note, :pass, :source => "</note>") | ||
end | ||
end | ||
|
||
class ChangeAdmonishmentInline < Extensions::InlineMacroProcessor | ||
use_dsl | ||
name_positional_attributes :version, :text | ||
with_format :short | ||
|
||
def initialize(revisionflag) | ||
super | ||
@revisionflag = revisionflag | ||
end | ||
|
||
def process parent, target, attrs | ||
if attrs[:text] | ||
<<~DOCBOOK | ||
<phrase revisionflag="#{@revisionflag}" revision="#{attrs[:version]}"> | ||
#{attrs[:text]} | ||
</phrase> | ||
DOCBOOK | ||
else | ||
<<~DOCBOOK | ||
<phrase revisionflag="#{@revisionflag}" revision="#{attrs[:version]}"/> | ||
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
This file was deleted.
Oops, something went wrong.
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,115 @@ | ||
require 'change_admonishment/extension' | ||
|
||
RSpec.describe ChangeAdmonishment do | ||
before(:each) do | ||
Extensions.register ChangeAdmonishment | ||
end | ||
|
||
after(:each) do | ||
Extensions.unregister_all | ||
end | ||
|
||
[ | ||
['added', 'added'], | ||
['coming', 'changed'], | ||
['deprecated', 'deleted'] | ||
].each { |(name, revisionflag)| | ||
it "#{name}'s block version creates a note" do | ||
actual = convert <<~ASCIIDOC | ||
== Example | ||
#{name}::[some_version] | ||
ASCIIDOC | ||
expected = <<~DOCBOOK | ||
<chapter id="_example"> | ||
<title>Example</title> | ||
<note revisionflag="#{revisionflag}" revision="some_version"> | ||
<simpara></simpara> | ||
</note> | ||
</chapter> | ||
DOCBOOK | ||
expect(actual).to eq(expected.strip) | ||
end | ||
|
||
it "#{name}'s block version supports asciidoc in the passtext" do | ||
actual = convert <<~ASCIIDOC | ||
== Example | ||
#{name}::[some_version,See <<some-reference>>] | ||
[[some-reference]] | ||
=== Some Reference | ||
ASCIIDOC | ||
expected = <<~DOCBOOK | ||
<chapter id="_example"> | ||
<title>Example</title> | ||
<note revisionflag="#{revisionflag}" revision="some_version"> | ||
<simpara>See <xref linkend="some-reference"/></simpara> | ||
</note> | ||
<section id="some-reference"> | ||
<title>Some Reference</title> | ||
|
||
</section> | ||
</chapter> | ||
DOCBOOK | ||
expect(actual).to eq(expected.strip) | ||
end | ||
|
||
it "#{name}'s block version is not invoked without the ::" do | ||
actual = convert <<~ASCIIDOC | ||
== Example | ||
#{name}[some_version] | ||
ASCIIDOC | ||
expected = <<~DOCBOOK | ||
<chapter id="_example"> | ||
<title>Example</title> | ||
<simpara>#{name}[some_version]</simpara> | ||
</chapter> | ||
DOCBOOK | ||
expect(actual).to eq(expected.strip) | ||
end | ||
|
||
it "#{name}'s inline version creates a phrase" do | ||
actual = convert <<~ASCIIDOC | ||
== Example | ||
words #{name}:[some_version] | ||
ASCIIDOC | ||
expected = <<~DOCBOOK | ||
<chapter id="_example"> | ||
<title>Example</title> | ||
<simpara>words <phrase revisionflag="#{revisionflag}" revision="some_version"/> | ||
</simpara> | ||
</chapter> | ||
DOCBOOK | ||
expect(actual).to eq(expected.strip) | ||
end | ||
|
||
it "#{name}'s inline version creates a phrase with extra text if provided" do | ||
actual = convert <<~ASCIIDOC | ||
== Example | ||
words #{name}:[some_version, more words] | ||
ASCIIDOC | ||
expected = <<~DOCBOOK | ||
<chapter id="_example"> | ||
<title>Example</title> | ||
<simpara>words <phrase revisionflag="#{revisionflag}" revision="some_version"> | ||
more words | ||
</phrase> | ||
</simpara> | ||
</chapter> | ||
DOCBOOK | ||
expect(actual).to eq(expected.strip) | ||
end | ||
|
||
it "#{name}'s inline version is not invoked without the :" do | ||
actual = convert <<~ASCIIDOC | ||
== Example | ||
words #{name}[some_version] | ||
ASCIIDOC | ||
expected = <<~DOCBOOK | ||
<chapter id="_example"> | ||
<title>Example</title> | ||
<simpara>words #{name}[some_version]</simpara> | ||
</chapter> | ||
DOCBOOK | ||
expect(actual).to eq(expected.strip) | ||
end | ||
} | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of these things is not like the others! I'm sure there is a reason BUT, to people (like me!) reading this, the word
deprecated
absolutely does not mean the same thing asdeleted
, in fact it very specifically implies "definitely totally 100% still present".Is this dictated by the docbook side? I see from the tests that the revisionFlag will contain
deleted
. If that is within our control it may be worth its own issue? I have no clear sense of how much inertia there is behind it either.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is dictated by the docbook side, yeah. I'll file an issue for it! I think it is a thing that we can clean up now, but I'd like to break it into its own thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#588