stub in docs services

This commit is contained in:
Jonathan Shook 2020-04-20 02:04:46 -05:00
parent b1822a3548
commit d53f62de74
10 changed files with 145 additions and 16 deletions

View File

@ -0,0 +1,35 @@
package io.nosqlbench.engine.docs;
import io.nosqlbench.docsys.api.Docs;
import io.nosqlbench.docsys.api.DocsBinder;
import io.nosqlbench.nb.api.annotations.Service;
import io.nosqlbench.nb.api.content.Content;
import io.nosqlbench.nb.api.content.NBIO;
import io.nosqlbench.nb.api.content.NBIOWalker;
import io.nosqlbench.nb.api.content.PathContent;
import io.nosqlbench.nb.api.markdown.providers.MarkdownProvider;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service(MarkdownProvider.class)
public class NosqlBenchMarkdownSource implements MarkdownProvider {
@Override
public List<Content<?>> getMarkdownInfo() {
Path docspath = NBIO.local().name("docs-for-eb")
.one().asPath();
NBIOWalker.CollectVisitor capture = new NBIOWalker.CollectVisitor(true, false);
NBIOWalker.RegexFilter filter = new NBIOWalker.RegexFilter("\\.md",true);
NBIOWalker.walkFullPath(docspath,capture,filter);
List<Content<?>> content = new ArrayList<>();
for (Path path : capture.get()) {
content.add(new PathContent(path));
}
return content;
}
}

View File

@ -1,4 +1,4 @@
package io.nosqlbench.nb.api.markdown.descriptor;
package io.nosqlbench.nb.api.markdown.aggregator;
/**
* DocScope determines which display mode a topic is meant to be displayed in.

View File

@ -1,4 +1,4 @@
package io.nosqlbench.nb.api.markdown.descriptor;
package io.nosqlbench.nb.api.markdown.aggregator;
import java.util.List;
import java.util.Set;

View File

@ -0,0 +1,56 @@
package io.nosqlbench.nb.api.markdown.aggregator;
import com.vladsch.flexmark.ext.yaml.front.matter.AbstractYamlFrontMatterVisitor;
import com.vladsch.flexmark.ext.yaml.front.matter.YamlFrontMatterExtension;
import com.vladsch.flexmark.html2md.converter.FlexmarkHtmlConverter;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.ast.Document;
import io.nosqlbench.nb.api.content.Content;
import io.nosqlbench.nb.api.markdown.FlexParser;
import io.nosqlbench.nb.api.markdown.providers.MarkdownProviders;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class MarkdownDocs {
private static FlexmarkHtmlConverter converter = FlexmarkHtmlConverter.builder()
.extensions(List.of(YamlFrontMatterExtension.create()))
.build();
public static MarkdownInfo find(DocScope... scopes) {
return null;
}
public static List<MarkdownInfo> find(String name, DocScope... scopes) {
List<MarkdownInfo> aggregated = new ArrayList<>();
List<Content<?>> markdownContent = MarkdownProviders.getAllMarkdown();
MarkdownInfo info = new MutableMarkdownInfo();
// Find all topics and aggregators
List<String> aggregators = new ArrayList<>();
List<String> topics = new ArrayList<>();
for (Content<?> content : markdownContent) {
String markdown = content.asString();
String convert = converter.convert(markdown);
AbstractYamlFrontMatterVisitor v = new AbstractYamlFrontMatterVisitor();
Document parsed = FlexParser.parser.parse(markdown);
v.visit(parsed);
Map<String, List<String>> data = v.getData();
System.out.print("frontmatter for " + content.asPath());
for (Map.Entry<String, List<String>> e : data.entrySet()) {
System.out.println("k : " + e.getKey());
System.out.println(" v:" + String.join(",",e.getValue()));
}
}
return aggregated;
}
}

View File

@ -1,10 +1,10 @@
package io.nosqlbench.nb.api.markdown.descriptor;
package io.nosqlbench.nb.api.markdown.aggregator;
import java.nio.file.Path;
public interface MarkdownInfo {
Path getPath();
CharSequence getBody();
String getBody();
FrontMatter getFrontmatter();
}

View File

@ -0,0 +1,20 @@
package io.nosqlbench.nb.api.markdown.aggregator;
import java.nio.file.Path;
public class MutableMarkdownInfo implements MarkdownInfo {
@Override
public Path getPath() {
return null;
}
@Override
public String getBody() {
return null;
}
@Override
public FrontMatter getFrontmatter() {
return null;
}
}

View File

@ -1,10 +0,0 @@
package io.nosqlbench.nb.api.markdown.finder;
import io.nosqlbench.nb.api.markdown.descriptor.DocScope;
import io.nosqlbench.nb.api.markdown.descriptor.MarkdownInfo;
public class MarkdownLoader {
public static MarkdownInfo find(DocScope... scopes) {
return null;
}
}

View File

@ -0,0 +1,6 @@
/**
* Because documentation is meant to be provide across all modules
* to both developers and users, the markdown support for NoSQLBench
* is considered a core API.
*/
package io.nosqlbench.nb.api.markdown;

View File

@ -1,4 +1,6 @@
package io.nosqlbench.nb.api.markdown.descriptor;
package io.nosqlbench.nb.api.markdown.providers;
import io.nosqlbench.nb.api.content.Content;
import java.util.List;
@ -6,5 +8,5 @@ import java.util.List;
* A MarkdownProvider simply provides all the markdown content it is aware of.
*/
public interface MarkdownProvider {
List<MarkdownInfo> getMarkdownInfo();
List<Content<?>> getMarkdownInfo();
}

View File

@ -0,0 +1,20 @@
package io.nosqlbench.nb.api.markdown.providers;
import io.nosqlbench.nb.api.content.Content;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
/**
* The internal
*/
public class MarkdownProviders {
public static List<Content<?>> getAllMarkdown() {
ServiceLoader<MarkdownProvider> loader = ServiceLoader.load(MarkdownProvider.class);
List<Content<?>> names = new ArrayList<>();
loader.iterator().forEachRemaining(d -> names.addAll(d.getMarkdownInfo()));
return names;
}
}