@Override public void register(Asciidoctor asciidoctor) { asciidoctor.javaExtensionRegistry() .preprocessor(new DefaultAttributesPreprocessor()); asciidoctor.rubyExtensionRegistry() .loadClass(RestDocsExtensionRegistry.class .getResourceAsStream("/extensions/operation_block_macro.rb")) .blockMacro("operation", "OperationBlockMacro"); }
@Override public PreprocessorReader process(Document document, PreprocessorReader reader) { if (contentLines == null) { contentLines = reader.readLines(); } return reader; }
@Override public void restoreLine(String line) { getRubyProperty("unshift_line", line); }
public AbstractProcessorProxy(JRubyAsciidoctor asciidoctor, RubyClass metaClass, T processor) { super(asciidoctor.getRubyRuntime(), metaClass); this.asciidoctor = asciidoctor; processor.unwrap(JRubyProcessor.class).setAsciidoctor(asciidoctor); this.processor = processor; this.processorDelegate = processor.unwrap(JRubyProcessor.class); }
@Override public void process(Document document, PreprocessorReader reader, String target, Map<String, Object> attributes) { StringBuilder content = readContent(target); reader.push_include(content.toString(), target, target, 1, attributes); }
@Override public void process(Document document, PreprocessorReader reader, String target, Map<String, Object> attributes) { StringBuilder content = readContent(target); reader.push_include(content.toString(), target, target, 1, attributes); }
@Override public void process(Document document, PreprocessorReader reader, String target, Map<String, Object> attributes) { StringBuilder content = readContent(target); reader.push_include(content.toString(), target, target, 1, attributes); }
@Name("big") public static class LoggingProcessor extends BlockProcessor { @Override public Object process(StructuralNode parent, Reader reader, Map<String, Object> attributes) { log(new LogRecord(Severity.INFO, parent.getSourceLocation(), "Hello Log")); final List<String> strings = reader.readLines().stream() .map(String::toUpperCase) .collect(Collectors.toList()); return createBlock(parent, "paragraph", strings); } }
@Override public boolean hasMoreLines() { return getBoolean("has_more_lines?"); }
@Override public String read() { return getString("read"); }
@Override public List<String> readLines() { return getList("read_lines", String.class); }
protected void setProcessor(T processor) { this.processor = processor; this.processorDelegate = processor.unwrap(JRubyProcessor.class); }
@Override public PhraseNode createPhraseNode(ContentNode parent, String context, List<String> text, Map<String, Object> attributes, Map<Object, Object> options) { return delegate.createPhraseNode(parent, context, text, attributes, options); }
@Override public Block createBlock(StructuralNode parent, String context, Map<Object, Object> options) { return delegate.createBlock(parent, context, options); }
@Override public Document createDocument(Document parentDocument) { return delegate.createDocument(parentDocument); }
@Override public void parseContent(StructuralNode parent, List<String> lines) { delegate.parseContent(parent, lines); }
@Override public Document process(Document document) { this.document = document; processBlock((StructuralNode) this.document); return this.document; }
@Location(LocationType.HEADER) // <1> public class RobotsDocinfoProcessor extends DocinfoProcessor { // <2> @Override public String process(Document document) { return "<meta name=\"robots\" content=\"index,follow\">"; // <3> } } //end::include[]
@Name("ctrl") public class KeyboardInlineMacroProcessor extends InlineMacroProcessor { @Override public Object process(ContentNode parent, String target, Map<String, Object> attributes) { Map<String, Object> attrs = new HashMap<String, Object>(); attrs.put("keys", Arrays.asList("Ctrl", target)); // <1> return createPhraseNode(parent, "kbd", (String) null, attrs) // <2> .convert(); // <3> } } //end::include[]
@Override public void terminate() { getRubyProperty("terminate"); }