diff --git a/lib/puppetx/puppetlabs/strings/yard/templates/default/definedtype/html/docstring.erb b/lib/puppetx/puppetlabs/strings/yard/templates/default/definedtype/html/docstring.erb index edebfa0..900985f 100644 --- a/lib/puppetx/puppetlabs/strings/yard/templates/default/definedtype/html/docstring.erb +++ b/lib/puppetx/puppetlabs/strings/yard/templates/default/definedtype/html/docstring.erb @@ -27,23 +27,7 @@

Return:

<% end %> diff --git a/lib/puppetx/puppetlabs/strings/yard/templates/default/definedtype/html/parameter_details.erb b/lib/puppetx/puppetlabs/strings/yard/templates/default/definedtype/html/parameter_details.erb index b55a473..a085ac0 100644 --- a/lib/puppetx/puppetlabs/strings/yard/templates/default/definedtype/html/parameter_details.erb +++ b/lib/puppetx/puppetlabs/strings/yard/templates/default/definedtype/html/parameter_details.erb @@ -1,41 +1,6 @@

Parameter Summary

diff --git a/lib/puppetx/puppetlabs/strings/yard/templates/default/definedtype/setup.rb b/lib/puppetx/puppetlabs/strings/yard/templates/default/definedtype/setup.rb index adc2778..8ea5588 100644 --- a/lib/puppetx/puppetlabs/strings/yard/templates/default/definedtype/setup.rb +++ b/lib/puppetx/puppetlabs/strings/yard/templates/default/definedtype/setup.rb @@ -1,5 +1,7 @@ include T('default/module') +require File.join(File.dirname(__FILE__),'../html_helper') + def init sections :header, :box_info, :pre_docstring, :docstring, :parameter_details end @@ -7,6 +9,8 @@ end def parameter_details return if object.parameters.empty? + @html_helper = HTMLHelper.new + param_tags = object.tags.find_all{ |tag| tag.tag_name == "param"} params = object.parameters @@ -30,6 +34,8 @@ def header end def docstring + @html_helper = HTMLHelper.new + examples = Hash.new example_tags = object.tags.find_all { |tag| tag.tag_name == "example" } example_tags.each do |example| diff --git a/lib/puppetx/puppetlabs/strings/yard/templates/default/html_helper.rb b/lib/puppetx/puppetlabs/strings/yard/templates/default/html_helper.rb new file mode 100644 index 0000000..4cb0620 --- /dev/null +++ b/lib/puppetx/puppetlabs/strings/yard/templates/default/html_helper.rb @@ -0,0 +1,53 @@ +class HTMLHelper + + def generate_return_types(types, desc = nil) + result = [] + + result << "(" << types.join(", ") << ")" + + if !desc.nil? + result << "-

#{desc}

" + end + + result.join + end + + def generate_parameters(params) + result = [] + + params.each do |param| + result << "
  • " + + if !param[:exists?] + result << "" + end + + result << "#{param[:name]} " + result << "" + + if param[:types] + result << "(" << "" << param[:types].join(", ") << "" << ")" + else + result << "(TBD)" + end + result << "" + + # This is only relevant for manifests, not puppet functions + unless param[:fq_name].nil? + result << " => #{param[:fq_name]}" + end + + if param[:desc] + result << "-

    #{param[:desc]}

    " + end + + if !param[:exists?] + result << "
    " + end + + result << "
  • " + end + + result.join + end +end diff --git a/lib/puppetx/puppetlabs/strings/yard/templates/default/puppetnamespace/html/docstring.erb b/lib/puppetx/puppetlabs/strings/yard/templates/default/puppetnamespace/html/docstring.erb index cb5110a..8050727 100644 --- a/lib/puppetx/puppetlabs/strings/yard/templates/default/puppetnamespace/html/docstring.erb +++ b/lib/puppetx/puppetlabs/strings/yard/templates/default/puppetnamespace/html/docstring.erb @@ -1,6 +1,12 @@ +

    Function Details

    <% @class_details.each do |func| %>

    > - <%= func[:name] %> + + <% if func[:return] %> + <%= @html_helper.generate_return_types(func[:return][1]) %> + <% end %> + <%= func[:name] %> +

    @@ -31,23 +37,7 @@

    Returns:

    <% end %> @@ -55,39 +45,7 @@

    Parameters:

      - <% func[:params].each do |param| %> -
    • - <% if !param[:exists?] %> - - <% end %> - <%= param[:name] %> - <%# TODO: Linkify defaults that resolve to variable declarations in a different scope. %> - - <% if param[:types] %> - (<% param[:types].each do |type| %> - - <% if param[:types].last != type %> - <%= type %>, - <% else %> - <%= type %> - <% end %> - - <% end %>) - <% else %> - (TBD) - <% end %> - - <% if param[:desc]%> - — -
      -

      <%= param[:desc] %>

      -
      - <% end %> - <% if !param[:exists] %> -
      - <% end %> -
    • - <% end %> + <%= @html_helper.generate_parameters(func[:params]) %>
    <% end %> diff --git a/lib/puppetx/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_summary.erb b/lib/puppetx/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_summary.erb index 6d61392..11ec619 100644 --- a/lib/puppetx/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_summary.erb +++ b/lib/puppetx/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_summary.erb @@ -4,18 +4,10 @@
  • > - <% if ! method[:return_types].nil? %> - ( - <% method[:return_types].each do |type| %> - <%= type %> - <% if method[:return_types].last != type %> - , - <% end %> - <% end %> - ) — + <%= @html_helper.generate_return_types(method[:return_types]) %> <% end %> - + - <%= method[:name] %>
  • diff --git a/lib/puppetx/puppetlabs/strings/yard/templates/default/puppetnamespace/setup.rb b/lib/puppetx/puppetlabs/strings/yard/templates/default/puppetnamespace/setup.rb index a310566..84ee82f 100644 --- a/lib/puppetx/puppetlabs/strings/yard/templates/default/puppetnamespace/setup.rb +++ b/lib/puppetx/puppetlabs/strings/yard/templates/default/puppetnamespace/setup.rb @@ -1,9 +1,11 @@ include T('default/module') +require File.join(File.dirname(__FILE__),'../html_helper') + def init sections :header, :box_info, :pre_docstring, T('docstring'), :method_summary, [:item_summary], - :method_details_list, :method_details + :method_details_list, [T('method_details')] @methods = object.children end @@ -34,6 +36,7 @@ end def method_summary @method_details = [] + @html_helper = HTMLHelper.new @methods.each do |method| # If there are multiple sentences in the method description, only @@ -51,8 +54,9 @@ def method_summary erb(:method_summary) end -def method_details +def method_details_list @class_details = [] + @html_helper = HTMLHelper.new @methods.each do |object| examples = Hash.new @@ -122,3 +126,4 @@ def extract_param_details(params_array, tags_hash) parameter_info end +