You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by pa...@apache.org on 2015/04/19 19:18:51 UTC
incubator-groovy git commit: Documentation: add NodeBuilder
documentation
Repository: incubator-groovy
Updated Branches:
refs/heads/GROOVY_2_4_X 5aee7c966 -> cbf6aec77
Documentation: add NodeBuilder documentation
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/cbf6aec7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/cbf6aec7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/cbf6aec7
Branch: refs/heads/GROOVY_2_4_X
Commit: cbf6aec777e46311d1353715491131b9644ef1d2
Parents: 5aee7c9
Author: pascalschumacher <pa...@gmx.net>
Authored: Sun Apr 19 18:56:58 2015 +0200
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sun Apr 19 18:56:58 2015 +0200
----------------------------------------------------------------------
.../doc/core-domain-specific-languages.adoc | 14 ++++++-
src/spec/test/builder/NodeBuilderTest.groovy | 40 ++++++++++++++++++++
2 files changed, 53 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/cbf6aec7/src/spec/doc/core-domain-specific-languages.adoc
----------------------------------------------------------------------
diff --git a/src/spec/doc/core-domain-specific-languages.adoc b/src/spec/doc/core-domain-specific-languages.adoc
index 4870623..66c7072 100644
--- a/src/spec/doc/core-domain-specific-languages.adoc
+++ b/src/spec/doc/core-domain-specific-languages.adoc
@@ -1039,8 +1039,20 @@ include::{projectdir}/subprojects/groovy-xml/{specfolder}/stax-builder.adoc[leve
==== NodeBuilder
-(TBD)
+`NodeBuilder` is used for creating nested trees of gapi:groovy.util.Node[Node] objects for handling arbitrary data.
+To create a simple user list you use a `NodeBuilder` like this:
+
+[source,groovy]
+----
+include::{projectdir}/src/spec/test/builder/NodeBuilderTest.groovy[tags=node_builder_example,indent=0]
+----
+Now you can process the data further, e.g. by using <<gpath_expressions,GPath expressions>>:
+
+[source,groovy]
+----
+include::{projectdir}/src/spec/test/builder/NodeBuilderTest.groovy[tags=node_builder_gpath_assert,indent=0]
+----
include::{projectdir}/subprojects/groovy-json/{specfolder}/json-builder.adoc[leveloffset=+3]
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/cbf6aec7/src/spec/test/builder/NodeBuilderTest.groovy
----------------------------------------------------------------------
diff --git a/src/spec/test/builder/NodeBuilderTest.groovy b/src/spec/test/builder/NodeBuilderTest.groovy
new file mode 100644
index 0000000..c59830f
--- /dev/null
+++ b/src/spec/test/builder/NodeBuilderTest.groovy
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package builder
+
+class NodeBuilderTest extends GroovyTestCase {
+
+ void testNodeBuilder() {
+ // tag::node_builder_example[]
+ def nodeBuilder = new NodeBuilder()
+ def userlist = nodeBuilder.userlist {
+ user(id: '1', firstname: 'John', lastname: 'Smith') {
+ address(type: 'home', street: '1 Main St.', city: 'Springfield', state: 'MA', zip: '12345')
+ address(type: 'work', street: '2 South St.', city: 'Boston', state: 'MA', zip: '98765')
+ }
+ user(id: '2', firstname: 'Alice', lastname: 'Doe')
+ }
+ // end::node_builder_example[]
+
+ // tag::node_builder_gpath_assert[]
+ assert userlist.user.@firstname.join(', ') == 'John, Alice'
+ assert userlist.user.find { it.@lastname == 'Smith' }.address.size() == 2
+ // end::node_builder_gpath_assert[]
+ }
+}