Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsromero committed Oct 5, 2024
1 parent b8a34e1 commit 0faf08f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.asciidoctor.maven.site;

import org.apache.maven.project.MavenProject;
import org.asciidoctor.Attributes;
import org.asciidoctor.AttributesBuilder;
import org.asciidoctor.Options;
import org.asciidoctor.OptionsBuilder;
Expand All @@ -9,7 +10,10 @@
import org.codehaus.plexus.util.xml.Xpp3Dom;

import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -29,17 +33,21 @@ public SiteConversionConfiguration processAsciiDocConfig(Xpp3Dom siteConfig,

AsciidoctorHelper.addProperties(project.getProperties(), presetAttributes);

final Xpp3Dom siteConfiguration = Optional.ofNullable(siteConfig)
.map(sc -> sc.getChild("asciidoc"))
.orElse(null);
final Attributes attributes = presetAttributes.build();

if (siteConfiguration == null) {
final OptionsBuilder options = presetOptions.attributes(presetAttributes.build());
return new SiteConversionConfiguration(options.build(), Collections.emptyList());
if (siteConfig == null) {
final Options options = presetOptions.attributes(attributes).build();
return new SiteConversionConfiguration(options, Collections.emptyList());
}

final Xpp3Dom asciidocConfig = siteConfig.getChild("asciidoc");
if (asciidocConfig == null) {
final Options options = presetOptions.attributes(attributes).build();
return new SiteConversionConfiguration(options, Collections.emptyList());
}

final List<String> gemsToRequire = new ArrayList<>();
for (Xpp3Dom asciidocOpt : siteConfiguration.getChildren()) {
for (Xpp3Dom asciidocOpt : asciidocConfig.getChildren()) {
String optName = asciidocOpt.getName();

if ("requires".equals(optName)) {
Expand Down Expand Up @@ -79,12 +87,12 @@ public SiteConversionConfiguration processAsciiDocConfig(Xpp3Dom siteConfig,
}
}

final Options options = presetOptions.attributes(presetAttributes.build()).build();
final Options options = presetOptions.attributes(attributes).build();
return new SiteConversionConfiguration(options, gemsToRequire);
}

private File resolveProjectDir(MavenProject project, String path) {
final File filePath = new File(path);
return !filePath.isAbsolute() ? new File(project.getBasedir(), filePath.toString()): filePath;
return !filePath.isAbsolute() ? new File(project.getBasedir(), filePath.toString()) : filePath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.asciidoctor.ast.Document;
import org.asciidoctor.extension.Preprocessor;
import org.asciidoctor.extension.PreprocessorReader;
import org.asciidoctor.extension.Reader;

import java.util.Map;

Expand All @@ -16,9 +17,10 @@ public ChangeAttributeValuePreprocessor(Map<String, Object> config) {
}

@Override
public void process(Document document, PreprocessorReader reader) {
public Reader process(Document document, PreprocessorReader reader) {
System.out.println("Processing " + this.getClass().getSimpleName());
System.out.println("Processing: blocks found: " + document.getBlocks().size());
document.getAttributes().put("author", AUTHOR_NAME);
return reader;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.asciidoctor.ast.Document;
import org.asciidoctor.extension.Preprocessor;
import org.asciidoctor.extension.PreprocessorReader;
import org.asciidoctor.extension.Reader;

import java.util.Map;

Expand All @@ -14,7 +15,7 @@ public FailingPreprocessor(Map<String, Object> config) {
}

@Override
public void process(Document document, PreprocessorReader reader) {
public Reader process(Document document, PreprocessorReader reader) {
System.out.println("Processing " + this.getClass().getSimpleName());
System.out.println("Processing: blocks found: " + document.getBlocks().size());
throw new RuntimeException("That's all folks");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.asciidoctor.maven.test.processors;

import org.asciidoctor.ast.ContentNode;
import org.asciidoctor.ast.PhraseNode;
import org.asciidoctor.ast.StructuralNode;
import org.asciidoctor.extension.InlineMacroProcessor;

import java.util.HashMap;
Expand All @@ -13,11 +14,10 @@ public ManpageInlineMacroProcessor(String macroName) {
}

@Override
public String process(ContentNode parent, String target, Map<String, Object> attributes) {

public PhraseNode process(StructuralNode parent, String target, Map<String, Object> attributes) {
final Map<String, Object> options = new HashMap<>();
options.put("type", ":link");
options.put("target", target + ".html");
return createPhraseNode(parent, "anchor", target, attributes, options).convert();
return createPhraseNode(parent, "anchor", target, attributes, options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void process(Document document, PreprocessorReader reader, String target,
Map<String, Object> attributes) {
System.out.println("Processing " + this.getClass().getSimpleName());
final String content = readContent(target);
reader.push_include(content, target, target, 1, attributes);
reader.pushInclude(content, target, target, 1, attributes);
}

private String readContent(String target) {
Expand Down
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.java.version>11</project.java.version>
<maven.project.version>3.9.1</maven.project.version>
<asciidoctorj.version>2.5.11</asciidoctorj.version>
<project.execution.environment>JavaSE-1.8</project.execution.environment>
<asciidoctorj.version>3.0.0</asciidoctorj.version>
<jruby.version>9.4.5.0</jruby.version>
<maven.project.version>3.9.1</maven.project.version>
</properties>

<dependencies>
Expand Down

0 comments on commit 0faf08f

Please sign in to comment.