Java Code Examples for org.asciidoctor.OptionsBuilder#options()

The following examples show how to use org.asciidoctor.OptionsBuilder#options() . 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: InspectorImpl.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private String swaggerToHtml(String swaggerContent) {
  if (asciidoctor == null) {
    synchronized (this) {
      if (asciidoctor == null) {
        // very slow, need a few seconds
        LOGGER.info("create AsciiDoctor start.");
        asciidoctor = Factory.create();
        asciidoctor.javaExtensionRegistry().docinfoProcessor(AppendStyleProcessor.class);
        LOGGER.info("create AsciiDoctor end.");
      }
    }
  }

  // swagger to markup
  Builder markupBuilder = Swagger2MarkupConverter.from(SwaggerUtils.parseSwagger(swaggerContent));
  // default not support cookie parameter
  // so must customize config
  Swagger2MarkupConfig markupConfig = new Swagger2MarkupConfigBuilder()
      .withParameterOrdering(Ordering
          .explicit("path", "query", "header", "cookie", "formData", "body")
          .onResultOf(Parameter::getIn))
      .build();
  String markup = markupBuilder.withConfig(markupConfig).build().toString();

  // markup to html
  OptionsBuilder builder = OptionsBuilder.options();
  builder.docType("book")
      .backend("html5")
      .headerFooter(true)
      .safe(SafeMode.UNSAFE)
      .attributes(AttributesBuilder.attributes()
          .attribute("toclevels", 3)
          .attribute(Attributes.TOC_2, true)
          .attribute(Attributes.TOC_POSITION, "left")
          .attribute(Attributes.LINK_CSS, true)
          .attribute(Attributes.STYLESHEET_NAME, inspectorConfig.getAsciidoctorCss())
          .attribute(Attributes.SECTION_NUMBERS, true)
          .attribute(Attributes.SECT_NUM_LEVELS, 4));
  return asciidoctor.convert(markup, builder.asMap());
}
 
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_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 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_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 12
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();
}