(PDOC-24) Add support for @param in 3x functions

Prior to this commit, the @param tag was not supported for 3x
functions since we could not derive any information about the
parameter from the code itself. Since we would still like users
to be able to document parameters if they wish, update the code so
that if a parameter is documented in the 3x :doc string it will be
displayed in the HTML.
This commit is contained in:
Hailee Kenney 2015-01-28 11:39:28 -08:00
parent b9da8b164f
commit 121bcfd2a7
2 changed files with 28 additions and 3 deletions

View File

@ -64,10 +64,9 @@ def method_details_list
method_info = @template_helper.extract_tag_data(object)
param_details = nil
param_tags = object.tags.find_all{ |tag| tag.tag_name == "param"}
if object['puppet_4x_function']
param_tags = object.tags.find_all{ |tag| tag.tag_name == "param"}
# Extract the source code
source_code = object.source
# Extract the parameters for the source code
@ -76,6 +75,8 @@ def method_details_list
params = parameters.nil? ? nil : parameters[1].split(/\s*,\s*/)
param_details = @template_helper.extract_param_details(params, param_tags) unless params.nil?
else
param_details = @template_helper.comment_only_param_details(param_tags)
end
method_info[:params] = param_details

View File

@ -38,7 +38,6 @@ class TemplateHelper
def extract_param_details(parameters, tags_hash, fq_name = false)
parameter_info = []
# Extract the information for parameters that actually exist
parameters.each do |param|
@ -78,4 +77,29 @@ class TemplateHelper
parameter_info
end
# Generates parameter information in situations where the information can only
# come from YARD tags in the comments, not from the code itself. For now the only
# use for this is 3x functions. In this case exists? will always be true since we
# cannot verify if the paramter exists in the code itself. We must trust the user
# to provide information in the comments that is accurate.
#
# @param param_tags [Array] parameter details obtained from comments
#
# @return [Hash] The relevant information about each parameter
# @option opts [String] :name The name of the parameter
# @option opts [String] :desc The description provided in the comment
# @options opts [Array] :types The parameter type(s) specified in the comment
# @options opts [Boolean] :exists? True only if the parameter exists in the documented logic and not just in a comment
def comment_only_param_details(param_tags)
return if param_tags.empty?
parameter_info = []
param_tags.each do |tag|
parameter_info.push({:name => tag.name, :desc => tag.text, :types => tag.types, :exists? => true})
end
parameter_info
end
end