From bf016e60f77638c32ce39c95ae9796922f436075 Mon Sep 17 00:00:00 2001 From: Eva Ogbe Date: Thu, 15 Jun 2017 14:11:01 -0700 Subject: [PATCH 1/2] Add TOC to Ruby version module --- .../ruby/RubyGapicSurfaceTransformer.java | 33 ++++++++----- .../viewmodel/metadata/TocModuleView.java | 47 +++++++++++++++++++ .../api/codegen/ruby/version_index.snip | 15 ++++++ .../ruby_doc_version_index_library.baseline | 7 +++ .../ruby_version_index_library.baseline | 7 +++ 5 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/google/api/codegen/viewmodel/metadata/TocModuleView.java diff --git a/src/main/java/com/google/api/codegen/transformer/ruby/RubyGapicSurfaceTransformer.java b/src/main/java/com/google/api/codegen/transformer/ruby/RubyGapicSurfaceTransformer.java index f6fe4cc9ce..bd4c95dc6a 100644 --- a/src/main/java/com/google/api/codegen/transformer/ruby/RubyGapicSurfaceTransformer.java +++ b/src/main/java/com/google/api/codegen/transformer/ruby/RubyGapicSurfaceTransformer.java @@ -17,6 +17,7 @@ import com.google.api.codegen.GeneratorVersionProvider; import com.google.api.codegen.InterfaceView; import com.google.api.codegen.TargetLanguage; +import com.google.api.codegen.config.GapicInterfaceConfig; import com.google.api.codegen.config.GapicProductConfig; import com.google.api.codegen.config.PackageMetadataConfig; import com.google.api.codegen.config.ProductServiceConfig; @@ -42,6 +43,7 @@ import com.google.api.codegen.viewmodel.PathTemplateGetterFunctionView; import com.google.api.codegen.viewmodel.ViewModel; import com.google.api.codegen.viewmodel.metadata.SimpleModuleView; +import com.google.api.codegen.viewmodel.metadata.TocModuleView; import com.google.api.codegen.viewmodel.metadata.VersionIndexModuleView; import com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView; import com.google.api.codegen.viewmodel.metadata.VersionIndexView; @@ -55,6 +57,7 @@ public class RubyGapicSurfaceTransformer implements ModelToViewTransformer { private static final String VERSION_INDEX_TEMPLATE_FILE = "ruby/version_index.snip"; private static final String XAPI_TEMPLATE_FILENAME = "ruby/main.snip"; + private static final int VERSION_MODULE_RINDEX = 1; private static final int SERVICE_MODULE_RINDEX = 2; private final GapicCodePathMapper pathMapper; @@ -173,11 +176,29 @@ private List generateApiMethods(GapicInterfaceContext context) { private ViewModel generateVersionIndexView(Model model, GapicProductConfig productConfig) { SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName()); + ImmutableList.Builder requireViews = ImmutableList.builder(); + Iterable interfaces = new InterfaceView().getElementIterable(model); + for (Interface apiInterface : interfaces) { + GapicInterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface); + requireViews.add( + VersionIndexRequireView.newBuilder() + .clientName(namer.getFullyQualifiedApiWrapperClassName(interfaceConfig)) + .fileName(namer.getServiceFileName(interfaceConfig)) + .build()); + } + ImmutableList.Builder moduleViews = ImmutableList.builder(); List apiModules = namer.getApiModules(); int moduleCount = apiModules.size(); for (int i = 0; i < moduleCount; ++i) { - if (i == moduleCount - SERVICE_MODULE_RINDEX) { + if (i == moduleCount - VERSION_MODULE_RINDEX) { + moduleViews.add( + TocModuleView.newBuilder() + .moduleName(apiModules.get(i)) + .fullName(model.getServiceConfig().getTitle()) + .requireViews(requireViews.build()) + .build()); + } else if (i == moduleCount - SERVICE_MODULE_RINDEX) { RubyPackageMetadataTransformer metadataTransformer = new RubyPackageMetadataTransformer(packageConfig); moduleViews.add( @@ -193,16 +214,6 @@ private ViewModel generateVersionIndexView(Model model, GapicProductConfig produ } } - ImmutableList.Builder requireViews = ImmutableList.builder(); - Iterable interfaces = new InterfaceView().getElementIterable(model); - for (Interface apiInterface : interfaces) { - requireViews.add( - VersionIndexRequireView.newBuilder() - .clientName(namer.getNotImplementedString("VersionIndexRequireView.clientName")) - .fileName(namer.getServiceFileName(productConfig.getInterfaceConfig(apiInterface))) - .build()); - } - return VersionIndexView.newBuilder() .apiVersion(namer.getApiWrapperModuleVersion()) // The following assumes that all generated interfaces are generated to the same output path. diff --git a/src/main/java/com/google/api/codegen/viewmodel/metadata/TocModuleView.java b/src/main/java/com/google/api/codegen/viewmodel/metadata/TocModuleView.java new file mode 100644 index 0000000000..3f6427d5fb --- /dev/null +++ b/src/main/java/com/google/api/codegen/viewmodel/metadata/TocModuleView.java @@ -0,0 +1,47 @@ +/* Copyright 2017 Google Inc + * + * Licensed 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 com.google.api.codegen.viewmodel.metadata; + +import com.google.auto.value.AutoValue; +import java.util.List; + +@AutoValue +public abstract class TocModuleView implements VersionIndexModuleView { + public abstract String moduleName(); + + public abstract String fullName(); + + public abstract List requireViews(); + + public static Builder newBuilder() { + return new AutoValue_TocModuleView.Builder(); + } + + public String type() { + return TocModuleView.class.getSimpleName(); + } + + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder moduleName(String val); + + public abstract Builder fullName(String val); + + public abstract Builder requireViews(List val); + + public abstract TocModuleView build(); + } +} diff --git a/src/main/resources/com/google/api/codegen/ruby/version_index.snip b/src/main/resources/com/google/api/codegen/ruby/version_index.snip index ea219f081a..422b94ea75 100644 --- a/src/main/resources/com/google/api/codegen/ruby/version_index.snip +++ b/src/main/resources/com/google/api/codegen/ruby/version_index.snip @@ -20,6 +20,8 @@ @switch module.type @case "ReadmeMetadataView" {@readmeModule(module, iterator)} + @case "TocModuleView" + {@tocModule(module, iterator)} @case "SimpleModuleView" {@simpleModule(module, iterator)} @end @@ -33,6 +35,19 @@ {@simpleModule(module, iterator)} @end +@private tocModule(module, iterator) + @## + @# # {@module.fullName} Contents + @# + @# | Filename | Description | + @# | -------- | ----------- | + @join requireView : module.requireViews + @# | {@requireView.fileName} | Accesses the {@requireView.clientName} | + @end + @# + {@simpleModule(module, iterator)} +@end + @private simpleModule(module, iterator) module {@module.moduleName} @if iterator.hasNext diff --git a/src/test/java/com/google/api/codegen/testdata/ruby_doc_version_index_library.baseline b/src/test/java/com/google/api/codegen/testdata/ruby_doc_version_index_library.baseline index 2eac5a703d..0792afce3f 100644 --- a/src/test/java/com/google/api/codegen/testdata/ruby_doc_version_index_library.baseline +++ b/src/test/java/com/google/api/codegen/testdata/ruby_doc_version_index_library.baseline @@ -50,6 +50,13 @@ # [Product Documentation]: https://cloud.google.com/library # module Library + ## + # # Google Example Library API Contents + # + # | Filename | Description | + # | -------- | ----------- | + # | library/v1/library_service_client | Accesses the Library::V1::LibraryServiceClient | + # module V1 end end diff --git a/src/test/java/com/google/api/codegen/testdata/ruby_version_index_library.baseline b/src/test/java/com/google/api/codegen/testdata/ruby_version_index_library.baseline index 2eac5a703d..0792afce3f 100644 --- a/src/test/java/com/google/api/codegen/testdata/ruby_version_index_library.baseline +++ b/src/test/java/com/google/api/codegen/testdata/ruby_version_index_library.baseline @@ -50,6 +50,13 @@ # [Product Documentation]: https://cloud.google.com/library # module Library + ## + # # Google Example Library API Contents + # + # | Filename | Description | + # | -------- | ----------- | + # | library/v1/library_service_client | Accesses the Library::V1::LibraryServiceClient | + # module V1 end end From 96fa2ff924aecabe4e41d3d1e919a0f3307f8697 Mon Sep 17 00:00:00 2001 From: Eva Ogbe Date: Mon, 26 Jun 2017 16:15:10 -0700 Subject: [PATCH 2/2] Change TOC from filenames to classes --- .../ruby/RubyGapicSurfaceTransformer.java | 27 ++++++++---- .../ruby/RubyPackageMetadataTransformer.java | 28 +++++++++++++ .../viewmodel/metadata/TocContentView.java | 42 +++++++++++++++++++ .../viewmodel/metadata/TocModuleView.java | 4 +- .../api/codegen/ruby/version_index.snip | 12 ++++-- .../ruby_doc_version_index_library.baseline | 10 +++-- .../ruby_version_index_library.baseline | 10 +++-- 7 files changed, 112 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/google/api/codegen/viewmodel/metadata/TocContentView.java diff --git a/src/main/java/com/google/api/codegen/transformer/ruby/RubyGapicSurfaceTransformer.java b/src/main/java/com/google/api/codegen/transformer/ruby/RubyGapicSurfaceTransformer.java index bd4c95dc6a..f541541f53 100644 --- a/src/main/java/com/google/api/codegen/transformer/ruby/RubyGapicSurfaceTransformer.java +++ b/src/main/java/com/google/api/codegen/transformer/ruby/RubyGapicSurfaceTransformer.java @@ -43,6 +43,7 @@ import com.google.api.codegen.viewmodel.PathTemplateGetterFunctionView; import com.google.api.codegen.viewmodel.ViewModel; import com.google.api.codegen.viewmodel.metadata.SimpleModuleView; +import com.google.api.codegen.viewmodel.metadata.TocContentView; import com.google.api.codegen.viewmodel.metadata.TocModuleView; import com.google.api.codegen.viewmodel.metadata.VersionIndexModuleView; import com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView; @@ -50,6 +51,7 @@ import com.google.api.tools.framework.model.Interface; import com.google.api.tools.framework.model.Method; import com.google.api.tools.framework.model.Model; +import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import java.util.List; @@ -175,8 +177,16 @@ private List generateApiMethods(GapicInterfaceContext context) { private ViewModel generateVersionIndexView(Model model, GapicProductConfig productConfig) { SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName()); + RubyPackageMetadataTransformer metadataTransformer = + new RubyPackageMetadataTransformer(packageConfig); + RubyPackageMetadataNamer packageNamer = + new RubyPackageMetadataNamer(productConfig.getPackageName()); + List apiModules = namer.getApiModules(); + int moduleCount = apiModules.size(); + String version = apiModules.get(moduleCount - VERSION_MODULE_RINDEX).toLowerCase(); ImmutableList.Builder requireViews = ImmutableList.builder(); + ImmutableList.Builder tocContents = ImmutableList.builder(); Iterable interfaces = new InterfaceView().getElementIterable(model); for (Interface apiInterface : interfaces) { GapicInterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface); @@ -185,28 +195,27 @@ private ViewModel generateVersionIndexView(Model model, GapicProductConfig produ .clientName(namer.getFullyQualifiedApiWrapperClassName(interfaceConfig)) .fileName(namer.getServiceFileName(interfaceConfig)) .build()); + tocContents.add( + metadataTransformer.generateTocContent( + model, packageNamer, version, namer.getApiWrapperClassName(interfaceConfig))); } + tocContents.add( + metadataTransformer.generateDataTypeTocContent( + Joiner.on("::").join(apiModules), packageNamer, version)); ImmutableList.Builder moduleViews = ImmutableList.builder(); - List apiModules = namer.getApiModules(); - int moduleCount = apiModules.size(); for (int i = 0; i < moduleCount; ++i) { if (i == moduleCount - VERSION_MODULE_RINDEX) { moduleViews.add( TocModuleView.newBuilder() .moduleName(apiModules.get(i)) .fullName(model.getServiceConfig().getTitle()) - .requireViews(requireViews.build()) + .contents(tocContents.build()) .build()); } else if (i == moduleCount - SERVICE_MODULE_RINDEX) { - RubyPackageMetadataTransformer metadataTransformer = - new RubyPackageMetadataTransformer(packageConfig); moduleViews.add( metadataTransformer - .generateReadmeMetadataView( - model, - productConfig, - new RubyPackageMetadataNamer(productConfig.getPackageName())) + .generateReadmeMetadataView(model, productConfig, packageNamer) .moduleName(apiModules.get(i)) .build()); } else { diff --git a/src/main/java/com/google/api/codegen/transformer/ruby/RubyPackageMetadataTransformer.java b/src/main/java/com/google/api/codegen/transformer/ruby/RubyPackageMetadataTransformer.java index 7b325bb84f..084c6d0416 100644 --- a/src/main/java/com/google/api/codegen/transformer/ruby/RubyPackageMetadataTransformer.java +++ b/src/main/java/com/google/api/codegen/transformer/ruby/RubyPackageMetadataTransformer.java @@ -38,6 +38,7 @@ import com.google.api.codegen.viewmodel.OptionalArrayMethodView; import com.google.api.codegen.viewmodel.ViewModel; import com.google.api.codegen.viewmodel.metadata.ReadmeMetadataView; +import com.google.api.codegen.viewmodel.metadata.TocContentView; import com.google.api.tools.framework.model.Interface; import com.google.api.tools.framework.model.Method; import com.google.api.tools.framework.model.Model; @@ -120,6 +121,33 @@ public ReadmeMetadataView.Builder generateReadmeMetadataView( .exampleMethods(generateExampleMethods(model, productConfig)); } + public TocContentView generateTocContent( + Model model, RubyPackageMetadataNamer namer, String version, String clientName) { + return generateTocContent( + model.getServiceConfig().getDocumentation().getSummary(), namer, version, clientName); + } + + public TocContentView generateDataTypeTocContent( + String apiModule, RubyPackageMetadataNamer namer, String version) { + return generateTocContent("Data types for " + apiModule, namer, version, "Data Types"); + } + + private TocContentView generateTocContent( + String description, RubyPackageMetadataNamer namer, String version, String clientName) { + return TocContentView.newBuilder() + .name(clientName) + .description(description) + .link( + GITHUB_DOC_HOST + + String.format( + LIB_DOC_PATH, namer.getMetadataIdentifier(), packageConfig.protoPath()) + + '/' + + version + + '/' + + clientName.replace(" ", "").toLowerCase()) + .build(); + } + private ViewModel generateGemspecView(Model model, RubyPackageMetadataNamer namer) { return metadataTransformer .generateMetadataView( diff --git a/src/main/java/com/google/api/codegen/viewmodel/metadata/TocContentView.java b/src/main/java/com/google/api/codegen/viewmodel/metadata/TocContentView.java new file mode 100644 index 0000000000..26bf1b2306 --- /dev/null +++ b/src/main/java/com/google/api/codegen/viewmodel/metadata/TocContentView.java @@ -0,0 +1,42 @@ +/* Copyright 2017 Google Inc + * + * Licensed 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 com.google.api.codegen.viewmodel.metadata; + +import com.google.auto.value.AutoValue; + +@AutoValue +public abstract class TocContentView { + public abstract String name(); + + public abstract String description(); + + public abstract String link(); + + public static Builder newBuilder() { + return new AutoValue_TocContentView.Builder(); + } + + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder name(String val); + + public abstract Builder description(String val); + + public abstract Builder link(String val); + + public abstract TocContentView build(); + } +} diff --git a/src/main/java/com/google/api/codegen/viewmodel/metadata/TocModuleView.java b/src/main/java/com/google/api/codegen/viewmodel/metadata/TocModuleView.java index 3f6427d5fb..bd70daaab0 100644 --- a/src/main/java/com/google/api/codegen/viewmodel/metadata/TocModuleView.java +++ b/src/main/java/com/google/api/codegen/viewmodel/metadata/TocModuleView.java @@ -24,7 +24,7 @@ public abstract class TocModuleView implements VersionIndexModuleView { public abstract String fullName(); - public abstract List requireViews(); + public abstract List contents(); public static Builder newBuilder() { return new AutoValue_TocModuleView.Builder(); @@ -40,7 +40,7 @@ public abstract static class Builder { public abstract Builder fullName(String val); - public abstract Builder requireViews(List val); + public abstract Builder contents(List val); public abstract TocModuleView build(); } diff --git a/src/main/resources/com/google/api/codegen/ruby/version_index.snip b/src/main/resources/com/google/api/codegen/ruby/version_index.snip index 422b94ea75..27989c19be 100644 --- a/src/main/resources/com/google/api/codegen/ruby/version_index.snip +++ b/src/main/resources/com/google/api/codegen/ruby/version_index.snip @@ -39,10 +39,14 @@ @## @# # {@module.fullName} Contents @# - @# | Filename | Description | - @# | -------- | ----------- | - @join requireView : module.requireViews - @# | {@requireView.fileName} | Accesses the {@requireView.clientName} | + @# | Class | Description | + @# | ----- | ----------- | + @join content : module.contents + @# | [{@content.name}][] | {@content.description} | + @end + @# + @join content : module.contents + @# [{@content.name}]: {@content.link} @end @# {@simpleModule(module, iterator)} diff --git a/src/test/java/com/google/api/codegen/testdata/ruby_doc_version_index_library.baseline b/src/test/java/com/google/api/codegen/testdata/ruby_doc_version_index_library.baseline index 0792afce3f..af7e3c4268 100644 --- a/src/test/java/com/google/api/codegen/testdata/ruby_doc_version_index_library.baseline +++ b/src/test/java/com/google/api/codegen/testdata/ruby_doc_version_index_library.baseline @@ -53,9 +53,13 @@ module Library ## # # Google Example Library API Contents # - # | Filename | Description | - # | -------- | ----------- | - # | library/v1/library_service_client | Accesses the Library::V1::LibraryServiceClient | + # | Class | Description | + # | ----- | ----------- | + # | [LibraryServiceClient][] | A simple Google Example Library API. | + # | [Data Types][] | Data types for Library::V1 | + # + # [LibraryServiceClient]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/library/latest/google/library/v1/libraryserviceclient + # [Data Types]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/library/latest/google/library/v1/datatypes # module V1 end diff --git a/src/test/java/com/google/api/codegen/testdata/ruby_version_index_library.baseline b/src/test/java/com/google/api/codegen/testdata/ruby_version_index_library.baseline index 0792afce3f..af7e3c4268 100644 --- a/src/test/java/com/google/api/codegen/testdata/ruby_version_index_library.baseline +++ b/src/test/java/com/google/api/codegen/testdata/ruby_version_index_library.baseline @@ -53,9 +53,13 @@ module Library ## # # Google Example Library API Contents # - # | Filename | Description | - # | -------- | ----------- | - # | library/v1/library_service_client | Accesses the Library::V1::LibraryServiceClient | + # | Class | Description | + # | ----- | ----------- | + # | [LibraryServiceClient][] | A simple Google Example Library API. | + # | [Data Types][] | Data types for Library::V1 | + # + # [LibraryServiceClient]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/library/latest/google/library/v1/libraryserviceclient + # [Data Types]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/library/latest/google/library/v1/datatypes # module V1 end