TINKERPOP-1447 Added automatic tab generation for code snippets in asciidoc files.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/91f2f9b0 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/91f2f9b0 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/91f2f9b0 Branch: refs/heads/TINKERPOP-1447 Commit: 91f2f9b0858bb98cd0b16f9c2a81400f236bc49d Parents: 4eeb178 Author: Daniel Kuppitz <[email protected]> Authored: Fri Dec 15 14:30:59 2017 -0700 Committer: Daniel Kuppitz <[email protected]> Committed: Wed Apr 25 17:01:55 2018 -0700 ---------------------------------------------------------------------- docs/postprocessor/processor.awk | 4 + docs/preprocessor/awk/tabify.awk | 120 +++++++++++++++++++ docs/preprocessor/preprocess-file.sh | 4 +- docs/sass/compile | 30 +++++ docs/sass/tabs.scss | 178 +++++++++++++++++++++++++++++ docs/src/dev/provider/index.asciidoc | 4 +- docs/src/recipes/index.asciidoc | 4 +- docs/src/reference/the-graph.asciidoc | 82 +++++++++++++ docs/stylesheets/tabs.css | 19 +++ 9 files changed, 440 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91f2f9b0/docs/postprocessor/processor.awk ---------------------------------------------------------------------- diff --git a/docs/postprocessor/processor.awk b/docs/postprocessor/processor.awk index 18ada47..da82420 100644 --- a/docs/postprocessor/processor.awk +++ b/docs/postprocessor/processor.awk @@ -33,6 +33,10 @@ BEGIN { } } +/<body/ { + print "<link rel=\"stylesheet\" href=\"/docs/x.y.z/stylesheets/tabs.css\" />" +} + !/<span class="comment">/ { if (firstMatch || !isHeader) { print gensub(/(<b class="conum">)\(([0-9]+)\)(<\/b>)/, http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91f2f9b0/docs/preprocessor/awk/tabify.awk ---------------------------------------------------------------------- diff --git a/docs/preprocessor/awk/tabify.awk b/docs/preprocessor/awk/tabify.awk new file mode 100644 index 0000000..24d42a6 --- /dev/null +++ b/docs/preprocessor/awk/tabify.awk @@ -0,0 +1,120 @@ +# 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. + +# +# @author Daniel Kuppitz (http://gremlin.guru) +# +function print_tabs(next_id, tabs, blocks) { + + num_tabs = length(tabs) + x = next_id + + print "++++" + print "<section class=\"tabs tabs-" num_tabs "\">" + + for (i in tabs) { + title = tabs[i] + print " <input id=\"tab-" id_part "-" x "\" type=\"radio\" name=\"radio-set-" id_part "-" next_id "\" class=\"tab-selector-" i "\"" (i == 1 ? " checked=\"checked\"" : "") " />" + print " <label for=\"tab-" id_part "-" x "\" class=\"tab-label-" i "\">" title "</label>" + x++ + } + + for (i in blocks) { + print " <div class=\"tabcontent\">" + print " <div class=\"tabcontent-" i "\">" + print "++++\n" + print blocks[i] + print "++++" + print " </div>" + print " </div>" + } + + print "</section>" + print "++++\n" +} + +function transform_callouts(code, c) { + return gensub(/\s*((<[0-9]+>\s*)*<[0-9]+>)\s*\n/, " " c c " \\1\\2\n", "g", code) +} + +BEGIN { + id_part=systime() + status = 0 + next_id = 1 + block[0] = 0 # initialize "blocks" as an array + delete blocks[0] +} + +/^\[gremlin-/ { + status = 1 + lang = gensub(/^\[gremlin-([^,\]]+).*/, "\\1", "g", $0) + code = "" +} + +/^\[source,(csharp|groovy|java|python)/ { + if (status == 3) { + status = 1 + lang = gensub(/^\[source,([^\]]+).*/, "\\1", "g", $0) + code = "" + } +} + +! /^\[source,(csharp|groovy|java|python)/ { + if (status == 3 && $0 != "") { + print_tabs(next_id, tabs, blocks) + next_id = next_id + length(tabs) + for (i in tabs) { + delete tabs[i] + delete blocks[i] + } + status = 0 + } +} + +/^----$/ { + if (status == 1) { + status = 2 + } else if (status == 2) { + status = 3 + } +} + +{ if (status == 3) { + if ($0 == "----") { + i = length(blocks) + 1 + if (i == 1) { + tabs[i] = "console (" lang ")" + blocks[i] = code_header code "\n" $0 "\n" + i++ + } + tabs[i] = lang + switch (lang) { + case "python": + c = "#" + break + default: + c = "//" + break + } + blocks[i] = "[source," lang "]" transform_callouts(code, c) "\n" $0 "\n" + } + } else { + if (status == 0) print + else if (status == 1) code_header = $0 + else code = code "\n" $0 + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91f2f9b0/docs/preprocessor/preprocess-file.sh ---------------------------------------------------------------------- diff --git a/docs/preprocessor/preprocess-file.sh b/docs/preprocessor/preprocess-file.sh index d5076f1..7d3956d 100755 --- a/docs/preprocessor/preprocess-file.sh +++ b/docs/preprocessor/preprocess-file.sh @@ -132,6 +132,7 @@ if [ ! ${SKIP} ] && [ $(grep -c '^\[gremlin' ${input}) -gt 0 ]; then fi sed 's/\t/ /g' ${input} | + awk -f ${AWK_SCRIPTS}/tabify.awk | awk -f ${AWK_SCRIPTS}/prepare.awk | awk -f ${AWK_SCRIPTS}/init-code-blocks.awk -v TP_HOME="${TP_HOME}" -v PYTHONPATH="${TP_HOME}/gremlin-python/target/classes/Lib" | awk -f ${AWK_SCRIPTS}/progressbar.awk -v tpl=${AWK_SCRIPTS}/progressbar.groovy.template | @@ -141,8 +142,9 @@ if [ ! ${SKIP} ] && [ $(grep -c '^\[gremlin' ${input}) -gt 0 ]; then ${lb} awk -f ${AWK_SCRIPTS}/cleanup.awk | ${lb} awk -f ${AWK_SCRIPTS}/language-variants.awk > ${output} + # check exit code for each of the previously piped commands ps=(${PIPESTATUS[@]}) - for i in {0..6}; do + for i in {0..9}; do ec=${ps[i]} [ ${ec} -eq 0 ] || break done http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91f2f9b0/docs/sass/compile ---------------------------------------------------------------------- diff --git a/docs/sass/compile b/docs/sass/compile new file mode 100755 index 0000000..002954e --- /dev/null +++ b/docs/sass/compile @@ -0,0 +1,30 @@ +#!/bin/bash +# +# +# 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. +# + +DIR=`dirname $0` + +IF="${DIR}/tabs.scss" +OF="${DIR}/../stylesheets/tabs.css" +TF=`mktemp` + +scss --sourcemap=none -t compressed -C ${IF} ${OF} + +cat ${DIR}/../stylesheets/tinkerpop.css | awk 'BEGIN {p=1} {if (p) print} /\*\// {p=0}' | cat - ${OF} > ${TF} && mv ${TF} ${OF} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91f2f9b0/docs/sass/tabs.scss ---------------------------------------------------------------------- diff --git a/docs/sass/tabs.scss b/docs/sass/tabs.scss new file mode 100644 index 0000000..39c88f4 --- /dev/null +++ b/docs/sass/tabs.scss @@ -0,0 +1,178 @@ +/* + * 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. + */ + +$blue: #3f6b9d; +$orange: #e08f24; +$white: #fefefe; +$black: #1a1a1a; +$gray: #eee; + +$active: #609060; +$inactive: #e9ffe9; + +$tabHeight: 50px; +$minTabs: 2; +$maxTabs: 4; + +@mixin single-transition($property:all, $speed:150ms, $ease:ease, $delay: 0s) { + -webkit-transition: $property $speed $ease $delay; + transition: $property $speed $ease $delay; +} + +.tabs { + + position: relative; + margin: 40px auto; + width: 1024px; + max-width: 100%; + overflow: hidden; + padding-top: 10px; + margin-bottom: 60px; + + input { + position: absolute; + z-index: 1000; + height: $tabHeight; + left: 0; + top: 0; + opacity: 0; + -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; + filter: alpha(opacity=0); + cursor: pointer; + margin: 0; + &:hover + label { + background: $orange; + } + } + + label { + background: $inactive; + color: $black; + font-size: 15px; + line-height: $tabHeight; + height: $tabHeight + 10; + position: relative; + top: 0; + padding: 0 20px; + float: left; + display: block; + letter-spacing: 1px; + text-transform: uppercase; + font-weight: bold; + text-align: center; + box-shadow: 2px 0 2px rgba(0,0,0,0.1), -2px 0 2px rgba(0,0,0,0.1); + box-sizing: border-box; + @include single-transition(); + &:hover{ + cursor: pointer; + } + &:after { + content: ''; + background: $active; + position: absolute; + bottom: -2px; + left: 0; + width: 100%; + height: 2px; + display: block; + } + } +} + +@for $n from $minTabs through $maxTabs { + + .tabs-#{$n} { + + input { + width: 100% / $n; + @for $i from 1 through $n { + &.tab-selector-#{$i}{ + left: ($i - 1) * (100% / $n); + } + } + } + + label { + width: 100% / $n; + } + } +} + +.tabs label:first-of-type { + z-index: 4; +} +.tab-label-2 { + z-index: 4; +} +.tab-label-3 { + z-index: 3; +} +.tab-label-4 { + z-index: 2; +} + +.tabs input:checked + label { + background: $active; + color: $white; + z-index: 6; +} + +.clear-shadow { + clear: both; +} + +.tabcontent { + height: auto; + width: 100%; + float: left; + position: relative; + z-index: 5; + background: $gray; + top: -10px; + box-sizing: border-box; + &>div{ + position: relative; + float: left; + width: 0; + height: 0; + box-sizing: border-box; + top: 0; + left: 0; + z-index: 1; + opacity: 0; + background: $gray; + } + .CodeRay { + background-color: $white; + } +} + +@for $i from 1 through $maxTabs { + .tabs .tab-selector-#{$i}:checked ~ .tabcontent .tabcontent-#{$i} { + z-index: 100; + -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; + filter: alpha(opacity=100); + opacity: 1; + width: 100%; + height: auto; + width: 100%; + height: auto; + padding-top: 30px; + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91f2f9b0/docs/src/dev/provider/index.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/dev/provider/index.asciidoc b/docs/src/dev/provider/index.asciidoc index ce4e9f4..5e73622 100644 --- a/docs/src/dev/provider/index.asciidoc +++ b/docs/src/dev/provider/index.asciidoc @@ -611,7 +611,7 @@ features it implements) or should not otherwise be executed. It is possible for by using the `@Graph.OptOut` annotation. The following is an example of this annotation usage as taken from `HadoopGraph`: -[source, java] +[source,java] ---- @Graph.OptIn(Graph.OptIn.SUITE_PROCESS_STANDARD) @Graph.OptIn(Graph.OptIn.SUITE_PROCESS_COMPUTER) @@ -648,7 +648,7 @@ Also note that some of the tests in the Gremlin Test Suite are parameterized tes specificity to be properly ignored. To ignore these types of tests, examine the name template of the parameterized tests. It is defined by a Java annotation that looks like this: -[source, java] +[source,java] @Parameterized.Parameters(name = "expect({0})") The annotation above shows that the name of each parameterized test will be prefixed with "expect" and have http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91f2f9b0/docs/src/recipes/index.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/recipes/index.asciidoc b/docs/src/recipes/index.asciidoc index c59cc89..3fdee22 100644 --- a/docs/src/recipes/index.asciidoc +++ b/docs/src/recipes/index.asciidoc @@ -90,12 +90,12 @@ prior to submitting a recipe. To contribute a recipe, first clone the repository: -[source, shell] +[source,shell] git clone https://github.com/apache/tinkerpop.git The recipes can be found in this directory: -[source, shell] +[source,shell] ls docs/src/recipes Each recipe exists within a separate `.asciidoc` file. The file name should match the name of the recipe. Recipe names http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91f2f9b0/docs/src/reference/the-graph.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/reference/the-graph.asciidoc b/docs/src/reference/the-graph.asciidoc index a3b2bd3..791c342 100644 --- a/docs/src/reference/the-graph.asciidoc +++ b/docs/src/reference/the-graph.asciidoc @@ -602,6 +602,88 @@ IMPORTANT: When using the extended type system in Gremlin Server, support for th Gremlin Language Variants is dependent on the programming language, the driver and its serializers. These implementations are only required to support the core types and not the extended ones. +Here's the same previous example of GraphSON 1.0, but with GraphSON 2.0: + +[gremlin-groovy] +---- +graph = TinkerFactory.createModern() +g = graph.traversal() +f = new ByteArrayOutputStream() +mapper = graph.io(graphson()).mapper().version(GraphSONVersion.V2_0).create() +graph.io(graphson()).writer().mapper(mapper).create().writeVertex(f, g.V(1).next(), BOTH) +f.close() +---- + +Creating a GraphSON 2.0 mapper is done by calling `.version(GraphSONVersion.V2_0)` on the mapper builder. Here's is the +example output from the code above: + +[source,json] +---- +{ + "@type": "g:Vertex", + "@value": { + "id": { + "@type": "g:Int32", + "@value": 1 + }, + "label": "person", + "properties": { + "name": [{ + "@type": "g:VertexProperty", + "@value": { + "id": { + "@type": "g:Int64", + "@value": 0 + }, + "value": "marko", + "label": "name" + } + }], + "uuid": [{ + "@type": "g:VertexProperty", + "@value": { + "id": { + "@type": "g:Int64", + "@value": 12 + }, + "value": { + "@type": "g:UUID", + "@value": "829c7ddb-3831-4687-a872-e25201230cd3" + }, + "label": "uuid" + } + }], + "age": [{ + "@type": "g:VertexProperty", + "@value": { + "id": { + "@type": "g:Int64", + "@value": 1 + }, + "value": { + "@type": "g:Int32", + "@value": 29 + }, + "label": "age" + } + }] + } + } +} +---- + +Types can be disabled when creating a GraphSON 2.0 `Mapper` with: + +[source,groovy] +---- +graph.io(graphson()).mapper(). + version(GraphSONVersion.V2_0). + typeInfo(GraphSONMapper.TypeInfo.NO_TYPES).create() +---- + +By disabling types, the JSON payload produced will lack the extra information that is written for types. Please note, +disabling types can be unsafe with regards to the written data in that types can be lost. + [[gryo-reader-writer]] === Gryo Reader/Writer http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91f2f9b0/docs/stylesheets/tabs.css ---------------------------------------------------------------------- diff --git a/docs/stylesheets/tabs.css b/docs/stylesheets/tabs.css new file mode 100644 index 0000000..df508b7 --- /dev/null +++ b/docs/stylesheets/tabs.css @@ -0,0 +1,19 @@ +/* + * 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. + */ +.tabs{position:relative;margin:40px auto;width:1024px;max-width:100%;overflow:hidden;padding-top:10px;margin-bottom:60px}.tabs input{position:absolute;z-index:1000;height:50px;left:0;top:0;opacity:0;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";filter:alpha(opacity=0);cursor:pointer;margin:0}.tabs input:hover+label{background:#e08f24}.tabs label{background:#e9ffe9;color:#1a1a1a;font-size:15px;line-height:50px;height:60px;position:relative;top:0;padding:0 20px;float:left;display:block;letter-spacing:1px;text-transform:uppercase;font-weight:bold;text-align:center;box-shadow:2px 0 2px rgba(0,0,0,0.1),-2px 0 2px rgba(0,0,0,0.1);box-sizing:border-box;-webkit-transition:all 150ms ease 0s;transition:all 150ms ease 0s}.tabs label:hover{cursor:pointer}.tabs label:after{content:'';background:#609060;position:absolute;bottom:-2px;left:0;width:100%;height:2px;display:block}.tabs-2 input{width:50%}.tabs-2 input.tab-selector-1{left:0%}.tabs-2 input.tab-selector-2{left:50%}.tabs- 2 label{width:50%}.tabs-3 input{width:33.33333%}.tabs-3 input.tab-selector-1{left:0%}.tabs-3 input.tab-selector-2{left:33.33333%}.tabs-3 input.tab-selector-3{left:66.66667%}.tabs-3 label{width:33.33333%}.tabs-4 input{width:25%}.tabs-4 input.tab-selector-1{left:0%}.tabs-4 input.tab-selector-2{left:25%}.tabs-4 input.tab-selector-3{left:50%}.tabs-4 input.tab-selector-4{left:75%}.tabs-4 label{width:25%}.tabs label:first-of-type{z-index:4}.tab-label-2{z-index:4}.tab-label-3{z-index:3}.tab-label-4{z-index:2}.tabs input:checked+label{background:#609060;color:#fefefe;z-index:6}.clear-shadow{clear:both}.tabcontent{height:auto;width:100%;float:left;position:relative;z-index:5;background:#eee;top:-10px;box-sizing:border-box}.tabcontent>div{position:relative;float:left;width:0;height:0;box-sizing:border-box;top:0;left:0;z-index:1;opacity:0;background:#eee}.tabcontent .CodeRay{background-color:#fefefe}.tabs .tab-selector-1:checked ~ .tabcontent .tabcontent-1{z-index:100;-ms-filter:"progid:DXImag eTransform.Microsoft.Alpha(Opacity=100)";filter:alpha(opacity=100);opacity:1;width:100%;height:auto;width:100%;height:auto;padding-top:30px}.tabs .tab-selector-2:checked ~ .tabcontent .tabcontent-2{z-index:100;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";filter:alpha(opacity=100);opacity:1;width:100%;height:auto;width:100%;height:auto;padding-top:30px}.tabs .tab-selector-3:checked ~ .tabcontent .tabcontent-3{z-index:100;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";filter:alpha(opacity=100);opacity:1;width:100%;height:auto;width:100%;height:auto;padding-top:30px}.tabs .tab-selector-4:checked ~ .tabcontent .tabcontent-4{z-index:100;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";filter:alpha(opacity=100);opacity:1;width:100%;height:auto;width:100%;height:auto;padding-top:30px}
