diff --git a/lib/puppet-strings/markdown/base.rb b/lib/puppet-strings/markdown/base.rb index 55456f2..8e9792a 100644 --- a/lib/puppet-strings/markdown/base.rb +++ b/lib/puppet-strings/markdown/base.rb @@ -58,8 +58,9 @@ module PuppetStrings::Markdown { :return_val => 'return', :since => 'since', :summary => 'summary' }.each do |method_name, tag_name| + # @return [String] unless the tag is nil or the string.length == 0 define_method method_name do - @tags.select { |tag| tag[:tag_name] == "#{tag_name}" }[0][:text] unless @tags.select { |tag| tag[:tag_name] == "#{tag_name}" }[0].nil? + @tags.select { |tag| tag[:tag_name] == "#{tag_name}" }[0][:text] unless @tags.select { |tag| tag[:tag_name] == "#{tag_name}" }[0].nil? || @tags.select { |tag| tag[:tag_name] == "#{tag_name}" }[0][:text].length.zero? end end diff --git a/lib/puppet-strings/markdown/templates/function.erb b/lib/puppet-strings/markdown/templates/function.erb index 52ae63c..40a6ca8 100644 --- a/lib/puppet-strings/markdown/templates/function.erb +++ b/lib/puppet-strings/markdown/templates/function.erb @@ -8,8 +8,8 @@ Type: <%= type %> <%= sig.text %> <% end -%> -<% if sig.return_val -%> -Returns: `<%= sig.return_type %>` <%= sig.return_val %> +<% if sig.return_type -%> +Returns: `<%= sig.return_type %>`<% if sig.return_val %> <%= sig.return_val %><% end %> <% end -%> <% if raises -%> diff --git a/spec/fixtures/unit/markdown/output.md b/spec/fixtures/unit/markdown/output.md index 0f8db8c..005277d 100644 --- a/spec/fixtures/unit/markdown/output.md +++ b/spec/fixtures/unit/markdown/output.md @@ -9,6 +9,7 @@ * [`database`](#database): An example database server type. ## Functions * [`func`](#func): A simple Puppet function. +* [`func3x`](#func3x): Documentation for an example 3.x function. * [`func4x`](#func4x): An example 4.x function. * [`func4x_1`](#func4x_1): An example 4.x function with only one signature. ## Classes @@ -279,6 +280,27 @@ Options: * **:param3opt** `Array`: Something about this option +### func3x +Type: Ruby 3.x API + +#### `func3x(String $param1, Integer $param2)` + +Documentation for an example 3.x function. + +Returns: `Undef` + +##### `param1` + +Data type: `String` + +The first parameter. + +##### `param2` + +Data type: `Integer` + +The second parameter. + ### func4x Type: Ruby 4.x API diff --git a/spec/unit/puppet-strings/markdown_spec.rb b/spec/unit/puppet-strings/markdown_spec.rb index 11cfbf3..6eab938 100644 --- a/spec/unit/puppet-strings/markdown_spec.rb +++ b/spec/unit/puppet-strings/markdown_spec.rb @@ -111,6 +111,19 @@ Puppet::Functions.create_function(:func4x_1) do end end +# An example 3.x function +Puppet::Parser::Functions.newfunction(:func3x, doc: <<-DOC + Documentation for an example 3.x function. + @param param1 [String] The first parameter. + @param param2 [Integer] The second parameter. + @return [Undef] + @example Calling the function. + func3x('hi', 10) + DOC + ) do |*args| + #... +end + Puppet::Type.type(:database).provide :linux do desc 'An example provider on Linux.' confine kernel: 'Linux'