Skip to content

Commit 7d243dd

Browse files
authored
Asciidoctor: Implement beta and experimental (#662)
Implements the `beta[]` and `experimental[]` macros for asciidoctor. It adds integration tests that make sure that we copy the required image even if that is the only admonition in the book. This is an especially good idea here because the code that copies the images for the admonitions is a little sneaky.
1 parent 6732289 commit 7d243dd

File tree

11 files changed

+339
-35
lines changed

11 files changed

+339
-35
lines changed

README.asciidoc

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
= Docs HOWTO
22
:ref: http://www.elastic.co/guide/elasticsearch/reference/current
33

4+
////
5+
This file contains the sequence `_` to escape from around Elastic's
6+
Asciidoctor plugin that provides Asciidoc compatibility. It automatically
7+
translates things like `beta[]` into their Asciidoctor compatible form
8+
which looks like `beta::[]`. We use `beta_]` inside of asciidoc
9+
examples so we can output `beta[]`. Once we no longer support Asciidoc
10+
we can drop these sequences.
11+
////
12+
413
== Conditions of use
514

615
This documentation build process is provided to the public purely for the
@@ -1233,9 +1242,9 @@ the addition or deprecation of individual parameters.
12331242
[source,asciidoc]
12341243
----------------------------------
12351244
[horizontal]
1236-
`foo.bar`:: Does XYZ. added[0.90.4]
1237-
`foo.bar`:: Does XYZ. coming[0.90.4]
1238-
`foo.baz`:: Does XYZ. deprecated[0.90.4]
1245+
`foo.bar`:: Does XYZ. added_0.90.4]
1246+
`foo.bar`:: Does XYZ. coming_0.90.4]
1247+
`foo.baz`:: Does XYZ. deprecated_0.90.4]
12391248
----------------------------------
12401249

12411250
[horizontal]
@@ -1250,9 +1259,9 @@ user hovers over it:
12501259
[source,asciidoc]
12511260
----------------------------------
12521261
[horizontal]
1253-
`foo.bar`:: Does XYZ. added[0.90.4,Replaces `foo.baz`]
1254-
`foo.bar`:: Does XYZ. coming[0.90.4,Replaces `foo.baz`]
1255-
`foo.baz`:: Does XYZ. deprecated[0.90.4,Replaced by `foo.bar`]
1262+
`foo.bar`:: Does XYZ. added_0.90.4,Replaces `foo.baz`]
1263+
`foo.bar`:: Does XYZ. coming_0.90.4,Replaces `foo.baz`]
1264+
`foo.baz`:: Does XYZ. deprecated_0.90.4,Replaced by `foo.bar`]
12561265
----------------------------------
12571266

12581267
[horizontal]
@@ -1270,19 +1279,19 @@ to the version in which the change was made:
12701279
----------------------------------
12711280
==== New section
12721281
1273-
added[0.90.4]
1282+
added_0.90.4]
12741283
12751284
Text about new functionality...
12761285
12771286
==== New section not yet released
12781287
1279-
coming[0.90.9]
1288+
coming_0.90.9]
12801289
12811290
Text about new functionality...
12821291
12831292
==== Old section
12841293
1285-
deprecated[0.90.4]
1294+
deprecated_0.90.4]
12861295
12871296
Text about old functionality...
12881297
----------------------------------
@@ -1305,6 +1314,7 @@ deprecated[0.90.4]
13051314

13061315
Text about old functionality...
13071316

1317+
[[with_details]]
13081318
==== With details...
13091319

