Java Code Examples for org.asciidoctor.AttributesBuilder#attributes()

The following examples show how to use org.asciidoctor.AttributesBuilder#attributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_default_configuration_when_site_xml_is_null() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();

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

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES);
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
    assertThat(configuration.getRequires()).isEmpty();
}
 
Example 2
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_default_configuration_when_asciidoc_xml_is_null() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.siteNode()
            .build();
    // when
    SiteConversionConfiguration configuration = new SiteConversionConfigurationParser(project)
            .processAsciiDocConfig(siteConfig, emptyOptions, emptyAttributes);

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES);
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
    assertThat(configuration.getRequires()).isEmpty();
}
 
Example 3
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_simple_single_requires() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
            .addChild("requires")
            .addChild("require", "gem")
            .build();

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

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES);
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
    assertThat(configuration.getRequires())
            .containsExactly("gem");
}
 
Example 4
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_multiple_requires() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
            .addChild("requires")
            .addChild("require", "gem_1", "gem_2", "gem_3")
            .build();

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

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES);
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
    assertThat(configuration.getRequires())
            .containsExactlyInAnyOrder("gem_1", "gem_2", "gem_3");
}
 
Example 5
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_multiple_requires_when_defined_in_single_element() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
            .addChild("requires")
            .addChild("require", "gem_1,gem_2, gem_3")
            .build();

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

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES);
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
    assertThat(configuration.getRequires())
            .containsExactlyInAnyOrder("gem_1", "gem_2", "gem_3");
}
 
Example 6
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_remove_empty_and_blank_requires() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
            .addChild("requires")
            .addChild("require", "gem_1,,gem_2", "", ",,", "gem_3")
            .build();

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

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES);
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
    assertThat(configuration.getRequires())
            .containsExactlyInAnyOrder("gem_1", "gem_2", "gem_3");
}
 
Example 7
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_not_return_empty_template_dirs() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
            .addChild("template_dirs")
            .addChild("dir", "")
            .parent()
            .addChild("dir", null)
            .build();

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

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES);
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
}
 
Example 8
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_baseDir_dirs_when_defined_as_template_dirs_dir() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
            .addChild("baseDir", "path")
            .build();

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

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();

    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES, BASEDIR);
    assertThat(optionsMap.get(BASEDIR))
            .isEqualTo(new File("path").getAbsolutePath());
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
}
 
Example 9
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_template_dirs_when_defined_as_templateDirs_dir() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
            .addChild("templateDirs")
            .addChild("dir", "path")
            .parent()
            .addChild("dir", "path2")
            .build();

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

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES, TEMPLATE_DIRS);
    assertThat(optionsMap.get(TEMPLATE_DIRS))
            .isEqualTo(Arrays.asList(
                    new File("path").getAbsolutePath(),
                    new File("path2").getAbsolutePath()
            ));
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
}
 
Example 10
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_template_dirs_when_defined_as_template_dirs_dir() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
            .addChild("template_dirs")
            .addChild("dir", "path")
            .parent()
            .addChild("dir", "path2")
            .build();

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

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES, TEMPLATE_DIRS);
    assertThat(optionsMap.get(TEMPLATE_DIRS))
            .isEqualTo(Arrays.asList(
                    new File("path").getAbsolutePath(),
                    new File("path2").getAbsolutePath()
            ));
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
}
 
Example 11
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_any_configuration_inside_asciidoc_node_as_option() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
            .addChild("option-1", "value-1")
            .parent().addChild("option_2", "value-2")
            .parent().addChild("_option-3", "value-3")
            .parent().addChild("option-4_", "value-4")
            .parent().addChild("option.5", "value-5")
            .build();

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

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap)
            .containsOnlyKeys(ATTRIBUTES, "option-1", "option_2", "_option-3", "option-4_", "option.5");
    assertThat(optionsMap.get("option-1")).isEqualTo("value-1");
    assertThat(optionsMap.get("option_2")).isEqualTo("value-2");
    assertThat(optionsMap.get("_option-3")).isEqualTo("value-3");
    assertThat(optionsMap.get("option-4_")).isEqualTo("value-4");
    assertThat(optionsMap.get("option.5")).isEqualTo("value-5");
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
}
 
