Java Code Examples for org.asciidoctor.ast.StructuralNode#append()
The following examples show how to use
org.asciidoctor.ast.StructuralNode#append() .
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: MediaContentComponent.java From swagger2markup with Apache License 2.0 | 6 votes |
@Override public StructuralNode apply(StructuralNode node, MediaContentComponent.Parameters parameters) { Content content = parameters.content; if (content == null || content.isEmpty()) return node; DescriptionListImpl mediaContentList = new DescriptionListImpl(node); mediaContentList.setTitle(labels.getLabel(LABEL_CONTENT)); content.forEach((type, mediaType) -> { DescriptionListEntryImpl tagEntry = new DescriptionListEntryImpl(mediaContentList, Collections.singletonList(new ListItemImpl(mediaContentList, type))); ListItemImpl tagDesc = new ListItemImpl(tagEntry, ""); Document tagDescDocument = schemaComponent.apply(mediaContentList, mediaType.getSchema()); mediaTypeExampleComponent.apply(tagDescDocument, mediaType.getExample()); examplesComponent.apply(tagDescDocument, mediaType.getExamples()); encodingComponent.apply(tagDescDocument, mediaType.getEncoding()); tagDesc.append(tagDescDocument); tagEntry.setDescription(tagDesc); mediaContentList.addEntry(tagEntry); }); node.append(mediaContentList); return node; }
Example 2
Source File: HeadersComponent.java From swagger2markup with Apache License 2.0 | 6 votes |
@Override public StructuralNode apply(StructuralNode node, HeadersComponent.Parameters parameters) { Map<String, Header> headers = parameters.headers; if (null == headers || headers.isEmpty()) return node; TableImpl responseHeadersTable = new TableImpl(node, new HashMap<>(), new ArrayList<>()); responseHeadersTable.setOption("header"); responseHeadersTable.setAttribute("caption", "", true); responseHeadersTable.setAttribute("cols", ".^2a,.^14a,.^4a", true); responseHeadersTable.setTitle(labels.getLabel(TABLE_TITLE_HEADERS)); responseHeadersTable.setHeaderRow(labels.getLabel(TABLE_HEADER_NAME), labels.getLabel(TABLE_HEADER_DESCRIPTION), labels.getLabel(TABLE_HEADER_SCHEMA)); headers.forEach((name, header) -> responseHeadersTable.addRow( generateInnerDoc(responseHeadersTable, name), generateInnerDoc(responseHeadersTable, Optional.ofNullable(header.getDescription()).orElse("")), generateInnerDoc(responseHeadersTable, getSchemaTypeAsString(header.getSchema())) )); node.append(responseHeadersTable); return node; }
Example 3
Source File: ResponseComponent.java From swagger2markup with Apache License 2.0 | 6 votes |
@Override public StructuralNode apply(StructuralNode serverSection, Parameters params) { Map<String, ApiResponse> apiResponses = params.apiResponses; if (null == apiResponses || apiResponses.isEmpty()) return serverSection; TableImpl pathResponsesTable = new TableImpl(serverSection, new HashMap<>(), new ArrayList<>()); pathResponsesTable.setOption("header"); pathResponsesTable.setAttribute("caption", "", true); pathResponsesTable.setAttribute("cols", ".^2a,.^14a,.^4a", true); pathResponsesTable.setTitle(labels.getLabel(TABLE_TITLE_RESPONSES)); pathResponsesTable.setHeaderRow( labels.getLabel(TABLE_HEADER_HTTP_CODE), labels.getLabel(TABLE_HEADER_DESCRIPTION), labels.getLabel(TABLE_HEADER_LINKS)); apiResponses.forEach((httpCode, apiResponse) -> pathResponsesTable.addRow( generateInnerDoc(pathResponsesTable, httpCode), getResponseDescriptionColumnDocument(pathResponsesTable, apiResponse), linkComponent.apply(pathResponsesTable, apiResponse.getLinks()) )); serverSection.append(pathResponsesTable); return serverSection; }
Example 4
Source File: PathsDocument.java From swagger2markup with Apache License 2.0 | 6 votes |
private void appendServersSection(StructuralNode node, List<Server> servers) { if (null == servers || servers.isEmpty()) return; Section serversSection = new SectionImpl(node); serversSection.setTitle(labels.getLabel(SECTION_TITLE_SERVERS)); servers.forEach(server -> { Section serverSection = new SectionImpl(serversSection); serverSection.setTitle(italicUnconstrained(labels.getLabel(LABEL_SERVER)) + ": " + server.getUrl()); appendDescription(serverSection, server.getDescription()); ServerVariables variables = server.getVariables(); appendVariables(serverSection, variables); serversSection.append(serverSection); }); node.append(serversSection); }
Example 5
Source File: OpenApiHelpers.java From swagger2markup with Apache License 2.0 | 5 votes |
public static void appendDescription(StructuralNode node, String description) { if (StringUtils.isNotBlank(description)) { Block paragraph = new ParagraphBlockImpl(node); paragraph.setSource(description); node.append(paragraph); } }
Example 6
Source File: MediaTypeExampleComponent.java From swagger2markup with Apache License 2.0 | 5 votes |
@Override public StructuralNode apply(StructuralNode node, MediaTypeExampleComponent.Parameters parameters) { Object example = parameters.example; if (example == null || StringUtils.isBlank(example.toString())) return node; ParagraphBlockImpl sourceBlock = new ParagraphBlockImpl(node); sourceBlock.setTitle(labels.getLabel(LABEL_EXAMPLE)); sourceBlock.setAttribute("style", "source", true); sourceBlock.setSource(DELIMITER_BLOCK + LINE_SEPARATOR + example + LINE_SEPARATOR + DELIMITER_BLOCK); node.append(sourceBlock); return node; }
Example 7
Source File: SecurityRequirementTableComponent.java From swagger2markup with Apache License 2.0 | 5 votes |
@Override public StructuralNode apply(StructuralNode node, SecurityRequirementTableComponent.Parameters parameters) { List<SecurityRequirement> securityRequirements = parameters.securityRequirements; if (securityRequirements == null || securityRequirements.isEmpty()) return node; TableImpl securityRequirementsTable = new TableImpl(node, new HashMap<>(), new ArrayList<>()); securityRequirementsTable.setOption("header"); securityRequirementsTable.setAttribute("caption", "", true); securityRequirementsTable.setAttribute("cols", ".^3a,.^4a,.^13a", true); if (parameters.addTitle) { securityRequirementsTable.setTitle(labels.getLabel(TABLE_TITLE_SECURITY)); } securityRequirementsTable.setHeaderRow( labels.getLabel(TABLE_HEADER_TYPE), labels.getLabel(TABLE_HEADER_NAME), labels.getLabel(TABLE_HEADER_SCOPES)); securityRequirements.forEach(securityRequirement -> securityRequirement.forEach((name, scopes) -> securityRequirementsTable.addRow( generateInnerDoc(securityRequirementsTable, boldUnconstrained(scopes.isEmpty() ? "apiKey" : "oauth2")), generateInnerDoc(securityRequirementsTable, name), generateInnerDoc(securityRequirementsTable, String.join(", ", scopes)) ) ) ); node.append(securityRequirementsTable); return node; }
Example 8
Source File: ExternalDocumentationComponent.java From swagger2markup with Apache License 2.0 | 5 votes |
@Override public StructuralNode apply(StructuralNode node, Parameters params) { ExternalDocumentation externalDocs = params.externalDocs; if (externalDocs == null) return node; String url = externalDocs.getUrl(); if (StringUtils.isNotBlank(url)) { Block paragraph = new ParagraphBlockImpl(node); String desc = externalDocs.getDescription(); paragraph.setSource(url + (StringUtils.isNotBlank(desc) ? "[" + desc + "]" : "")); node.append(paragraph); } return node; }
Example 9
Source File: PropertiesTableComponent.java From swagger2markup with Apache License 2.0 | 5 votes |
public StructuralNode apply(StructuralNode parent, Parameters params) { @SuppressWarnings("rawtypes") Map<String, Schema> properties = params.properties; List<String> schemaRequired = params.schemaRequired; if (null == properties || properties.isEmpty()) return parent; List<String> finalSchemaRequired = (null == schemaRequired) ? new ArrayList<>() : schemaRequired; TableImpl propertiesTable = new TableImpl(parent, new HashMap<>(), new ArrayList<>()); propertiesTable.setOption("header"); propertiesTable.setAttribute("caption", "", true); propertiesTable.setAttribute("cols", ".^4a,.^16a,.^4a", true); propertiesTable.setTitle(labels.getLabel(TABLE_TITLE_PROPERTIES)); propertiesTable.setHeaderRow( labels.getLabel(TABLE_HEADER_NAME), labels.getLabel(TABLE_HEADER_DESCRIPTION), labels.getLabel(TABLE_HEADER_SCHEMA)); properties.forEach((name, schema) -> propertiesTable.addRow( generateInnerDoc(propertiesTable, name + LINE_SEPARATOR + requiredIndicator(finalSchemaRequired.contains(name), labels.getLabel(LABEL_REQUIRED), labels.getLabel(LABEL_OPTIONAL))), schemaComponent.apply(propertiesTable, schema), generateInnerDoc(propertiesTable, getSchemaTypeAsString(schema)) )); parent.append(propertiesTable); return parent; }
Example 10
Source File: ParametersComponent.java From swagger2markup with Apache License 2.0 | 5 votes |
@Override public StructuralNode apply(StructuralNode parent, ParametersComponent.Parameters componentParameters) { Map<String, Parameter> parameters = componentParameters.parameters; if (null == parameters || parameters.isEmpty()) return parent; TableImpl pathParametersTable = new TableImpl(parent, new HashMap<>(), new ArrayList<>()); pathParametersTable.setOption("header"); pathParametersTable.setAttribute("caption", "", true); pathParametersTable.setAttribute("cols", ".^2a,.^3a,.^10a,.^5a", true); pathParametersTable.setTitle(labels.getLabel(TABLE_TITLE_PARAMETERS)); pathParametersTable.setHeaderRow( labels.getLabel(TABLE_HEADER_TYPE), labels.getLabel(TABLE_HEADER_NAME), labels.getLabel(TABLE_HEADER_DESCRIPTION), labels.getLabel(TABLE_HEADER_SCHEMA)); parameters.forEach((alt, parameter) -> pathParametersTable.addRow( generateInnerDoc(pathParametersTable, boldUnconstrained(parameter.getIn()), alt), getParameterNameDocument(pathParametersTable, parameter), generateInnerDoc(pathParametersTable, Optional.ofNullable(parameter.getDescription()).orElse("")), generateInnerDoc(pathParametersTable, getSchemaTypeAsString(parameter.getSchema())) )); parent.append(pathParametersTable); return parent; }
Example 11
Source File: ExamplesComponent.java From swagger2markup with Apache License 2.0 | 5 votes |
@Override public StructuralNode apply(StructuralNode node, ExamplesComponent.Parameters parameters) { Map<String, Example> examples = parameters.examples; if (examples == null || examples.isEmpty()) return node; DescriptionListImpl examplesList = new DescriptionListImpl(node); examplesList.setTitle(labels.getLabel(LABEL_EXAMPLES)); examples.forEach((name, example) -> { DescriptionListEntryImpl exampleEntry = new DescriptionListEntryImpl(examplesList, Collections.singletonList(new ListItemImpl(examplesList, name))); ListItemImpl tagDesc = new ListItemImpl(exampleEntry, ""); ParagraphBlockImpl exampleBlock = new ParagraphBlockImpl(tagDesc); appendDescription(exampleBlock, example.getSummary()); appendDescription(exampleBlock, example.getDescription()); mediaTypeExampleComponent.apply(tagDesc, example.getValue()); ParagraphBlockImpl paragraphBlock = new ParagraphBlockImpl(tagDesc); String source = ""; generateRefLink(source, example.getExternalValue(), labels.getLabel(LABEL_EXTERNAL_VALUE)); generateRefLink(source, example.get$ref(), ""); if(StringUtils.isNotBlank(source)){ paragraphBlock.setSource(source); tagDesc.append(paragraphBlock); } exampleEntry.setDescription(tagDesc); examplesList.addEntry(exampleEntry); }); node.append(examplesList); return node; }
Example 12
Source File: EncodingComponent.java From swagger2markup with Apache License 2.0 | 5 votes |
@Override public StructuralNode apply(StructuralNode node, EncodingComponent.Parameters parameters) { Map<String, Encoding> encodings = parameters.encodings; if (encodings == null || encodings.isEmpty()) return node; DescriptionListImpl encodingList = new DescriptionListImpl(node); encodingList.setTitle(labels.getLabel(LABEL_EXAMPLES)); encodings.forEach((name, encoding) -> { DescriptionListEntryImpl encodingEntry = new DescriptionListEntryImpl(encodingList, Collections.singletonList(new ListItemImpl(encodingList, name))); ListItemImpl tagDesc = new ListItemImpl(encodingEntry, ""); ParagraphBlockImpl encodingBlock = new ParagraphBlockImpl(tagDesc); StringBuilder sb = new StringBuilder(); String contentType = encoding.getContentType(); if(StringUtils.isNotBlank(contentType)){ sb.append("Content-Type:").append(contentType).append(LINE_SEPARATOR); } if(encoding.getAllowReserved()){ sb.append(italicUnconstrained("Allow Reserved").toLowerCase()).append(LINE_SEPARATOR); } if(encoding.getExplode()){ sb.append(italicUnconstrained("Explode").toLowerCase()).append(LINE_SEPARATOR); } Encoding.StyleEnum style = encoding.getStyle(); if(style != null){ sb.append("style").append(style).append(LINE_SEPARATOR); } encodingBlock.setSource(sb.toString()); tagDesc.append(encodingBlock); headersComponent.apply(tagDesc, encoding.getHeaders()); encodingEntry.setDescription(tagDesc); encodingList.addEntry(encodingEntry); }); node.append(encodingList); return node; }
Example 13
Source File: JRubyProcessor.java From asciidoctorj with Apache License 2.0 | 3 votes |
/** * Parses the given raw asciidoctor content, parses it and appends it as children to the given parent block. * <p>The following example will add two paragraphs with the role {@code newcontent} to all top * level sections of a document: * <pre> * <verbatim> * Asciidoctor asciidoctor = ... * asciidoctor.javaExtensionRegistry().treeprocessor(new Treeprocessor() { * DocumentRuby process(DocumentRuby document) { * for (AbstractBlock block: document.getBlocks()) { * if (block instanceof Section) { * parseContent(block, Arrays.asList(new String[]{ * "[newcontent]", * "This is new content" * "", * "[newcontent]", * "This is also new content"})); * } * } * } * }); * </verbatim> * </pre> * * @param parent The block to which the parsed content should be added as children. * @param lines Raw asciidoctor content */ @Override public void parseContent(StructuralNode parent, List<String> lines) { Ruby runtime = JRubyRuntimeContext.get(parent); Parser parser = new Parser(runtime, parent, ReaderImpl.createReader(runtime, lines)); StructuralNode nextBlock = parser.nextBlock(); while (nextBlock != null) { parent.append(nextBlock); nextBlock = parser.nextBlock(); } }