13101320
Or they can include extra text, including more
@@ -1315,21 +1325,21 @@ Asciidoc markup:
13151325
[[new-section]]
13161326
==== New section
13171327
1318-
added[0.90.4,Replaces `foo.bar`. See <<old-section>>]
1328+
added&#x5f;0.90.4,Replaces `foo.bar`. See <<old-section>>]
13191329
13201330
Text about new functionality...
13211331
13221332
[[coming-section]]
13231333
==== New section not yet released
13241334
1325-
coming[0.90.9,Replaces `foo.bar`. See <<old-section>>]
1335+
coming&#x5f;0.90.9,Replaces `foo.bar`. See <<old-section>>]
13261336
13271337
Text about new functionality...
13281338
13291339
[[old-section]]
13301340
==== Old section
13311341
1332-
deprecated[0.90.4,Replace by `foo.baz`. See <<new-section>>]
1342+
deprecated&#x5f;0.90.4,Replace by `foo.baz`. See <<new-section>>]
13331343
13341344
Text about old functionality...
13351345
----------------------------------
@@ -1359,9 +1369,9 @@ markup similar to that used in <<changes>>. For instance:
13591369
[[new-feature]]
13601370
=== New experimental feature
13611371
1362-
experimental[]
1372+
experimental&#x5f;]
13631373
1364-
experimental[Custom text goes here]
1374+
experimental&#x5f;Custom text goes here]
13651375
13661376
Text about new feature...
13671377
@@ -1373,8 +1383,8 @@ a new experimental parameter:
13731383
13741384
[horizontal]
13751385
`established_param`:: This param has been around for ages and won't change.
1376-
`experimental_param`:: experimental[] This param is experimental and may change in the future.
1377-
`experimental_param`:: experimental[Custom text goes here] This param is experimental and may change in the future.
1386+
`experimental_param`:: experimental&#x5f;] This param is experimental and may change in the future.
1387+
`experimental_param`:: experimental&#x5f;Custom text goes here] This param is experimental and may change in the future.
13781388
13791389
----------------------------------
13801390

@@ -1403,9 +1413,9 @@ a new experimental parameter:
14031413
[[new-beta-feature]]
14041414
=== New beta feature
14051415
1406-
beta[]
1416+
beta&#x5f;]
14071417
1408-
beta[Custom text goes here]
1418+
beta&#x5f;Custom text goes here]
14091419
14101420
Text about new feature...
14111421
@@ -1417,8 +1427,8 @@ a new beta parameter:
14171427
14181428
[horizontal]
14191429
`established_param`:: This param has been around for ages and won't change.
1420-
`beta_param`:: beta[] This param is beta and may change in the future.
1421-
`beta_param`:: beta[Custom text goes here] This param is beta and may change in the future.
1430+
`beta_param`:: beta&#x5f;] This param is beta and may change in the future.
1431+
`beta_param`:: beta&#x5f;Custom text goes here] This param is beta and may change in the future.
14221432
14231433
----------------------------------
14241434

integtest/Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ check: \
1212
style \
1313
minimal_expected_files minimal_same_files \
1414
includes_expected_files includes_same_files \
15+
beta_expected_files beta_same_files \
16+
experimental_expected_files experimental_same_files \
1517
readme_expected_files readme_same_files \
1618
small_all_expected_files
1719

@@ -41,6 +43,16 @@ readme_expected_files: /tmp/readme_asciidoc
4143
[ -s $^/images/icons/callouts/2.png ]
4244
[ -s $^/snippets/blocks/1.json ]
4345

46+
.PHONY: experimental_expected_files
47+
beta_expected_files: /tmp/beta_asciidoc
48+
$(STANDARD_EXPECTED_FILES)
49+
[ -s $^/images/icons/warning.png ]
50+
51+
.PHONY: experimental_expected_files
52+
experimental_expected_files: /tmp/experimental_asciidoc
53+
$(STANDARD_EXPECTED_FILES)
54+
[ -s $^/images/icons/warning.png ]
55+
4456
.PHONY: %_expected_files
4557
%_expected_files: /tmp/%_asciidoc
4658
$(STANDARD_EXPECTED_FILES)
@@ -54,7 +66,7 @@ readme_expected_files: /tmp/readme_asciidoc
5466
<(cd /tmp/$*_asciidoctor && find * -type f | sort)
5567
# The grep -v below are for known issues with asciidoctor
5668
for file in $$(cd /tmp/$*_asciidoc && find * -type f -name '*.html' \
57-
| grep -v 'blocks\|changes\|experimental'); do \
69+
| grep -v 'blocks'); do \
5870
./html_diff /tmp/$*_asciidoc/$$file /tmp/$*_asciidoctor/$$file; \
5971
done
6072

@@ -67,6 +79,11 @@ endef
6779

