(PDOC-35) Fix formatting from Nick's suggestions

* Float several namevars/ensurables to top of list
* Fix minor code style issues
This commit is contained in:
Ian Kronquist 2015-09-02 11:56:07 -07:00
parent 0206c78ee0
commit 1991475b4c
4 changed files with 28 additions and 32 deletions

View File

@ -18,11 +18,11 @@ class PuppetX::PuppetLabs::Strings::YARD::Handlers::PuppetProviderHandler < YARD
# You think this is ugly? It's better than the alternative. # You think this is ugly? It's better than the alternative.
return unless statement.children.length > 2 return unless statement.children.length > 2
first = statement.children.first.first first = statement.children.first.first
return unless (first.source == 'Puppet::Type') or return unless (first.source == 'Puppet::Type') ||
(first.type == :var_ref and (first.type == :var_ref &&
first.source == 'Type') and first.source == 'Type') &&
statement[2].source == 'provide' statement[2].source == 'provide'
i = statement.index { |s| YARD::Parser::Ruby::AstNode === s and s.type == :ident and s.source == 'provide' } i = statement.index { |s| YARD::Parser::Ruby::AstNode === s && s.type == :ident && s.source == 'provide' }
provider_name = statement[i+1].jump(:ident).source provider_name = statement[i+1].jump(:ident).source
type_name = statement.jump(:symbol).first.source type_name = statement.jump(:symbol).first.source
@ -35,19 +35,19 @@ class PuppetX::PuppetLabs::Strings::YARD::Handlers::PuppetProviderHandler < YARD
defaults = {} defaults = {}
do_block = statement.jump(:do_block) do_block = statement.jump(:do_block)
do_block.traverse do |node| do_block.traverse do |node|
if is_a_func_call_named? 'desc', node if is_a_func_call_named?('desc', node)
content = node.jump(:tstring_content) content = node.jump(:tstring_content)
# if we found the string content extract its source # if we found the string content extract its source
if content != node if content != node
# The docstring is either the source stripped of heredoc # The docstring is either the source stripped of heredoc
# annotations or the raw source. # annotations or the raw source.
if @heredoc_helper.is_heredoc? content.source if @heredoc_helper.is_heredoc?(content.source)
docstring = @heredoc_helper.process_heredoc content.source docstring = @heredoc_helper.process_heredoc content.source
else else
docstring = content.source docstring = content.source
end end
end end
elsif is_a_func_call_named? 'confine', node elsif is_a_func_call_named?('confine', node)
node.traverse do |s| node.traverse do |s|
if s.type == :assoc if s.type == :assoc
k = s.first.jump(:ident).source k = s.first.jump(:ident).source
@ -55,20 +55,20 @@ class PuppetX::PuppetLabs::Strings::YARD::Handlers::PuppetProviderHandler < YARD
confines[k] = v confines[k] = v
end end
end end
elsif is_a_func_call_named? 'has_feature', node elsif is_a_func_call_named?('has_feature', node)
list = node.jump :list list = node.jump :list
if list != nil and list != node if list != nil && list != node
features += list.map { |s| s.source if YARD::Parser::Ruby::AstNode === s }.compact features += list.map { |s| s.source if YARD::Parser::Ruby::AstNode === s }.compact
end end
elsif is_a_func_call_named? 'commands', node elsif is_a_func_call_named?('commands', node)
assoc = node.jump(:assoc) assoc = node.jump(:assoc)
if assoc and assoc != node if assoc && assoc != node
ident = assoc.jump(:ident) ident = assoc.jump(:ident)
if ident and ident != assoc if ident && ident != assoc
commands << ident.source commands << ident.source
end end
end end
elsif is_a_func_call_named? 'defaultfor', node elsif is_a_func_call_named?('defaultfor', node)
node.traverse do |s| node.traverse do |s|
if s.type == :assoc if s.type == :assoc
k = s.first.jump(:ident).source k = s.first.jump(:ident).source
@ -88,7 +88,7 @@ class PuppetX::PuppetLabs::Strings::YARD::Handlers::PuppetProviderHandler < YARD
register obj register obj
end end
def is_a_func_call_named? name, node def is_a_func_call_named?(name, node)
(node.type == :fcall or node.type == :command or node.type == :vcall) and node.children.first.source == name (node.type == :fcall || node.type == :command || node.type == :vcall) && node.children.first.source == name
end end
end end

View File

@ -41,8 +41,6 @@ def generate_puppet_provider_list
generate_list_contents generate_list_contents
end end
# A hacked version of class_list that can be instructed to only display certain # A hacked version of class_list that can be instructed to only display certain
# namespace types. This allows us to separate Puppet bits from Ruby bits. # namespace types. This allows us to separate Puppet bits from Ruby bits.
def namespace_list(opts = {}) def namespace_list(opts = {})

View File

@ -87,13 +87,13 @@ class HTMLHelper
result << "(<tt>Unknown</tt>)" result << "(<tt>Unknown</tt>)"
end end
if param[:puppet_type] and param[:parameter] if param[:puppet_type] and param[:parameter]
result << "<b> Parameter </b>" result << "(Parameter) "
elsif param[:puppet_type] and param[:property] elsif param[:puppet_type] and param[:property]
result << "<b> Property </b>" result << "(Property) "
end end
if param[:namevar] if param[:namevar]
result << "<b> Namevar </b>" result << "(Namevar) "
end end
if param[:default] if param[:default]
result << " Default value: <tt>" << param[:default] << "</tt> " result << " Default value: <tt>" << param[:default] << "</tt> "
@ -112,8 +112,13 @@ class HTMLHelper
if param[:desc] if param[:desc]
result << " - <div class=\"inline\"><p> #{param[:desc]} </p></div>" result << " - <div class=\"inline\"><p> #{param[:desc]} </p></div>"
end end
if !param[:exists?]
result << "</strike>"
end
if param[:allowed_values] and param[:allowed_values] != [] if param[:allowed_values] and param[:allowed_values] != []
result << "<h4> Allowed Values: </h4>" result << "<b> Allowed Values: </b>"
result << "<ul>" result << "<ul>"
param[:allowed_values].each do |value_thing| param[:allowed_values].each do |value_thing|
result << "<li>" result << "<li>"
@ -126,11 +131,6 @@ class HTMLHelper
result << "</ul>" result << "</ul>"
end end
if !param[:exists?]
result << "</strike>"
end
result << "</li>" result << "</li>"
end end

View File

@ -25,12 +25,10 @@ def parameter_details
@param_details = (object.parameter_details + object.property_details).each { @param_details = (object.parameter_details + object.property_details).each {
|h| h[:desc] = htmlify(Puppet::Util::Docs::scrub(h[:desc])) if h[:desc] |h| h[:desc] = htmlify(Puppet::Util::Docs::scrub(h[:desc])) if h[:desc]
}.sort { |a, b| a[:name] <=> b[:name] } }.sort { |a, b| a[:name] <=> b[:name] }
if ensurable = @param_details.index { |h| h[:name] == 'ensure' } # Float ensurable and namevars to the top of the list
@param_details = @param_details.unshift(@param_details.delete_at(ensurable)) @param_details = @param_details.partition{|a| a[:name] == 'ensure'}.flatten
end @param_details = @param_details.partition{|a| a[:namevar]}.flatten
if namevar = @param_details.index { |h| h[:namevar] }
@param_details = @param_details.unshift(@param_details.delete_at(namevar))
end
@feature_details = object.features @feature_details = object.features
@template_helper.check_parameters_match_docs object @template_helper.check_parameters_match_docs object