Skip to content

Commit

Permalink
Merge pull request asciidoctor#1207 from abelsromero/issue-1201-remov…
Browse files Browse the repository at this point in the history
…e-deprecated-from-Asciidoctor-interface

Remove deprecated from Asciidoctor interface
  • Loading branch information
robertpanzer committed May 30, 2023
2 parents d6ce35e + fbd2838 commit 8e336da
Show file tree
Hide file tree
Showing 37 changed files with 361 additions and 814 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Improvement::
* Return Document AST when using convert or convertFile with appropriate options (#1171) (@abelsromero)
* Expose Links in the catalog (#1183) (@abelsromero)
* BREAKING: Remove deprecated methods in Options, OptionsBuilder, Attributes & AttributesBuilder (#1199) (@abelsromero)
* BREAKING: Remove deprecated Asciidoctor interface (#1201) (@abelsromero)

Bug Fixes::

Expand Down
310 changes: 1 addition & 309 deletions asciidoctorj-api/src/main/java/org/asciidoctor/Asciidoctor.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class Attributes {
public static final String HIDE_URI_SCHEME = "hide-uri-scheme";
public static final String COMPAT_MODE = "compat-mode";

private Map<String, Object> attributes = new LinkedHashMap<>();
private final Map<String, Object> attributes = new LinkedHashMap<>();

Attributes() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Options {
public static final String PARSE = "parse";
public static final String PARSE_HEADER_ONLY = "parse_header_only";

private Map<String, Object> options = new HashMap<>();
private final Map<String, Object> options = new HashMap<>();

Options() {
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import org.asciidoctor.Attributes;
import org.asciidoctor.Options;
import org.asciidoctor.OptionsBuilder;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.DocumentHeader;
import org.asciidoctor.converter.JavaConverterRegistry;
import org.asciidoctor.extension.ExtensionGroup;
import org.asciidoctor.extension.JavaExtensionRegistry;
import org.asciidoctor.extension.RubyExtensionRegistry;
import org.asciidoctor.jruby.AsciidoctorJRuby;
import org.asciidoctor.jruby.ast.impl.DocumentHeaderImpl;
import org.asciidoctor.jruby.ast.impl.NodeConverter;
import org.asciidoctor.jruby.converter.internal.ConverterRegistryExecutor;
import org.asciidoctor.jruby.extension.internal.ExtensionRegistryExecutor;
Expand Down Expand Up @@ -161,50 +158,7 @@ public Ruby getRubyRuntime() {
return rubyRuntime;
}

private DocumentHeader toDocumentHeader(Document document) {

Document documentImpl = (Document) NodeConverter.createASTNode(document);

return DocumentHeaderImpl.createDocumentHeader(
documentImpl.getStructuredDoctitle(),
documentImpl.getDoctitle(),
documentImpl.getAuthors(),
document.getAttributes());
}

@SuppressWarnings("unchecked")
@Override
public DocumentHeader readDocumentHeader(File file) {

RubyHash rubyHash = getParseHeaderOnlyOption();

Document document = (Document) NodeConverter.createASTNode(getAsciidoctorModule().callMethod("load_file", rubyRuntime.newString(file.getAbsolutePath()), rubyHash));

return toDocumentHeader(document);
}

@Override
public DocumentHeader readDocumentHeader(String content) {

RubyHash rubyHash = getParseHeaderOnlyOption();

Document document = (Document) NodeConverter.createASTNode(getAsciidoctorModule().callMethod("load", rubyRuntime.newString(content), rubyHash));
return toDocumentHeader(document);
}

@Override
public DocumentHeader readDocumentHeader(Reader contentReader) {
String content = IOUtils.readFull(contentReader);
return this.readDocumentHeader(content);
}

private RubyHash getParseHeaderOnlyOption() {
Map<String, Object> options = new HashMap<>();
options.put("parse_header_only", true);
return RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);
}

private List<String> convertAllFiles(Map<String, Object> options, final Iterable<File> asciidoctorFiles) {
private List<String> convertAllFiles(Options options, final Iterable<File> asciidoctorFiles) {
List<String> asciidoctorContent = new ArrayList<>();
for (File asciidoctorFile : asciidoctorFiles) {
String renderedFile = convertFile(asciidoctorFile, options);
Expand Down Expand Up @@ -272,11 +226,6 @@ private RubyModule getAsciidoctorModule() {
return rubyRuntime.getModule("Asciidoctor");
}

@Override
public String convert(String content, Map<String, Object> options) {
return convert(content, options, String.class);
}

public <T> T convert(String content, Map<String, Object> options, Class<T> expectedResult) {

this.rubyGemsPreloader.preloadRequiredLibraries(options);
Expand Down Expand Up @@ -330,39 +279,14 @@ public <T> T convert(String content, Options options, Class<T> expectedResult) {
return convert(content, options.map(), expectedResult);
}

@Override
public String convert(String content, OptionsBuilder options) {
return convert(content, options, String.class);
}

@Override
public <T> T convert(String content, OptionsBuilder options, Class<T> expectedResult) {
return convert(content, options.build(), expectedResult);
}

@Override
public void convert(Reader contentReader, Writer rendererWriter, Map<String, Object> options) throws IOException {
String content = IOUtils.readFull(contentReader);
String renderedContent = convert(content, options);
IOUtils.writeFull(rendererWriter, renderedContent);
}

@Override
public void convert(Reader contentReader, Writer rendererWriter, Options options) throws IOException {
this.convert(contentReader, rendererWriter, options.map());
}

@Override
public void convert(Reader contentReader, Writer rendererWriter, OptionsBuilder options) throws IOException {
this.convert(contentReader, rendererWriter, options.build());
}

@Override
public String convertFile(File file, Map<String, Object> options) {
return convertFile(file, options, String.class);
final String content = IOUtils.readFull(contentReader);
final String renderedContent = convert(content, options);
IOUtils.writeFull(rendererWriter, renderedContent);
}

@Override
// @Override
public <T> T convertFile(File file, Map<String, Object> options, Class<T> expectedResult) {

this.rubyGemsPreloader.preloadRequiredLibraries(options);
Expand Down Expand Up @@ -419,53 +343,16 @@ public <T> T convertFile(File file, Options options, Class<T> expectedResult) {
return convertFile(file, options.map(), expectedResult);
}

@Override
public String convertFile(File file, OptionsBuilder options) {
return convertFile(file, options.build(), String.class);
}

@Override
public <T> T convertFile(File file, OptionsBuilder options, Class<T> expectedResult) {
return convertFile(file, options.build(), expectedResult);
}

@Override
public String[] convertDirectory(Iterable<File> directoryWalker, Map<String, Object> options) {
List<String> asciidoctorContent = convertAllFiles(options, directoryWalker);
return asciidoctorContent.toArray(new String[0]);
}

@Override
public String[] convertDirectory(Iterable<File> directoryWalker, Options options) {
return convertDirectory(directoryWalker, options.map());
}

@Override
public String[] convertDirectory(Iterable<File> directoryWalker, OptionsBuilder options) {
return convertDirectory(directoryWalker, options.build());
}

@Override
public String[] convertFiles(Collection<File> files, Map<String, Object> options) {
List<String> asciidoctorContent = convertAllFiles(options, files);
List<String> asciidoctorContent = convertAllFiles(options, directoryWalker);
return asciidoctorContent.toArray(new String[0]);
}

@Override
public String[] convertFiles(Collection<File> asciidoctorFiles, Options options) {
return convertFiles(asciidoctorFiles, options.map());
}

@Override
public String[] convertFiles(Collection<File> files, OptionsBuilder options) {
return convertFiles(files, options.build());
}

@Override
public Document load(String content, Map<String, Object> options) {
RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);
return (Document) NodeConverter.createASTNode(getAsciidoctorModule().callMethod("load",
rubyRuntime.newString(content), rubyHash));
List<String> asciidoctorContent = convertAllFiles(options, asciidoctorFiles);
return asciidoctorContent.toArray(new String[0]);
}

@Override
Expand All @@ -475,18 +362,9 @@ public Document load(String content, Options options) {
Optional.ofNullable(content).map(rubyRuntime::newString).orElse(null), rubyHash));
}

@Override
public Document loadFile(File file, Map<String, Object> options) {
RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);

return (Document) NodeConverter.createASTNode(getAsciidoctorModule().callMethod("load_file",
rubyRuntime.newString(file.getAbsolutePath()), rubyHash));
}

@Override
public Document loadFile(File file, Options options) {
RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options.map());

return (Document) NodeConverter.createASTNode(getAsciidoctorModule().callMethod("load_file",
rubyRuntime.newString(file.getAbsolutePath()), rubyHash));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.asciidoctor


import org.asciidoctor.ast.Section
import spock.lang.Specification

import static org.asciidoctor.util.OptionsTestHelper.emptyOptions

class WhenADocumentContainsNumberedSections extends Specification {

private Asciidoctor asciidoctor = Asciidoctor.Factory.create()
Expand All @@ -18,7 +21,7 @@ class WhenADocumentContainsNumberedSections extends Specification {
'''.stripIndent()

when:
def document = asciidoctor.load source, [:]
def document = asciidoctor.load(source, emptyOptions())

then:
final appendix = (Section) document.blocks[0]
Expand All @@ -36,7 +39,7 @@ class WhenADocumentContainsNumberedSections extends Specification {
'''.stripIndent()

when:
def document = asciidoctor.load source, [:]
def document = asciidoctor.load(source, emptyOptions())

then:
final section = (Section) document.blocks[0]
Expand All @@ -58,7 +61,7 @@ class WhenADocumentContainsNumberedSections extends Specification {
'''.stripIndent()

when:
def document = asciidoctor.load source, [:]
def document = asciidoctor.load(source, emptyOptions())

then:
final part = (Section) document.blocks[0]
Expand Down
Loading

0 comments on commit 8e336da

Please sign in to comment.