Permalink
Browse files

Improved the generated output from the Cypher docs regarding translat…

…ion support.
  • Loading branch information...
1 parent c2f8360 commit 617c79476f550ee5ac30f19031663b5f9091654e @nawroth nawroth committed Oct 11, 2012
@@ -25,8 +25,7 @@ You can also create a graph entity from a `Map<String,Object>` map. All
the key/value pairs in the map will be set as properties on the created
relationship or node.
-_Query_
-
+.Query
[source,cypher]
----
create ({props})
@@ -47,8 +46,7 @@ classifier=test-sources
By providing an iterable of maps (`Iterable<Map<String,Object>>`), Cypher will create a node for each map
in the iterable. When you do this, you can't create anything else in the same create statement.
-_Query_
-
+.Query
[source,cypher]
----
create (n {props}) return n
@@ -29,6 +29,7 @@
import org.neo4j.test.GraphDescription.Graph;
import org.neo4j.visualization.asciidoc.AsciidocHelper;
+import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;
@@ -54,19 +55,21 @@ public void intro_examples() throws Exception
Writer fw = AsciiDocGenerator.getFW( "target/docs/dev/", gen.get().getTitle() );
data.get();
fw.append( "\nImagine an example graph like the following one:\n\n" );
- fw.append( AsciidocHelper.createGraphVizWithNodeId( "Example Graph",
- graphdb(),
- "cypher-intro" ) );
+ fw.append( AsciiDocGenerator.dumpToSeparateFileWithType( new File("target/docs/dev/"), "intro.graph",
+ AsciidocHelper.createGraphVizWithNodeId( "Example Graph",
+ graphdb(), "cypher-intro" ) ) );
- fw.append( "For example, here is a query which finds a user called John in an index and then traverses the graph looking for friends of Johns friends (though not his direct friends) before returning both John and any friends-of-friends that are found." );
- fw.append( "\n" );
+ fw.append( "\nFor example, here is a query which finds a user called John in an index and then traverses the graph looking for friends of Johns friends (though not his direct friends) before returning both John and any friends-of-friends that are found." );
+ fw.append( "\n\n" );
String query = "START john=node:node_auto_index(name = 'John') "
+ "MATCH john-[:friend]->()-[:friend]->fof RETURN john, fof ";
- fw.append( createCypherSnippet( query ) );
- fw.append( "\nResulting in:\n" );
- fw.append( createQueryResultSnippet( engine.execute( query ).toString() ) );
+ fw.append( AsciiDocGenerator.dumpToSeparateFileWithType( new File("target/docs/dev/"), "intro.query",
+ createCypherSnippet( query ) ) );
+ fw.append( "\nResulting in:\n\n" );
+ fw.append( AsciiDocGenerator.dumpToSeparateFileWithType( new File("target/docs/dev/"), "intro.result",
+ createQueryResultSnippet( engine.execute( query ).toString() ) ) );
- fw.append( "Next up we will add filtering to set more parts "
+ fw.append( "\nNext up we will add filtering to set more parts "
+ "in motion:\n\nIn this next example, we take a list of users "
+ "(by node ID) and traverse the graph looking for those other "
+ "users that have an outgoing +friend+ relationship, returning "
@@ -82,10 +85,12 @@ public void intro_examples() throws Exception
+ ","
+ data.get().get( "Steve" ).getId()
+ ") MATCH user-[:friend]->follower WHERE follower.name =~ 'S.*' RETURN user, follower.name ";
- fw.append( "\n" );
- fw.append( createCypherSnippet( query ) );
- fw.append( "\nResulting in\n" );
- fw.append( createQueryResultSnippet( engine.execute( query ).toString() ) );
+ fw.append( "\n\n" );
+ fw.append( AsciiDocGenerator.dumpToSeparateFileWithType( new File("target/docs/dev/"), "intro.query",
+ createCypherSnippet( query ) ) );
+ fw.append( "\nResulting in:\n\n" );
+ fw.append( AsciiDocGenerator.dumpToSeparateFileWithType( new File("target/docs/dev/"), "intro.result",
+ createQueryResultSnippet( engine.execute( query ).toString() ) ) );
fw.close();
}
@@ -103,8 +103,7 @@ abstract class ArticleTest extends Assertions with DocumentationHelper {
val resultSnippetAsciiDoc = AsciidocHelper.createQueryResultSnippet(queryOutput)
val resultSnippet = AsciiDocGenerator.dumpToSeparateFileWithType(dir, name + "-result", resultSnippetAsciiDoc)
- val queryText = """_Query_
-
+ val queryText = """.Query
%s
""".format(querySnippet)
@@ -74,8 +74,7 @@ trait DocumentationHelper {
writer.emit(out, Walker.fullGraph(db))
return """
-_Graph_
-
+.Graph
["dot", "%s.svg", "neoviz", "%s"]
----
%s
@@ -197,7 +196,7 @@ abstract class DocumentingTestBase extends Assertions with DocumentationHelper {
def runQuery(dir: File, writer: PrintWriter, testId: String, query: String, returns: String, result: ExecutionResult) {
val output = new StringBuilder(2048)
- output.append("_Query_\n\n")
+ output.append(".Query\n")
output.append(AsciidocHelper.createCypherSnippet(query))
writer.println(AsciiDocGenerator.dumpToSeparateFile(dir, testId + ".query", output.toString))
writer.println

0 comments on commit 617c794

Please sign in to comment.