Skip to content

Commit 71d8558

Browse files
authored
Merge pull request #1162 from abelsromero/issue-1160-deprecate-headerFooter-with-standalone-for-2.5.x
(v2.5.x) Deprecate 'headerFooter' in favour of 'standalone'
2 parents 17dccb4 + e330544 commit 71d8558

File tree

11 files changed

+197
-149
lines changed

11 files changed

+197
-149
lines changed

CHANGELOG.adoc

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co
1313

1414
== Unreleased
1515

16+
Improvement::
17+
18+
* Add 'standalone' option, deprecates 'headerFooter' (#1160) (@abelsromero)
19+
20+
Bug Fixes::
21+
22+
* Fix destinationDir not having effect. Deprecate destinationDir in favour of toDir (#853, #941) (@abelsromero)
23+
1624
== 2.5.7 (2022-10-21)
1725

1826
Improvement::
@@ -21,9 +29,6 @@ Improvement::
2129
* Upgrade to asciidoctorj-diagram 2.2.4 (#1140)
2230
* Upgrade to jruby 9.3.10.0 (#1138) (@alexlevinfr)
2331

24-
Bug Fixes::
25-
* Fix destinationDir not having effect. Deprecate destinationDir in favour of toDir (@abelsromero) (#853, #941)
26-
2732
Build / Infrastructure::
2833

2934
* Replace use of deprecated 'numbered' attribute by 'sectnums' (#1127) (@abelsromero)

asciidoctorj-api/src/main/java/org/asciidoctor/Options.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.asciidoctor;
22

3-
import java.io.File;
43
import java.io.OutputStream;
54
import java.util.ArrayList;
65
import java.util.Arrays;
@@ -71,6 +70,19 @@ public void setAttributes(Map<String, Object> attributes) {
7170
this.options.put(ATTRIBUTES, attributes);
7271
}
7372

73+
/**
74+
* Toggle including header and footer into the output.
75+
*
76+
* @param standalone <code>true</code> to generate a standalone output document
77+
* (which includes the shell around the body content, such
78+
* as the header and footer).
79+
* Defaults to <code>true</code> when converting a file only,
80+
* otherwise is <code>false</code>.
81+
*/
82+
public void setStandalone(boolean standalone) {
83+
this.options.put(STANDALONE, standalone);
84+
}
85+
7486
/**
7587
* Toggle including header and footer into the output.
7688
*
@@ -85,7 +97,7 @@ public void setHeaderFooter(boolean headerFooter) {
8597
public void setTemplateDirs(String... templateDirs) {
8698

8799
if (!this.options.containsKey(TEMPLATE_DIRS)) {
88-
this.options.put(TEMPLATE_DIRS, new ArrayList<Object>());
100+
this.options.put(TEMPLATE_DIRS, new ArrayList<>());
89101
}
90102

91103
List<Object> allTemplateDirs = (List<Object>) this.options.get(TEMPLATE_DIRS);

asciidoctorj-api/src/main/java/org/asciidoctor/OptionsBuilder.java

+19-3
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,28 @@ public OptionsBuilder inPlace(boolean inPlace) {
5959
return this;
6060
}
6161

62+
/**
63+
* Toggle including header and footer into the output.
64+
*
65+
* @param standalone <code>true</code> to generate a standalone output document
66+
* (which includes the shell around the body content, such
67+
* as the header and footer).
68+
* Defaults to <code>true</code> when converting a file only,
69+
* otherwise is <code>false</code>.
70+
*/
71+
public OptionsBuilder standalone(boolean standalone) {
72+
this.options.setStandalone(standalone);
73+
return this;
74+
}
75+
6276
/**
6377
* Sets header footer attribute.
64-
*
65-
* @param headerFooter
66-
* value.
78+
*
79+
* @param headerFooter value.
6780
* @return this instance.
81+
* @deprecated Use {@link #standalone(boolean)} instead.
6882
*/
83+
@Deprecated
6984
public OptionsBuilder headerFooter(boolean headerFooter) {
7085
this.options.setHeaderFooter(headerFooter);
7186
return this;
@@ -80,6 +95,7 @@ public OptionsBuilder headerFooter(boolean headerFooter) {
8095
* directory where templates are stored.
8196
* @return this instance.
8297
*/
98+
@Deprecated
8399
public OptionsBuilder templateDir(File templateDir) {
84100
this.options.setTemplateDirs(templateDir.getAbsolutePath());
85101
return this;

asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/AsciidoctorUtils.java

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
package org.asciidoctor.jruby.internal;
22

3+
import org.asciidoctor.Options;
4+
import org.asciidoctor.SafeMode;
5+
import org.asciidoctor.jruby.cli.AsciidoctorCliOptions;
6+
37
import java.util.ArrayList;
48
import java.util.List;
59
import java.util.Map;
610
import java.util.Map.Entry;
711
import java.util.Set;
812

9-
import org.asciidoctor.Options;
10-
import org.asciidoctor.SafeMode;
11-
import org.asciidoctor.jruby.cli.AsciidoctorCliOptions;
12-
1313
public class AsciidoctorUtils {
1414

1515
private static final String RUNNER = "asciidoctor";
1616

1717
private AsciidoctorUtils() {
1818
super();
1919
}
20-
20+
2121
public static boolean isOptionWithAttribute(Map<String, Object> options, String attributeName, String attributeValue) {
22-
22+
2323
if(options.containsKey(Options.ATTRIBUTES)) {
2424
Map<String, Object> attributes = (Map<String, Object>) options.get(Options.ATTRIBUTES);
25-
25+
2626
if(attributes.containsKey(attributeName)) {
2727
String configuredAttributeValue = (String) attributes.get(attributeName);
28-
28+
2929
if(configuredAttributeValue.equals(attributeValue)) {
3030
return true;
3131
}
32-
32+
3333
}
34-
34+
3535
}
36-
36+
3737
return false;
3838
}
39-
39+
4040
public static List<String> toAsciidoctorCommand(Map<String, Object> options,
4141
String inputPath) {
4242

@@ -65,7 +65,7 @@ private static List<String> getOptions(Map<String, Object> options) {
6565

6666
if (options.containsKey(Options.TEMPLATE_DIRS)) {
6767
List<String> templates = (List<String>) options.get(Options.TEMPLATE_DIRS);
68-
68+
6969
for (String template : templates) {
7070
optionsAndAttributes.add(AsciidoctorCliOptions.TEMPLATE_DIR);
7171
optionsAndAttributes.add(template);
@@ -86,7 +86,7 @@ private static List<String> getOptions(Map<String, Object> options) {
8686
optionsAndAttributes.add(options.get(Options.ERUBY).toString());
8787
}
8888

89-
if (options.containsKey(Options.HEADER_FOOTER)) {
89+
if (options.containsKey(Options.STANDALONE) || options.containsKey(Options.HEADER_FOOTER)) {
9090
optionsAndAttributes.add(AsciidoctorCliOptions.NO_HEADER_FOOTER);
9191
}
9292

@@ -117,9 +117,9 @@ private static List<String> getOptions(Map<String, Object> options) {
117117
}
118118

119119
return optionsAndAttributes;
120-
120+
121121
}
122-
122+
123123
private static List<String> getAttributesSyntax(Map<String, Object> attributes) {
124124
List<String> attributesOutput = new ArrayList<>();
125125

@@ -144,9 +144,9 @@ private static List<String> getAttributeSyntax(String attributeName,
144144

145145
if (attributeValue != null && !"".equals(attributeValue.toString().trim())) {
146146
argument.append("=");
147-
argument.append(attributeValue.toString());
147+
argument.append(attributeValue);
148148
}
149-
149+
150150
if(attributeValue == null) {
151151
argument.append("!");
152152
}

asciidoctorj-core/src/test/java/org/asciidoctor/WhenAsciidoctorLogsToConsole.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public void shouldOnlyNotifyFromRegisteredAsciidoctor() throws Exception {
188188
}
189189

190190
@Test
191-
public void shouldNoLongerNotifyAfterUnregisterOnlyNotifyFromRegisteredAsciidoctor() throws Exception {
191+
public void shouldNoLongerNotifyAfterUnregisterOnlyNotifyFromRegisteredAsciidoctor() {
192192

193193
final List<LogRecord> logRecords = new ArrayList<>();
194194

@@ -274,7 +274,7 @@ public Object process(StructuralNode parent, Reader reader, Map<String, Object>
274274
}
275275

276276
@Test
277-
public void a_extension_should_be_able_to_log() throws Exception {
277+
public void a_extension_should_be_able_to_log() {
278278

279279
final List<LogRecord> logRecords = new ArrayList<>();
280280

asciidoctorj-core/src/test/java/org/asciidoctor/WhenSourceHighlightingIsUsed.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class WhenSourceHighlightingIsUsed {
2727
private Asciidoctor asciidoctor;
2828

2929
@Test
30-
public void should_render_with_rouge() throws Exception {
30+
public void should_render_with_rouge() {
3131
String html = asciidoctor.convert(DOCUMENT,
3232
OptionsBuilder.options()
3333
.headerFooter(true)
@@ -43,7 +43,7 @@ public void should_render_with_rouge() throws Exception {
4343
}
4444

4545
@Test
46-
public void should_render_with_coderay() throws Exception {
46+
public void should_render_with_coderay() {
4747
String html = asciidoctor.convert(DOCUMENT,
4848
OptionsBuilder.options()
4949
.headerFooter(true)

asciidoctorj-core/src/test/java/org/asciidoctor/util/TestHttpServer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private TestHttpServer(Map<String, File> resources) {
4646
.channel(NioServerSocketChannel.class)
4747
.childHandler(new ChannelInitializer<Channel>() {
4848
@Override
49-
protected void initChannel(Channel ch) throws Exception {
49+
protected void initChannel(Channel ch) {
5050
ChannelPipeline pipeline = ch.pipeline();
5151
pipeline.addLast("codec", new HttpServerCodec());
5252
pipeline.addLast("aggregator", new HttpObjectAggregator(MAX_MESSAGE_LENGTH));

asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/OptionsTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void options_for_pdf_document() throws Exception {
6666
}
6767

6868
@Test
69-
public void convert_in_unsafe_mode() throws Exception {
69+
public void convert_in_unsafe_mode() {
7070
//tag::unsafeConversion[]
7171
File sourceFile =
7272
//end::unsafeConversion[]
@@ -113,7 +113,7 @@ public void convert_to_dedicated_file() throws Exception {
113113
}
114114

115115
@Test
116-
public void use_font_awesome_icons() throws Exception {
116+
public void use_font_awesome_icons() {
117117
//tag::attributeFontIcons[]
118118
String result =
119119
asciidoctor.convert(
@@ -122,7 +122,7 @@ public void use_font_awesome_icons() throws Exception {
122122
"{foo}",
123123
Options.builder()
124124
.toFile(false)
125-
.headerFooter(false)
125+
.standalone(false)
126126
.attributes(
127127
Attributes.builder() // <1>
128128
.icons(Attributes.FONT_ICONS) // <2>

asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/YellBlockProcessorTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class YellBlockProcessorTest {
2424
private ClasspathResources classpathResources;
2525

2626
@Test
27-
public void should_invoke_block_processor() throws Exception {
27+
public void should_invoke_block_processor() {
2828
//tag::include[]
2929
File yellblock_adoc = //...
3030
//end::include[]
@@ -41,7 +41,7 @@ public void should_invoke_block_processor() throws Exception {
4141
}
4242

4343
@Test
44-
public void should_invoke_block_processor_with_attributes() throws Exception {
44+
public void should_invoke_block_processor_with_attributes() {
4545
File yellblock_adoc = //...
4646
classpathResources.getResource("yell-block-attributes.adoc");
4747

@@ -53,7 +53,7 @@ public void should_invoke_block_processor_with_attributes() throws Exception {
5353
}
5454

5555
@Test
56-
public void should_invoke_block_processor_with_positional_attributes() throws Exception {
56+
public void should_invoke_block_processor_with_positional_attributes() {
5757
File yellblock_adoc = //...
5858
classpathResources.getResource("yell-block-positional.adoc");
5959

asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/HighlightJsHighlighterTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class HighlightJsHighlighterTest {
3333
public TemporaryFolder tempDir;
3434

3535
@Test
36-
public void should_invoke_syntax_highlighter() throws Exception {
36+
public void should_invoke_syntax_highlighter() {
3737
//tag::include[]
3838
File sources_adoc = //...
3939
//end::include[]
@@ -56,7 +56,7 @@ public void should_invoke_syntax_highlighter() throws Exception {
5656
}
5757

5858
@Test
59-
public void should_invoke_syntax_highlighter_with_3_params() throws Exception {
59+
public void should_invoke_syntax_highlighter_with_3_params() {
6060
File sources_adoc =
6161
classpathResources.getResource("sources.adoc");
6262

@@ -75,7 +75,7 @@ public void should_invoke_syntax_highlighter_with_3_params() throws Exception {
7575
}
7676

7777
@Test
78-
public void should_invoke_formatting_syntax_highlighter() throws Exception {
78+
public void should_invoke_formatting_syntax_highlighter() {
7979
File sources_adoc =
8080
classpathResources.getResource("sources.adoc");
8181

0 commit comments

Comments
 (0)