6880
/tmp/readme_asciidoctor: /docs_build/README.asciidoc
6981
$(BD) --asciidoctor --doc /docs_build/README.asciidoc
82+
# These are different when rendered by asciidoctor but they are
83+
# correct for asciidoctor. So we're ok with it. It isn't perfect, but
84+
# perfect is quite hard for this.
85+
# sed -i -E 's/beta::?\[/beta\[/' /tmp/readme_asciidoctor/experimental.html
86+
# sed -i -E 's/experimental::?\[/experimental\[/' /tmp/readme_asciidoctor/experimental.html
7087

7188
# These don't declare dependencies because we don't know in general which files
7289
# are needed to build which asciidoc files.

integtest/beta.asciidoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
= Title
2+
3+
== Chapter
4+
5+
beta[]
6+
7+
Words

integtest/experimental.asciidoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
= Title
2+
3+
== Chapter
4+
5+
experimental[]
6+
7+
Words

lib/ES/Template.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ sub _init {
154154
}
155155

156156
my $created = $1 || 0;
157-
if ( not $force and time - $latest < 20 * 60 ) {
157+
if ( not $force and time - $latest < 20 * 60) {
158158
$new = $old[-1];
159159
}
160160
else {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# frozen_string_literal: true
2+
3+
require 'asciidoctor/extensions'
4+
5+
##
6+
# Extensions for marking when something as `beta` or `experimental`.
7+
#
8+
# Usage
9+
#
10+
# beta::[]
11+
# experimental::[]
12+
# Foo beta:[]
13+
# Foo experimental:[]
14+
#
15+
class CareAdmonition < Asciidoctor::Extensions::Group
16+
def activate(registry)
17+
[
18+
[:beta, 'beta'],
19+
[:experimental, 'experimental'],
20+
].each do |(name, role)|
21+
registry.block_macro ChangeAdmonitionBlock.new(role), name
22+
registry.inline_macro ChangeAdmonitionInline.new(role), name
23+
end
24+
end
25+
26+
##
27+
# Block care admonition.
28+
class ChangeAdmonitionBlock < Asciidoctor::Extensions::BlockMacroProcessor
29+
use_dsl
30+
name_positional_attributes :passtext
31+
32+
def initialize(role)
33+
super(nil)
34+
@role = role
35+
end
36+
37+
def process(parent, _target, attrs)
38+
Asciidoctor::Block.new(parent, :admonition,
39+
:source => attrs[:passtext],
40+
:attributes => {
41+
'role' => @role,
42+
'name' => 'warning',
43+
'style' => 'warning',
44+
})
45+
end
46+
end
47+
48+
##
49+
# Inline care admonition.
50+
class ChangeAdmonitionInline < Asciidoctor::Extensions::InlineMacroProcessor
51+
use_dsl
52+
name_positional_attributes :text
53+
with_format :short
54+
55+
def initialize(role)
56+
super(nil)
57+
@role = role
58+
end
59+
60+
def process(_parent, _target, attrs)
61+
if attrs[:text]
62+
<<~DOCBOOK
63+
<phrase role="#{@role}">
64+
#{attrs[:text]}
65+
</phrase>
66+
DOCBOOK
67+
else
68+
<<~DOCBOOK
69+
<phrase role="#{@role}"/>
70+
DOCBOOK
71+
end
72+
end
73+
end
74+
end

resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def reader.process_line(line)
142142
@code_block_start = line
143143
end
144144
end
145-
supported = 'added|coming|deprecated'
145+
supported = 'added|beta|coming|deprecated|experimental'
146146
# First convert the "block" version of these macros. We convert them
147147
# to block macros because they are at the start of the line....
148148
line&.gsub!(/^(#{supported})\[([^\]]*)\]/, '\1::[\2]')

resources/asciidoctor/lib/extensions.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require_relative 'care_admonition/extension'
34
require_relative 'change_admonition/extension'
45
require_relative 'copy_images/extension'
56
require_relative 'cramped_include/extension'
@@ -8,6 +9,7 @@
89
require_relative 'elastic_compat_preprocessor/extension'
910
require_relative 'elastic_include_tagged/extension'
1011

12+
Asciidoctor::Extensions.register CareAdmonition
1113
Asciidoctor::Extensions.register ChangeAdmonition
1214
Asciidoctor::Extensions.register do
1315
# Enable storing the source locations so we can look at them. This is required

0 commit comments

Comments
 (0)