-
Notifications
You must be signed in to change notification settings - Fork 338
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,23 @@ | |
# | ||
# Turns | ||
# added[6.0.0-beta1] | ||
# changed[6.0.0-beta1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code and comments disagree, the code says There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've pushed a fix! |
||
# deprecated[6.0.0-beta1] | ||
# Into | ||
# added::[6.0.0-beta1] | ||
# changed::[6.0.0-beta1] | ||
# deprecated::[6.0.0-beta1] | ||
# Because `::` is required by asciidoctor to invoke block macros but isn't | ||
# required by asciidoc. | ||
# | ||
# Turns | ||
# words words added[6.0.0-beta1] | ||
# words words changed[6.0.0-beta1] | ||
# words words deprecated[6.0.0-beta1] | ||
# Into | ||
# words words added:[6.0.0-beta1] | ||
# words words changed:[6.0.0-beta1] | ||
# words words deprecated:[6.0.0-beta1] | ||
# Because `:` is required by asciidoctor to invoke inline macros but isn't | ||
# required by asciidoc. | ||
# | ||
|
@@ -140,12 +148,13 @@ def reader.process_line line | |
@code_block_start = line | ||
end | ||
end | ||
supported = 'added|coming|deprecated' | ||
# First convert the "block" version of these macros. We convert them | ||
# to block macros because they are at the start of the line.... | ||
line&.gsub!(/^(added)\[([^\]]*)\]/, '\1::[\2]') | ||
line&.gsub!(/^(#{supported})\[([^\]]*)\]/, '\1::[\2]') | ||
# Then convert the "inline" version of these macros. We convert them | ||
# to inline macros because they are *not* at the start of the line.... | ||
line&.gsub!(/(added)\[([^\]]*)\]/, '\1:[\2]') | ||
line&.gsub!(/(#{supported})\[([^\]]*)\]/, '\1:[\2]') | ||
end | ||
end | ||
reader | ||
|
This file was deleted.
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 |
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