-
Notifications
You must be signed in to change notification settings - Fork 345
Asciidoctor: BWC for // CONSOLE then callouts #721
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
Changes from all commits
ead0692
a830f1d
96bc662
97f882c
b55d932
73e73d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
## | ||
# Block macro that exists entirely to mark language overrides in a clean way | ||
# without adding additional lines to the input file which would throw off | ||
# line numbers. | ||
# | ||
class LangOverride < Asciidoctor::Extensions::BlockMacroProcessor | ||
use_dsl | ||
named :lang_override | ||
name_positional_attributes :override | ||
def process(parent, _target, attrs) | ||
Asciidoctor::Block.new(parent, :pass, :source => "// #{attrs[:override]}") | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'elastic_compat_tree_processor/extension' | ||
require 'lang_override/extension' | ||
|
||
RSpec.describe ElasticCompatTreeProcessor do | ||
before(:each) do | ||
Asciidoctor::Extensions.register do | ||
treeprocessor ElasticCompatTreeProcessor | ||
block_macro LangOverride | ||
end | ||
end | ||
|
||
|
@@ -72,51 +74,82 @@ | |
expect(actual).to eq(expected.strip) | ||
end | ||
|
||
[ | ||
%w[CONSOLE console], | ||
%w[AUTOSENSE sense], | ||
%w[KIBANA kibana], | ||
%w[SENSE:path/to/snippet.sense sense], | ||
].each do |command, lang| | ||
it "transforms legacy // #{command} commands into the #{lang} language" do | ||
actual = convert <<~ASCIIDOC | ||
== Example | ||
[source,js] | ||
---- | ||
GET / | ||
---- | ||
pass:[// #{command}] | ||
ASCIIDOC | ||
expected = <<~DOCBOOK | ||
<chapter id="_example"> | ||
<title>Example</title> | ||
<programlisting language="#{lang}" linenumbering="unnumbered">GET /</programlisting> | ||
</chapter> | ||
DOCBOOK | ||
expect(actual).to eq(expected.strip) | ||
end | ||
end | ||
shared_examples 'snippet language' do |override, lang| | ||
name = override ? " the #{override} lang override" : 'out a lang override' | ||
context "for a snippet with#{name}" do | ||
let(:snippet) do | ||
snippet = <<~ASCIIDOC | ||
[source,js] | ||
---- | ||
GET / <1> | ||
---- | ||
ASCIIDOC | ||
snippet += "lang_override::[#{override}]" if override | ||
snippet | ||
end | ||
let(:has_lang) do | ||
/<programlisting language="#{lang}" linenumbering="unnumbered">/ | ||
end | ||
shared_examples 'has the expected language' do | ||
it "has the #{lang} language" do | ||
expect(converted).to match(has_lang) | ||
end | ||
end | ||
context 'when it is alone' do | ||
let(:converted) do | ||
convert <<~ASCIIDOC | ||
== Example | ||
#{snippet} | ||
ASCIIDOC | ||
end | ||
include_examples 'has the expected language' | ||
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. This is very nuanced, but you could also use 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. Thanks for this! I looked at 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 see what you're saying. Ultimately, they can accomplish very similar things in the specs, so it's up to you and how you want the the specs to run and print out. |
||
end | ||
context 'when it is followed by a paragraph' do | ||
let(:converted) do | ||
convert <<~ASCIIDOC | ||
== Example | ||
#{snippet} | ||
|
||
context 'a snippet is inside of a definition list' do | ||
let(:converted) do | ||
convert <<~ASCIIDOC | ||
== Example | ||
Term:: | ||
Definition | ||
+ | ||
-- | ||
[source,js] | ||
---- | ||
GET / | ||
---- | ||
-- | ||
ASCIIDOC | ||
end | ||
let(:has_original_language) do | ||
%r{<programlisting language="js" linenumbering="unnumbered">GET /</programlisting>} | ||
end | ||
it "doesn't break" do | ||
expect(converted).to match(has_original_language) | ||
Words words words. | ||
ASCIIDOC | ||
end | ||
include_examples 'has the expected language' | ||
it "the paragraph is intact" do | ||
expect(converted).to match(%r{<simpara>Words words words.</simpara>}) | ||
end | ||
end | ||
context 'when it is inside a definition list' do | ||
let(:converted) do | ||
convert <<~ASCIIDOC | ||
== Example | ||
Term:: | ||
Definition | ||
+ | ||
-- | ||
#{snippet} | ||
-- | ||
ASCIIDOC | ||
end | ||
include_examples 'has the expected language' | ||
end | ||
context 'when it is followed by a callout list' do | ||
let(:converted) do | ||
convert <<~ASCIIDOC | ||
== Example | ||
#{snippet} | ||
<1> foo | ||
ASCIIDOC | ||
end | ||
include_examples 'has the expected language' | ||
it "has a working callout list" do | ||
expect(converted).to match(/<callout arearefs="CO1-1">\n<para>foo/) | ||
end | ||
end | ||
end | ||
end | ||
include_examples 'snippet language', 'CONSOLE', 'console' | ||
include_examples 'snippet language', 'AUTOSENSE', 'sense' | ||
include_examples 'snippet language', 'KIBANA', 'kibana' | ||
include_examples 'snippet language', 'SENSE:path/to/snippet.sense', 'sense' | ||
include_examples 'snippet language', nil, 'js' | ||
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.
Have you seen the
#tap
method in Ruby? It's a style thing, but you could use it here. I like using it so I never accidentally forget to return the object (in this case,snippet
) from the let block.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.
#tap
seems pretty complex to use here because the string is frozen. Though I bet there are other places i can use it....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.
ah, then it wouldn't work if the String is frozen..