Skip to content
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 3 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions resources/asciidoctor/lib/added/extension.rb

This file was deleted.

78 changes: 78 additions & 0 deletions resources/asciidoctor/lib/change_admonishment/extension.rb
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'],

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 as deleted, 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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

].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
Expand Up @@ -7,15 +7,23 @@
#
# Turns
# added[6.0.0-beta1]
# coming[6.0.0-beta1]
# deprecated[6.0.0-beta1]
# Into
# added::[6.0.0-beta1]
# coming::[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.
#
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions resources/asciidoctor/lib/extensions.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require_relative 'added/extension'
require_relative 'change_admonishment/extension'
require_relative 'copy_images/extension'
require_relative 'cramped_include/extension'
require_relative 'edit_me/extension'
require_relative 'elastic_compat_tree_processor/extension'
require_relative 'elastic_compat_preprocessor/extension'
require_relative 'elastic_include_tagged/extension'

Extensions.register Added
Extensions.register ChangeAdmonishment
Extensions.register do
# Enable storing the source locations so we can look at them. This is required
# for EditMe to get a nice location.
Expand Down
87 changes: 0 additions & 87 deletions resources/asciidoctor/spec/added_spec.rb

This file was deleted.

115 changes: 115 additions & 0 deletions resources/asciidoctor/spec/change_admonishment_spec.rb
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
Loading