Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsromero committed Jun 17, 2023
1 parent bbbd28a commit 34bfaca
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,4 @@ else if (value instanceof Boolean) {
attributesBuilder.attribute(attribute, value);
}
}

}
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 @@ -391,32 +391,7 @@ public void should_return_any_configuration_inside_asciidoc_node_as_option() {
}

@Test
public void should_return_and_format_any_maven_project_property_as_attribute_when_site_config_is_not_present() {
// given
final Map<String, String> projectProperties = new HashMap<>();
projectProperties.put("mvn.property-test1", "value-1");
projectProperties.put("mvn-property.test2", "value_2");
final MavenProject project = fakeProject(projectProperties);
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();

// when
SiteConversionConfiguration configuration = new SiteConversionConfigurationParser(project)
.processAsciiDocConfig(null, emptyOptions, emptyAttributes);

// then
final Map<String, Object> optionsMap = configuration.getOptions().map();
assertThat(optionsMap)
.containsOnlyKeys(ATTRIBUTES);
Map attributes = (Map) optionsMap.get(ATTRIBUTES);
assertThat(attributes).containsExactlyInAnyOrderEntriesOf(map(
entry("mvn-property-test1", "value-1"),
entry("mvn-property-test2", "value_2")
));
}

@Test
public void should_return_and_format_any_maven_project_property_as_attribute_when_site_config_is_present() {
public void should_return_and_format_any_maven_project_property_as_attribute() {
// given
final Map<String, String> projectProperties = new HashMap<>();
projectProperties.put("mvn.property-test1", "value-1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,11 @@ protected OptionsBuilder createOptionsBuilder(AsciidoctorMojo configuration, Att
optionsBuilder.templateDirs(templateDirs.toArray(new File[]{}));

optionsBuilder.attributes(attributesBuilder.build());

return optionsBuilder;
}


/**
* Creates an AttributesBuilder instance with the attributes defined in the configuration.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package org.asciidoctor.maven.test.processors;

import java.util.Map;

import org.asciidoctor.ast.Document;
import org.asciidoctor.extension.Preprocessor;
import org.asciidoctor.extension.PreprocessorReader;
import org.asciidoctor.extension.Reader;

import java.util.Map;

public class ChangeAttributeValuePreprocessor extends Preprocessor {

public static final String AUTHOR_NAME = "ThisIsMe";

public ChangeAttributeValuePreprocessor(Map<String, Object> config) {
super(config);
System.out.println(this.getClass().getSimpleName() + "("
System.out.println(this.getClass().getSimpleName() + "("
+ this.getClass().getSuperclass().getSimpleName() + ") initialized");
}

@Override
public void process(Document document, PreprocessorReader reader) {
System.out.println("Processing "+ this.getClass().getSimpleName());
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 @@ -15,10 +16,9 @@ public FailingPreprocessor(Map<String, Object> config) {
}

@Override
public void process(Document document, PreprocessorReader reader) {
System.out.println("Processing "+ this.getClass().getSimpleName());
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");
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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,12 +15,10 @@ public ManpageInlineMacroProcessor(String macroName) {
}

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

Map<String, Object> options = new HashMap<String, Object>();
public PhraseNode process(StructuralNode parent, String target, Map<String, Object> attributes) {
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 @@ -16,8 +16,8 @@ public class UriIncludeProcessor extends IncludeProcessor {

public UriIncludeProcessor(Map<String, Object> config) {
super(config);
System.out.println(this.getClass().getSimpleName() + "("
+ this.getClass().getSuperclass().getSimpleName() + ") initialized");
System.out.println(this.getClass().getSimpleName() + "("
+ this.getClass().getSuperclass().getSimpleName() + ") initialized");
}

@Override
Expand All @@ -29,10 +29,10 @@ public boolean handles(String target) {
public void process(Document document, PreprocessorReader reader, String target,
Map<String, Object> attributes) {

System.out.println("Processing "+ this.getClass().getSimpleName());
System.out.println("Processing " + this.getClass().getSimpleName());

StringBuilder content = readContent(target);
reader.push_include(content.toString(), target, target, 1, attributes);
reader.pushInclude(content.toString(), target, target, 1, attributes);

}

Expand Down Expand Up @@ -62,5 +62,4 @@ private StringBuilder readContent(String target) {
}
return content;
}

}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.java.version>11</project.java.version>
<project.execution.environment>JavaSE-1.8</project.execution.environment>
<asciidoctorj.version>2.5.10</asciidoctorj.version>
<asciidoctorj.version>3.0.0-alpha.1</asciidoctorj.version>
<jruby.version>9.4.2.0</jruby.version>
<maven.project.version>3.9.1</maven.project.version>
<maven.jacoco.plugin.version>0.8.8</maven.jacoco.plugin.version>
Expand Down

0 comments on commit 34bfaca

Please sign in to comment.