From b5a7277e1590a7135fc36aab2c4f56741a73adf3 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Thu, 23 May 2019 13:42:20 -0700 Subject: [PATCH 01/13] adding redcarpet to Gemfile --- Gemfile | 1 + Gemfile.lock | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Gemfile b/Gemfile index 5f3f293eb84e..4f35b7687c56 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ source 'https://rubygems.org' gem 'activesupport' gem 'binding_of_caller' gem 'rake' +gem 'redcarpet' group :test do gem 'erb_lint' diff --git a/Gemfile.lock b/Gemfile.lock index ad930ce6caf1..b0490ad55412 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -71,6 +71,7 @@ GEM loofah (~> 2.2, >= 2.2.2) rainbow (3.0.0) rake (12.3.1) + redcarpet (3.4.0) rspec (3.8.0) rspec-core (~> 3.8.0) rspec-expectations (~> 3.8.0) @@ -113,6 +114,7 @@ DEPENDENCIES octokit parallel_tests rake + redcarpet rspec rubocop (~> 0.63.1) From e4626c3e5d86605e6da5e4d789c74b04ee792285 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Tue, 18 Jun 2019 17:18:43 -0700 Subject: [PATCH 02/13] markdown parser --- provider/ansible/documentation.rb | 15 ++---- provider/ansible/markdown.rb | 81 +++++++++++++++++++++++++++++ templates/ansible/documentation.erb | 2 +- templates/ansible/facts.erb | 2 +- 4 files changed, 87 insertions(+), 13 deletions(-) create mode 100644 provider/ansible/markdown.rb diff --git a/provider/ansible/documentation.rb b/provider/ansible/documentation.rb index e9e302942f96..e653846d9c17 100644 --- a/provider/ansible/documentation.rb +++ b/provider/ansible/documentation.rb @@ -14,6 +14,7 @@ require 'compile/core' require 'provider/config' require 'provider/core' +require 'provider/ansible/markdown' # Rubocop doesn't like this file because the hashes are complicated. # Humans like this file because the hashes are explicit and easy to read. @@ -21,6 +22,7 @@ module Provider module Ansible # Responsible for building out YAML documentation blocks. module Documentation + include Provider::Ansible::Markdown # Builds out the DOCUMENTATION for a property. # This will eventually be converted to YAML def documentation_for_property(prop) @@ -28,7 +30,7 @@ def documentation_for_property(prop) { prop.name.underscore => { 'description' => [ - format_description(prop.description), + description(prop.description), (resourceref_description(prop) \ if prop.is_a?(Api::Type::ResourceRef) && !prop.resource_ref.readonly), (choices_description(prop) \ @@ -68,7 +70,7 @@ def returns_for_property(prop) && prop.item_type.is_a?(Api::Type::NestedObject)) { prop.name => { - 'description' => format_description(prop.description), + 'description' => description(prop.description), 'returned' => 'success', 'type' => type, 'contains' => ( @@ -102,15 +104,6 @@ def choices_description(prop) "Some valid choices include: #{prop.values.map { |x| "\"#{x}\"" }.join(', ')}" end - # MM puts descriptions in a text block. Ansible needs it in bullets - def format_description(desc) - desc.split(".\n").map do |paragraph| - paragraph += '.' unless paragraph.end_with?('.') - paragraph = format_url(paragraph) - paragraph.tr("\n", ' ').strip.squeeze(' ') - end - end - # Find URLs and surround with U() # If there's a period at the end of the URL, make sure the # period is outside of the () diff --git a/provider/ansible/markdown.rb b/provider/ansible/markdown.rb new file mode 100644 index 000000000000..37b65a06b6e6 --- /dev/null +++ b/provider/ansible/markdown.rb @@ -0,0 +1,81 @@ +# 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. + +require 'compile/core' +require 'provider/config' +require 'provider/core' +require 'redcarpet' + +module Provider + module Ansible + # Responsible for building out YAML documentation + # from Markdown + # This is primarily done for parsing descriptions. + module Markdown + DELIMITER = '$$$'.freeze + + def description(text) + Redcarpet::Markdown.new(AnsibleDescriptionRender) + .render(text.gsub(/\n^\n/, ' ')) + .split(DELIMITER) + end + + # This is a rendering class that takes in + # a Markdown description and returns an + # array of strings. This is used exclusively for + # description documentation. + # + # Redcarpet will return a String (because that's the expectation of markdown). + # Ansible wants an array of strings, so this class will return a single string + # with the '$$$' character denoting where the string should be split. + class AnsibleDescriptionRender < Redcarpet::Render::Base + LIST_DELIMITER = '%%%'.freeze + # Returns a paragraph with delimiters showing where it should be split. + def paragraph(text) + text.split(". ").map do |paragraph| + paragraph += '.' unless paragraph.end_with?('.') + paragraph.tr("\n", ' ').strip.squeeze(' ') + end.join(DELIMITER) + end + + + def codespan(code) + "`#{code}`" + end + + def normal_text(text) + text + end + + def link(link, title, content) + if content + "L(#{content},#{link})" + else + "U(#{link})" + end + end + + def list(content, list_type) + content.split(LIST_DELIMITER).join(', ') + end + + # List items come first. We have to place special delimiters + # because all of the list strings are joined together before + # list() is called. + def list_item(text, list_type) + "#{text.sub("\n", '')}#{LIST_DELIMITER}" + end + end + end + end +end diff --git a/templates/ansible/documentation.erb b/templates/ansible/documentation.erb index 9eafc4a4ccc4..d493cd3672d1 100644 --- a/templates/ansible/documentation.erb +++ b/templates/ansible/documentation.erb @@ -14,7 +14,7 @@ DOCUMENTATION = ''' --- <%= to_yaml({ 'module' => module_name(object), - 'description' => format_description(object.description), + 'description' => description(object.description), 'short_description' => "Creates a GCP #{object.name}", 'version_added' => version_added(object).to_f, 'author' => "Google Inc. (@googlecloudplatform)", diff --git a/templates/ansible/facts.erb b/templates/ansible/facts.erb index e3968dcf1e36..f8e2392b93e2 100644 --- a/templates/ansible/facts.erb +++ b/templates/ansible/facts.erb @@ -34,7 +34,7 @@ DOCUMENTATION = ''' 'options' => [ ({ object.facts.filter.name.underscore => { - 'description' => format_description(object.facts.filter.description) + 'description' => description(object.facts.filter.description) } } if object.facts.has_filters), uri_props.map { |p| documentation_for_property(p) } From cec5db2732a91d80ca531d3718bee484e0655332 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Tue, 18 Jun 2019 17:40:42 -0700 Subject: [PATCH 03/13] url formatting + better line splitting --- provider/ansible/markdown.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/provider/ansible/markdown.rb b/provider/ansible/markdown.rb index 37b65a06b6e6..cdbf06de40bf 100644 --- a/provider/ansible/markdown.rb +++ b/provider/ansible/markdown.rb @@ -42,8 +42,9 @@ class AnsibleDescriptionRender < Redcarpet::Render::Base LIST_DELIMITER = '%%%'.freeze # Returns a paragraph with delimiters showing where it should be split. def paragraph(text) - text.split(". ").map do |paragraph| + text.split(/\.[ \n]/).map do |paragraph| paragraph += '.' unless paragraph.end_with?('.') + format_url(paragraph) paragraph.tr("\n", ' ').strip.squeeze(' ') end.join(DELIMITER) end @@ -75,6 +76,20 @@ def list(content, list_type) def list_item(text, list_type) "#{text.sub("\n", '')}#{LIST_DELIMITER}" end + + private + + # Find URLs and surround with U() + # If there's a period at the end of the URL, make sure the + # period is outside of the () + def format_url(paragraph) + paragraph.gsub(%r{ + https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9] + [a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+ + [a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www)) + [a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9]\.[^\s]{2,} + }x, 'U(\\0)').gsub('.)', ').') + end end end end From 35b1101c63cd41368007f40621d24b5354e83100 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Tue, 18 Jun 2019 17:44:28 -0700 Subject: [PATCH 04/13] dont split lines --- provider/ansible/markdown.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/ansible/markdown.rb b/provider/ansible/markdown.rb index cdbf06de40bf..71180a0b0ee1 100644 --- a/provider/ansible/markdown.rb +++ b/provider/ansible/markdown.rb @@ -42,7 +42,7 @@ class AnsibleDescriptionRender < Redcarpet::Render::Base LIST_DELIMITER = '%%%'.freeze # Returns a paragraph with delimiters showing where it should be split. def paragraph(text) - text.split(/\.[ \n]/).map do |paragraph| + text.split(/\.\n/).map do |paragraph| paragraph += '.' unless paragraph.end_with?('.') format_url(paragraph) paragraph.tr("\n", ' ').strip.squeeze(' ') From f0ff799b3e52c7c01a5c35c97fc8e96d79d395e7 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 19 Jun 2019 10:21:39 -0700 Subject: [PATCH 05/13] adding new gemfile to container --- .ci/containers/go-ruby/Gemfile | 1 + .ci/containers/go-ruby/Gemfile.lock | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.ci/containers/go-ruby/Gemfile b/.ci/containers/go-ruby/Gemfile index 5f3f293eb84e..4f35b7687c56 100644 --- a/.ci/containers/go-ruby/Gemfile +++ b/.ci/containers/go-ruby/Gemfile @@ -3,6 +3,7 @@ source 'https://rubygems.org' gem 'activesupport' gem 'binding_of_caller' gem 'rake' +gem 'redcarpet' group :test do gem 'erb_lint' diff --git a/.ci/containers/go-ruby/Gemfile.lock b/.ci/containers/go-ruby/Gemfile.lock index ad930ce6caf1..b0490ad55412 100644 --- a/.ci/containers/go-ruby/Gemfile.lock +++ b/.ci/containers/go-ruby/Gemfile.lock @@ -71,6 +71,7 @@ GEM loofah (~> 2.2, >= 2.2.2) rainbow (3.0.0) rake (12.3.1) + redcarpet (3.4.0) rspec (3.8.0) rspec-core (~> 3.8.0) rspec-expectations (~> 3.8.0) @@ -113,6 +114,7 @@ DEPENDENCIES octokit parallel_tests rake + redcarpet rspec rubocop (~> 0.63.1) From f01f42d6a6b63c452f4cb23a59d7ea189fc4fa37 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 19 Jun 2019 10:38:35 -0700 Subject: [PATCH 06/13] more container changes --- .ci/containers/go-ruby-python/Dockerfile | 2 +- .ci/magic-modules/generate-ansible.yml | 2 +- .ci/magic-modules/generate-inspec.yml | 2 +- .ci/magic-modules/generate-terraform.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.ci/containers/go-ruby-python/Dockerfile b/.ci/containers/go-ruby-python/Dockerfile index 2fdf42ebc0e5..4bae9ca138e0 100644 --- a/.ci/containers/go-ruby-python/Dockerfile +++ b/.ci/containers/go-ruby-python/Dockerfile @@ -1,4 +1,4 @@ -FROM gcr.io/magic-modules/go-ruby:1.11.5-2.6.0-v2 +FROM gcr.io/magic-modules/go-ruby:1.11.5-2.6.0-v3 # Install python & python libraries. RUN apt-get update diff --git a/.ci/magic-modules/generate-ansible.yml b/.ci/magic-modules/generate-ansible.yml index c30b54b47945..90715272bc1f 100644 --- a/.ci/magic-modules/generate-ansible.yml +++ b/.ci/magic-modules/generate-ansible.yml @@ -8,7 +8,7 @@ image_resource: type: docker-image source: repository: gcr.io/magic-modules/go-ruby-python - tag: '1.11.5-2.6.0-2.7-v2' + tag: '1.11.5-2.6.0-2.7-v3' inputs: - name: magic-modules-branched diff --git a/.ci/magic-modules/generate-inspec.yml b/.ci/magic-modules/generate-inspec.yml index 44f15b5b0ac1..197f602943b7 100644 --- a/.ci/magic-modules/generate-inspec.yml +++ b/.ci/magic-modules/generate-inspec.yml @@ -8,7 +8,7 @@ image_resource: type: docker-image source: repository: gcr.io/magic-modules/go-ruby-python - tag: '1.11.5-2.6.0-2.7-v2' + tag: '1.11.5-2.6.0-2.7-v3' inputs: - name: magic-modules-branched diff --git a/.ci/magic-modules/generate-terraform.yml b/.ci/magic-modules/generate-terraform.yml index a641c3faaa77..1a3c540ab5df 100644 --- a/.ci/magic-modules/generate-terraform.yml +++ b/.ci/magic-modules/generate-terraform.yml @@ -8,7 +8,7 @@ image_resource: type: docker-image source: repository: gcr.io/magic-modules/go-ruby-python - tag: '1.11.5-2.6.0-2.7-v2' + tag: '1.11.5-2.6.0-2.7-v3' inputs: - name: magic-modules-branched From 2afd0eb2a062c87eb505d68cb8dcef05eb0f763c Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 19 Jun 2019 10:39:13 -0700 Subject: [PATCH 07/13] rubocop --- provider/ansible/markdown.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/provider/ansible/markdown.rb b/provider/ansible/markdown.rb index 71180a0b0ee1..fd6a6c15ec7b 100644 --- a/provider/ansible/markdown.rb +++ b/provider/ansible/markdown.rb @@ -49,7 +49,6 @@ def paragraph(text) end.join(DELIMITER) end - def codespan(code) "`#{code}`" end @@ -58,7 +57,7 @@ def normal_text(text) text end - def link(link, title, content) + def link(link, _title, content) if content "L(#{content},#{link})" else @@ -66,14 +65,14 @@ def link(link, title, content) end end - def list(content, list_type) + def list(content, _list_type) content.split(LIST_DELIMITER).join(', ') end # List items come first. We have to place special delimiters # because all of the list strings are joined together before # list() is called. - def list_item(text, list_type) + def list_item(text, _list_type) "#{text.sub("\n", '')}#{LIST_DELIMITER}" end From c5d5e956be48ae11fd503f0569d376d69b0935c9 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 19 Jun 2019 11:04:11 -0700 Subject: [PATCH 08/13] fixes --- provider/ansible/markdown.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/provider/ansible/markdown.rb b/provider/ansible/markdown.rb index fd6a6c15ec7b..6d428e1f8181 100644 --- a/provider/ansible/markdown.rb +++ b/provider/ansible/markdown.rb @@ -42,9 +42,9 @@ class AnsibleDescriptionRender < Redcarpet::Render::Base LIST_DELIMITER = '%%%'.freeze # Returns a paragraph with delimiters showing where it should be split. def paragraph(text) - text.split(/\.\n/).map do |paragraph| + text.split(".\n").map do |paragraph| paragraph += '.' unless paragraph.end_with?('.') - format_url(paragraph) + paragraph = format_url(paragraph) paragraph.tr("\n", ' ').strip.squeeze(' ') end.join(DELIMITER) end From ee15a7d216d67c5b4999f5e3e5e6cc8370bae591 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 19 Jun 2019 12:57:16 -0700 Subject: [PATCH 09/13] removing spaces --- provider/ansible/markdown.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/provider/ansible/markdown.rb b/provider/ansible/markdown.rb index 6d428e1f8181..c8a6381ecca8 100644 --- a/provider/ansible/markdown.rb +++ b/provider/ansible/markdown.rb @@ -25,8 +25,11 @@ module Markdown DELIMITER = '$$$'.freeze def description(text) + # Description texts should have leading + trailing spaces + # removed so that they are not mistaken for code blocks by the + # Markdown parser. Redcarpet::Markdown.new(AnsibleDescriptionRender) - .render(text.gsub(/\n^\n/, ' ')) + .render(text.strip) .split(DELIMITER) end From 05e7916b3a7e9d7090b440e54b976a2b42ae389e Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 19 Jun 2019 13:07:52 -0700 Subject: [PATCH 10/13] array differences --- provider/ansible/markdown.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/provider/ansible/markdown.rb b/provider/ansible/markdown.rb index c8a6381ecca8..68bdedcf3e0a 100644 --- a/provider/ansible/markdown.rb +++ b/provider/ansible/markdown.rb @@ -28,9 +28,10 @@ def description(text) # Description texts should have leading + trailing spaces # removed so that they are not mistaken for code blocks by the # Markdown parser. - Redcarpet::Markdown.new(AnsibleDescriptionRender) - .render(text.strip) - .split(DELIMITER) + test = Redcarpet::Markdown.new(AnsibleDescriptionRender) + .render(text.strip.squeeze("\n")) + .split(DELIMITER) + .map(&:strip) end # This is a rendering class that takes in @@ -48,7 +49,7 @@ def paragraph(text) text.split(".\n").map do |paragraph| paragraph += '.' unless paragraph.end_with?('.') paragraph = format_url(paragraph) - paragraph.tr("\n", ' ').strip.squeeze(' ') + paragraph.tr("\n", ' ').squeeze(' ') end.join(DELIMITER) end From cfaa708a3bf30904f06f46b63c11edd3bcf13873 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 19 Jun 2019 13:24:34 -0700 Subject: [PATCH 11/13] markdown --- provider/ansible/markdown.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/provider/ansible/markdown.rb b/provider/ansible/markdown.rb index 68bdedcf3e0a..6439c0f55989 100644 --- a/provider/ansible/markdown.rb +++ b/provider/ansible/markdown.rb @@ -28,10 +28,10 @@ def description(text) # Description texts should have leading + trailing spaces # removed so that they are not mistaken for code blocks by the # Markdown parser. - test = Redcarpet::Markdown.new(AnsibleDescriptionRender) - .render(text.strip.squeeze("\n")) - .split(DELIMITER) - .map(&:strip) + Redcarpet::Markdown.new(AnsibleDescriptionRender) + .render(text.strip.squeeze("\n")) + .split(DELIMITER) + .map(&:strip) end # This is a rendering class that takes in From 2e2fa8437b890e1ca8bbed80d724a96040ffa1f9 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 19 Jun 2019 14:10:42 -0700 Subject: [PATCH 12/13] removing some special symbols to make the parser happy --- provider/ansible/markdown.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/ansible/markdown.rb b/provider/ansible/markdown.rb index 6439c0f55989..b3b2689ec25d 100644 --- a/provider/ansible/markdown.rb +++ b/provider/ansible/markdown.rb @@ -54,7 +54,7 @@ def paragraph(text) end def codespan(code) - "`#{code}`" + code end def normal_text(text) From 72fa91daefd7f69684d5a47c62b2f8113c6306f7 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 19 Jun 2019 14:23:44 -0700 Subject: [PATCH 13/13] adding in quotes --- provider/ansible/markdown.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/ansible/markdown.rb b/provider/ansible/markdown.rb index b3b2689ec25d..9b229f05086c 100644 --- a/provider/ansible/markdown.rb +++ b/provider/ansible/markdown.rb @@ -54,7 +54,7 @@ def paragraph(text) end def codespan(code) - code + "\"#{code}\"" end def normal_text(text)