Skip to content

Commit

Permalink
Merge pull request #1162 from abelsromero/issue-1160-deprecate-header…
Browse files Browse the repository at this point in the history
…Footer-with-standalone-for-2.5.x

(v2.5.x) Deprecate 'headerFooter' in favour of 'standalone'
  • Loading branch information
robertpanzer authored Apr 7, 2023
2 parents 17dccb4 + e330544 commit 71d8558
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 149 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co

== Unreleased

Improvement::

* Add 'standalone' option, deprecates 'headerFooter' (#1160) (@abelsromero)

Bug Fixes::

* Fix destinationDir not having effect. Deprecate destinationDir in favour of toDir (#853, #941) (@abelsromero)

== 2.5.7 (2022-10-21)

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

Bug Fixes::
* Fix destinationDir not having effect. Deprecate destinationDir in favour of toDir (@abelsromero) (#853, #941)

Build / Infrastructure::

* Replace use of deprecated 'numbered' attribute by 'sectnums' (#1127) (@abelsromero)
Expand Down
16 changes: 14 additions & 2 deletions asciidoctorj-api/src/main/java/org/asciidoctor/Options.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.asciidoctor;

import java.io.File;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -71,6 +70,19 @@ public void setAttributes(Map<String, Object> attributes) {
this.options.put(ATTRIBUTES, attributes);
}

/**
* Toggle including header and footer into the output.
*
* @param standalone <code>true</code> to generate a standalone output document
* (which includes the shell around the body content, such
* as the header and footer).
* Defaults to <code>true</code> when converting a file only,
* otherwise is <code>false</code>.
*/
public void setStandalone(boolean standalone) {
this.options.put(STANDALONE, standalone);
}

/**
* Toggle including header and footer into the output.
*
Expand All @@ -85,7 +97,7 @@ public void setHeaderFooter(boolean headerFooter) {
public void setTemplateDirs(String... templateDirs) {

if (!this.options.containsKey(TEMPLATE_DIRS)) {
this.options.put(TEMPLATE_DIRS, new ArrayList<Object>());
this.options.put(TEMPLATE_DIRS, new ArrayList<>());
}

List<Object> allTemplateDirs = (List<Object>) this.options.get(TEMPLATE_DIRS);
Expand Down
22 changes: 19 additions & 3 deletions asciidoctorj-api/src/main/java/org/asciidoctor/OptionsBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,28 @@ public OptionsBuilder inPlace(boolean inPlace) {
return this;
}

/**
* Toggle including header and footer into the output.
*
* @param standalone <code>true</code> to generate a standalone output document
* (which includes the shell around the body content, such
* as the header and footer).
* Defaults to <code>true</code> when converting a file only,
* otherwise is <code>false</code>.
*/
public OptionsBuilder standalone(boolean standalone) {
this.options.setStandalone(standalone);
return this;
}

/**
* Sets header footer attribute.
*
* @param headerFooter
* value.
*
* @param headerFooter value.
* @return this instance.
* @deprecated Use {@link #standalone(boolean)} instead.
*/
@Deprecated
public OptionsBuilder headerFooter(boolean headerFooter) {
this.options.setHeaderFooter(headerFooter);
return this;
Expand All @@ -80,6 +95,7 @@ public OptionsBuilder headerFooter(boolean headerFooter) {
* directory where templates are stored.
* @return this instance.
*/
@Deprecated
public OptionsBuilder templateDir(File templateDir) {
this.options.setTemplateDirs(templateDir.getAbsolutePath());
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
package org.asciidoctor.jruby.internal;

import org.asciidoctor.Options;
import org.asciidoctor.SafeMode;
import org.asciidoctor.jruby.cli.AsciidoctorCliOptions;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.asciidoctor.Options;
import org.asciidoctor.SafeMode;
import org.asciidoctor.jruby.cli.AsciidoctorCliOptions;

public class AsciidoctorUtils {

private static final String RUNNER = "asciidoctor";

private AsciidoctorUtils() {
super();
}

public static boolean isOptionWithAttribute(Map<String, Object> options, String attributeName, String attributeValue) {

if(options.containsKey(Options.ATTRIBUTES)) {
Map<String, Object> attributes = (Map<String, Object>) options.get(Options.ATTRIBUTES);

if(attributes.containsKey(attributeName)) {
String configuredAttributeValue = (String) attributes.get(attributeName);

if(configuredAttributeValue.equals(attributeValue)) {
return true;
}

}

}

return false;
}

public static List<String> toAsciidoctorCommand(Map<String, Object> options,
String inputPath) {

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

if (options.containsKey(Options.TEMPLATE_DIRS)) {
List<String> templates = (List<String>) options.get(Options.TEMPLATE_DIRS);

for (String template : templates) {
optionsAndAttributes.add(AsciidoctorCliOptions.TEMPLATE_DIR);
optionsAndAttributes.add(template);
Expand All @@ -86,7 +86,7 @@ private static List<String> getOptions(Map<String, Object> options) {
optionsAndAttributes.add(options.get(Options.ERUBY).toString());
}

if (options.containsKey(Options.HEADER_FOOTER)) {
if (options.containsKey(Options.STANDALONE) || options.containsKey(Options.HEADER_FOOTER)) {
optionsAndAttributes.add(AsciidoctorCliOptions.NO_HEADER_FOOTER);
}

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

return optionsAndAttributes;

}

private static List<String> getAttributesSyntax(Map<String, Object> attributes) {
List<String> attributesOutput = new ArrayList<>();

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

if (attributeValue != null && !"".equals(attributeValue.toString().trim())) {
argument.append("=");
argument.append(attributeValue.toString());
argument.append(attributeValue);
}

if(attributeValue == null) {
argument.append("!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void shouldOnlyNotifyFromRegisteredAsciidoctor() throws Exception {
}

@Test
public void shouldNoLongerNotifyAfterUnregisterOnlyNotifyFromRegisteredAsciidoctor() throws Exception {
public void shouldNoLongerNotifyAfterUnregisterOnlyNotifyFromRegisteredAsciidoctor() {

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

Expand Down Expand Up @@ -274,7 +274,7 @@ public Object process(StructuralNode parent, Reader reader, Map<String, Object>
}

@Test
public void a_extension_should_be_able_to_log() throws Exception {
public void a_extension_should_be_able_to_log() {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class WhenSourceHighlightingIsUsed {
private Asciidoctor asciidoctor;

@Test
public void should_render_with_rouge() throws Exception {
public void should_render_with_rouge() {
String html = asciidoctor.convert(DOCUMENT,
OptionsBuilder.options()
.headerFooter(true)
Expand All @@ -43,7 +43,7 @@ public void should_render_with_rouge() throws Exception {
}

@Test
public void should_render_with_coderay() throws Exception {
public void should_render_with_coderay() {
String html = asciidoctor.convert(DOCUMENT,
OptionsBuilder.options()
.headerFooter(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private TestHttpServer(Map<String, File> resources) {
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
protected void initChannel(Channel ch) {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("codec", new HttpServerCodec());
pipeline.addLast("aggregator", new HttpObjectAggregator(MAX_MESSAGE_LENGTH));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void options_for_pdf_document() throws Exception {
}

@Test
public void convert_in_unsafe_mode() throws Exception {
public void convert_in_unsafe_mode() {
//tag::unsafeConversion[]
File sourceFile =
//end::unsafeConversion[]
Expand Down Expand Up @@ -113,7 +113,7 @@ public void convert_to_dedicated_file() throws Exception {
}

@Test
public void use_font_awesome_icons() throws Exception {
public void use_font_awesome_icons() {
//tag::attributeFontIcons[]
String result =
asciidoctor.convert(
Expand All @@ -122,7 +122,7 @@ public void use_font_awesome_icons() throws Exception {
"{foo}",
Options.builder()
.toFile(false)
.headerFooter(false)
.standalone(false)
.attributes(
Attributes.builder() // <1>
.icons(Attributes.FONT_ICONS) // <2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class YellBlockProcessorTest {
private ClasspathResources classpathResources;

@Test
public void should_invoke_block_processor() throws Exception {
public void should_invoke_block_processor() {
//tag::include[]
File yellblock_adoc = //...
//end::include[]
Expand All @@ -41,7 +41,7 @@ public void should_invoke_block_processor() throws Exception {
}

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

Expand All @@ -53,7 +53,7 @@ public void should_invoke_block_processor_with_attributes() throws Exception {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class HighlightJsHighlighterTest {
public TemporaryFolder tempDir;

@Test
public void should_invoke_syntax_highlighter() throws Exception {
public void should_invoke_syntax_highlighter() {
//tag::include[]
File sources_adoc = //...
//end::include[]
Expand All @@ -56,7 +56,7 @@ public void should_invoke_syntax_highlighter() throws Exception {
}

@Test
public void should_invoke_syntax_highlighter_with_3_params() throws Exception {
public void should_invoke_syntax_highlighter_with_3_params() {
File sources_adoc =
classpathResources.getResource("sources.adoc");

Expand All @@ -75,7 +75,7 @@ public void should_invoke_syntax_highlighter_with_3_params() throws Exception {
}

@Test
public void should_invoke_formatting_syntax_highlighter() throws Exception {
public void should_invoke_formatting_syntax_highlighter() {
File sources_adoc =
classpathResources.getResource("sources.adoc");

Expand Down
Loading

0 comments on commit 71d8558

Please sign in to comment.