Example 12
Source File: AsciidoctorCliOptions.java    From asciidoctorj with Apache License 2.0 4 votes vote down vote up
public Options parse() {
    AttributesBuilder attributesBuilder = AttributesBuilder.attributes();

    OptionsBuilder optionsBuilder = OptionsBuilder.options()
        .backend(this.backend)
        .safe(this.safeMode)
        .eruby(this.eruby)
        .option(Options.STANDALONE, true);

    if (isDoctypeOption()) {
        optionsBuilder.docType(this.doctype);
    }

    if (isInputStdin()) {
        optionsBuilder.toStream(System.out);
        if (outFile == null) {
            outFile = "-";
        }
    }

    if (isOutFileOption() && !isOutputStdout()) {
        optionsBuilder.toFile(new File(this.outFile));
    }

    if (isOutputStdout()) {
        optionsBuilder.toStream(System.out);
    }

    if (this.safe) {
        optionsBuilder.safe(SafeMode.SAFE);
    }

    if (this.noHeaderFooter) {
        optionsBuilder.option(Options.STANDALONE, false);
    }

    if (this.sectionNumbers) {
        attributesBuilder.sectionNumbers(this.sectionNumbers);
    }

    if (this.compact) {
        optionsBuilder.compact(this.compact);
    }

    if (isBaseDirOption()) {
        optionsBuilder.baseDir(new File(this.baseDir));
    }

    if (isTemplateEngineOption()) {
        optionsBuilder.templateEngine(this.templateEngine);
    }

    if (isTemplateDirOption()) {
        for (String templateDir : this.templateDir) {
            optionsBuilder.templateDir(new File(templateDir));
        }
    }

    if (isDestinationDirOption() && !isOutputStdout()) {
        optionsBuilder.toDir(new File(this.destinationDir));

        if(isSourceDirOption()) {
            optionsBuilder.sourceDir(new File(this.sourceDir));
        }
    }

    if (isInPlaceRequired()) {
        optionsBuilder.inPlace(true);
    }

    attributesBuilder.attributes(getAttributes());
    optionsBuilder.attributes(attributesBuilder.get());
    return optionsBuilder.get();

}
 
Example 13
Source File: AsciidoctorCliOptions.java    From asciidoctorj with Apache License 2.0 4 votes vote down vote up
public Options parse() {
    AttributesBuilder attributesBuilder = AttributesBuilder.attributes();

    OptionsBuilder optionsBuilder = OptionsBuilder.options()
        .backend(this.backend)
        .safe(this.safeMode)
        .eruby(this.eruby)
        .option(Options.STANDALONE, true);

    if (isDoctypeOption()) {
        optionsBuilder.docType(this.doctype);
    }

    if (isInputStdin()) {
        optionsBuilder.toStream(System.out);
        if (outFile == null) {
            outFile = "-";
        }
    }

    if (isOutFileOption() && !isOutputStdout()) {
        optionsBuilder.toFile(new File(this.outFile));
    }

    if (isOutputStdout()) {
        optionsBuilder.toStream(System.out);
    }

    if (this.safe) {
        optionsBuilder.safe(SafeMode.SAFE);
    }

    if (this.noHeaderFooter) {
        optionsBuilder.option(Options.STANDALONE, false);
    }

    if (this.sectionNumbers) {
        attributesBuilder.sectionNumbers(this.sectionNumbers);
    }

    if (this.compact) {
        optionsBuilder.compact(this.compact);
    }

    if (isBaseDirOption()) {
        optionsBuilder.baseDir(new File(this.baseDir));
    }

    if (isTemplateEngineOption()) {
        optionsBuilder.templateEngine(this.templateEngine);
    }

    if (isTemplateDirOption()) {
        for (String templateDir : this.templateDir) {
            optionsBuilder.templateDir(new File(templateDir));
        }
    }

    if (isDestinationDirOption() && !isOutputStdout()) {
        optionsBuilder.toDir(new File(this.destinationDir));

        if(isSourceDirOption()) {
            optionsBuilder.sourceDir(new File(this.sourceDir));
        }
    }

    if (isInPlaceRequired()) {
        optionsBuilder.inPlace(true);
    }

    attributesBuilder.attributes(getAttributes());
    optionsBuilder.attributes(attributesBuilder.get());
    return optionsBuilder.get();

}