diff --git a/resources/asciidoctor/lib/added/extension.rb b/resources/asciidoctor/lib/added/extension.rb deleted file mode 100644 index 2f890a2505306..0000000000000 --- a/resources/asciidoctor/lib/added/extension.rb +++ /dev/null @@ -1,59 +0,0 @@ -require 'asciidoctor/extensions' - -include Asciidoctor - -class Added < Extensions::Group - def activate registry - registry.block_macro AddedBlock - registry.inline_macro AddedInline - end -end - -# Extension for marking when something was added. -# -# Usage -# -# added::[6.0.0-beta1] -# -class AddedBlock < Extensions::BlockMacroProcessor - use_dsl - named :added - name_positional_attributes :version, :passtext - - def process parent, target, attrs - docbook = <<~DOCBOOK - - #{attrs[:passtext]} - - DOCBOOK - - create_pass_block parent, docbook, {}, subs: nil - end -end - -# Extension for marking when something was added. -# -# Usage -# -# Foo added:[6.0.0-beta1] -# -class AddedInline < Extensions::InlineMacroProcessor - use_dsl - named :added - name_positional_attributes :version, :text - with_format :short - - def process parent, target, attrs - if attrs[:text] - <<~DOCBOOK - - #{attrs[:text]} - - DOCBOOK - else - <<~DOCBOOK - - DOCBOOK - end - end -end diff --git a/resources/asciidoctor/lib/change_admonishment/extension.rb b/resources/asciidoctor/lib/change_admonishment/extension.rb new file mode 100644 index 0000000000000..38af08001c16d --- /dev/null +++ b/resources/asciidoctor/lib/change_admonishment/extension.rb @@ -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 << Block.new(note, :paragraph, + :source => attrs[:passtext], + :subs => Substitutors::NORMAL_SUBS) + note << Block.new(note, :pass, :source => "") + 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 + + #{attrs[:text]} + + DOCBOOK + else + <<~DOCBOOK + + DOCBOOK + end + end + end +end \ No newline at end of file diff --git a/resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb b/resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb index 3b454402aeb97..875ff1826ca6d 100644 --- a/resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb +++ b/resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb @@ -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. # @@ -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 diff --git a/resources/asciidoctor/lib/extensions.rb b/resources/asciidoctor/lib/extensions.rb index b7eaa25ee5445..651a0dd6bbb94 100644 --- a/resources/asciidoctor/lib/extensions.rb +++ b/resources/asciidoctor/lib/extensions.rb @@ -1,4 +1,4 @@ -require_relative 'added/extension' +require_relative 'change_admonishment/extension' require_relative 'copy_images/extension' require_relative 'cramped_include/extension' require_relative 'edit_me/extension' @@ -6,7 +6,7 @@ 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. diff --git a/resources/asciidoctor/spec/added_spec.rb b/resources/asciidoctor/spec/added_spec.rb deleted file mode 100644 index 9a642820d7bcc..0000000000000 --- a/resources/asciidoctor/spec/added_spec.rb +++ /dev/null @@ -1,87 +0,0 @@ -require 'added/extension' - -RSpec.describe Added do - before(:each) do - Extensions.register Added - end - - after(:each) do - Extensions.unregister_all - end - - it "block version creates a note" do - actual = convert <<~ASCIIDOC - == Example - added::[some_version] - ASCIIDOC - expected = <<~DOCBOOK - - Example - - - - - DOCBOOK - expect(actual).to eq(expected.strip) - end - - it "block version is not invoked without the ::" do - actual = convert <<~ASCIIDOC - == Example - added[some_version] - ASCIIDOC - expected = <<~DOCBOOK - - Example - added[some_version] - - DOCBOOK - expect(actual).to eq(expected.strip) - end - - it "inline version creates a phrase" do - actual = convert <<~ASCIIDOC - == Example - words added:[some_version] - ASCIIDOC - expected = <<~DOCBOOK - - Example - words - - - DOCBOOK - expect(actual).to eq(expected.strip) - end - - it "inline version creates a phrase with extra text if provided" do - actual = convert <<~ASCIIDOC - == Example - words added:[some_version, more words] - ASCIIDOC - expected = <<~DOCBOOK - - Example - words - more words - - - - DOCBOOK - expect(actual).to eq(expected.strip) - end - - it "inline version is not invoked without the :" do - actual = convert <<~ASCIIDOC - == Example - words added[some_version] - ASCIIDOC - expected = <<~DOCBOOK - - Example - words added[some_version] - - DOCBOOK - expect(actual).to eq(expected.strip) - end -end diff --git a/resources/asciidoctor/spec/change_admonishment_spec.rb b/resources/asciidoctor/spec/change_admonishment_spec.rb new file mode 100644 index 0000000000000..ca24dc88e3b68 --- /dev/null +++ b/resources/asciidoctor/spec/change_admonishment_spec.rb @@ -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 + + Example + + + + + 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 + ASCIIDOC + expected = <<~DOCBOOK + + Example + + See + +
+ Some Reference + +
+
+ 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 + + Example + #{name}[some_version] + + 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 + + Example + words + + + 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 + + Example + words + more words + + + + 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 + + Example + words #{name}[some_version] + + DOCBOOK + expect(actual).to eq(expected.strip) + end + } +end diff --git a/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb b/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb index de39df2e0a759..2a3652fa09ed2 100644 --- a/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb +++ b/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb @@ -1,11 +1,11 @@ -require 'added/extension' +require 'change_admonishment/extension' require 'elastic_compat_preprocessor/extension' require 'elastic_include_tagged/extension' require 'shared_examples/does_not_break_line_numbers' RSpec.describe ElasticCompatPreprocessor do before(:each) do - Extensions.register Added + Extensions.register ChangeAdmonishment Extensions.register do preprocessor ElasticCompatPreprocessor include_processor ElasticIncludeTagged @@ -18,36 +18,42 @@ include_examples "doesn't break line numbers" - it "invokes the added block macro when added[version] starts a line" do - actual = convert <<~ASCIIDOC - == Example - added[some_version] - ASCIIDOC - expected = <<~DOCBOOK - - Example - + [ + ['added', 'added'], + ['coming', 'changed'], + ['deprecated', 'deleted'] + ].each { |(name, revisionflag)| + it "invokes the #{name} block macro when #{name}[version] starts a line" do + actual = convert <<~ASCIIDOC + == Example + #{name}[some_version] + ASCIIDOC + expected = <<~DOCBOOK + + Example + - - - DOCBOOK - expect(actual).to eq(expected.strip) - end + + + DOCBOOK + expect(actual).to eq(expected.strip) + end - it "invokes the added inline macro when added[version] is otherwise on the line" do - actual = convert <<~ASCIIDOC - == Example - words added[some_version] - ASCIIDOC - expected = <<~DOCBOOK - - Example - words - - - DOCBOOK - expect(actual).to eq(expected.strip) - end + it "invokes the #{name} inline macro when #{name}[version] is otherwise on the line" do + actual = convert <<~ASCIIDOC + == Example + words #{name}[some_version] + ASCIIDOC + expected = <<~DOCBOOK + + Example + words + + + DOCBOOK + expect(actual).to eq(expected.strip) + end + } it "invokes include-tagged::" do actual = convert <<~ASCIIDOC @@ -111,7 +117,7 @@ Header - + DOCBOOK @@ -131,7 +137,7 @@ Header - + DOCBOOK @@ -154,7 +160,7 @@ Header - +