puppet-strings 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/lib/puppet-strings/rake_tasks.rb +18 -0
  3. data/lib/puppet/application/strings.rb +4 -0
  4. data/lib/puppet/face/strings.rb +64 -0
  5. data/lib/puppet/feature/rgen.rb +3 -0
  6. data/lib/puppet/feature/yard.rb +3 -0
  7. data/lib/puppet_x/puppetlabs/strings.rb +64 -0
  8. data/lib/puppet_x/puppetlabs/strings/actions.rb +92 -0
  9. data/lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb +79 -0
  10. data/lib/puppet_x/puppetlabs/strings/pops/yard_transformer.rb +47 -0
  11. data/lib/puppet_x/puppetlabs/strings/util.rb +65 -0
  12. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/defined_type_object.rb +33 -0
  13. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/host_class_object.rb +22 -0
  14. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/method_object.rb +62 -0
  15. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/provider_object.rb +24 -0
  16. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/puppet_namespace_object.rb +48 -0
  17. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/type_object.rb +42 -0
  18. data/lib/puppet_x/puppetlabs/strings/yard/core_ext/yard.rb +40 -0
  19. data/lib/puppet_x/puppetlabs/strings/yard/handlers/base.rb +13 -0
  20. data/lib/puppet_x/puppetlabs/strings/yard/handlers/defined_type_handler.rb +31 -0
  21. data/lib/puppet_x/puppetlabs/strings/yard/handlers/heredoc_helper.rb +80 -0
  22. data/lib/puppet_x/puppetlabs/strings/yard/handlers/host_class_handler.rb +42 -0
  23. data/lib/puppet_x/puppetlabs/strings/yard/handlers/provider_handler.rb +95 -0
  24. data/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb +54 -0
  25. data/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb +234 -0
  26. data/lib/puppet_x/puppetlabs/strings/yard/handlers/type_handler.rb +295 -0
  27. data/lib/puppet_x/puppetlabs/strings/yard/json_registry_store.rb +85 -0
  28. data/lib/puppet_x/puppetlabs/strings/yard/monkey_patches.rb +68 -0
  29. data/lib/puppet_x/puppetlabs/strings/yard/parser.rb +30 -0
  30. data/lib/puppet_x/puppetlabs/strings/yard/tags/directives.rb +9 -0
  31. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/docstring.erb +34 -0
  32. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/header.erb +5 -0
  33. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/parameter_details.erb +6 -0
  34. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/setup.rb +1 -0
  35. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/setup.rb +49 -0
  36. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_class.erb +2 -0
  37. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_manifest.erb +1 -0
  38. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_plugin.erb +21 -0
  39. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +1 -0
  40. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +1 -0
  41. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/setup.rb +82 -0
  42. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/box_info.erb +22 -0
  43. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/setup.rb +1 -0
  44. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/subclasses.erb +4 -0
  45. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/setup.rb +21 -0
  46. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/html_helper.rb +139 -0
  47. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/layout/html/setup.rb +18 -0
  48. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/html/header.erb +17 -0
  49. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/setup.rb +21 -0
  50. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/text/header.erb +2 -0
  51. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/command_details.erb +8 -0
  52. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/confine_details.erb +10 -0
  53. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/default_details.erb +10 -0
  54. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/docstring.erb +34 -0
  55. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/feature_details.erb +10 -0
  56. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/header.erb +5 -0
  57. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/setup.rb +1 -0
  58. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/setup.rb +50 -0
  59. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/box_info.erb +11 -0
  60. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/header.erb +5 -0
  61. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_details_list.erb +53 -0
  62. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_summary.erb +20 -0
  63. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/setup.rb +1 -0
  64. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/setup.rb +91 -0
  65. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/template_helper.rb +192 -0
  66. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/docstring.erb +34 -0
  67. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/header.erb +5 -0
  68. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/parameter_details.erb +12 -0
  69. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/provider_details.erb +10 -0
  70. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/setup.rb +1 -0
  71. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/setup.rb +55 -0
  72. metadata +142 -0
@@ -0,0 +1,21 @@
1
+ include T('default/definedtype')
2
+
3
+ def init
4
+ super
5
+ sections.push :subclasses
6
+ end
7
+
8
+ def subclasses
9
+ # The naming is a bit weird because Ruby classes use `globals.subclasses`.
10
+ unless globals.hostsubclasses
11
+ globals.hostsubclasses = {}
12
+ list = run_verifier Registry.all(:hostclass)
13
+ list.each {|o| (globals.hostsubclasses[o.parent_class.path] ||= []) << o if o.parent_class }
14
+ end
15
+
16
+ @subclasses = globals.hostsubclasses[object.path]
17
+
18
+ return if @subclasses.nil? || @subclasses.empty?
19
+ erb(:subclasses)
20
+ end
21
+
@@ -0,0 +1,139 @@
1
+ # A class containing helper methods to aid the generation of HTML
2
+ # given formatted data
3
+ class HTMLHelper
4
+
5
+ # Generates the HTML to format the relevant data about return values
6
+ def generate_return_types(types, desc = nil)
7
+ result = []
8
+
9
+ result << "(<span class=\"type\"><tt>" << types.join(", ") << "</tt></span>)"
10
+
11
+ if !desc.nil?
12
+ result << "- <div class=\"inline\"><p>#{desc}</p></div>"
13
+ end
14
+
15
+ result.join
16
+ end
17
+
18
+ def generate_features features, object
19
+ result = []
20
+
21
+ if features
22
+ features.each do |feat|
23
+ result << "<li>"
24
+ result << "<span class=\"name\">#{feat[:name]} </span>"
25
+ if feat[:desc]
26
+ result << "- <br/><div class=\"inline\"><p> #{feat[:desc]} </p></div>"
27
+ end
28
+ if feat[:methods]
29
+ result << "<h3> Methods </h3>"
30
+ result << "<ul>"
31
+ feat[:methods].each do |method|
32
+ result << "<li> <tt>" << method << "</tt> </li>"
33
+ end
34
+ result << "</ul>"
35
+ end
36
+ result << "</li>"
37
+ end
38
+ end
39
+ result.join
40
+ end
41
+
42
+ # Generates the HTML to format the relevant data about parameters
43
+ def generate_parameters(params, object)
44
+ result = []
45
+
46
+ params.each do |param|
47
+ result << "<li>"
48
+
49
+ # Parameters which are documented in the comments but not
50
+ # present in the code itself are given the strike through
51
+ # styling in order to show the reader that they do not actually
52
+ # exist
53
+ if !param[:exists?]
54
+ result << "<strike>"
55
+ end
56
+
57
+ result << "<span class=\"name\">#{param[:name]} </span>"
58
+ result << "<span class=\"type\">"
59
+
60
+ # If the docstring specifies types, use those
61
+ if param[:types]
62
+ result << "(" << "<tt>" << param[:types].join(", ") << "</tt>" << ")"
63
+ # Otherwise, if typing information could be extracted from the object
64
+ # itself, use that
65
+ elsif object.type_info
66
+ # If the parameter name includes the default value, scrub that.
67
+ if param[:name].match(/([^=]*)=/)
68
+ param_name = $1
69
+ else
70
+ param_name = param[:name]
71
+ end
72
+ # Collect all the possible types from the object. If no such type
73
+ # exists for this parameter name don't do anything.
74
+ possible_types = object.type_info.map {
75
+ |sig| sig[param_name] or nil
76
+ }.compact
77
+
78
+ # If no possible types could be determined, put the type down as
79
+ # Unknown
80
+ if possible_types == []
81
+ result << "(" << "<tt>Unknown</tt>" << ")"
82
+ else
83
+ result << "(" << "<tt>" << possible_types.join(", ") << "</tt>" << ")"
84
+ end
85
+ # Give up. It can probably be anything.
86
+ elsif not (param[:puppet_3_func] or param[:puppet_type])
87
+ result << "(<tt>Unknown</tt>)"
88
+ end
89
+ if param[:puppet_type] and param[:parameter]
90
+ result << "(Parameter) "
91
+ elsif param[:puppet_type] and param[:property]
92
+ result << "(Property) "
93
+ end
94
+
95
+ if param[:namevar]
96
+ result << "(Namevar) "
97
+ end
98
+ if param[:default]
99
+ result << " Default value: <tt>" << param[:default] << "</tt> "
100
+ end
101
+
102
+ result << "</span>"
103
+
104
+ # This is only relevant for manifests, not puppet functions
105
+ # This is due to the fact that the scope of a parameter (as illustrated by
106
+ # by it's fully qualified name) is not relevant for the parameters in puppet
107
+ # functions, but may be for components of a manifest (i.e. classes)
108
+ unless param[:fq_name].nil?
109
+ result << "<tt> => #{param[:fq_name]}</tt>"
110
+ end
111
+
112
+ if param[:desc]
113
+ result << " - <div class=\"inline\"><p> #{param[:desc]} </p></div>"
114
+ end
115
+
116
+ if !param[:exists?]
117
+ result << "</strike>"
118
+ end
119
+
120
+ if param[:allowed_values] and param[:allowed_values] != []
121
+ result << "\n<b> Allowed Values: </b>"
122
+ result << "<ul>"
123
+ param[:allowed_values].each do |value_thing|
124
+ result << "<li>"
125
+ result << "<tt>" << value_thing.first << "</tt>"
126
+ if value_thing[1]
127
+ result << " only available if " << "<tt>" << value_thing[1] << "</tt>"
128
+ end
129
+ result << "</li>"
130
+ end
131
+ result << "</ul>\n"
132
+ end
133
+
134
+ result << "</li>"
135
+ end
136
+
137
+ result.join
138
+ end
139
+ end
@@ -0,0 +1,18 @@
1
+ # TODO: This should be extendable. However, the re-assignment of
2
+ # @objects_by_letter prevents that. Submit a pull request.
3
+ def index
4
+ @objects_by_letter = {}
5
+ objects = Registry.all(:class, :module, :type, :puppetnamespace, :hostclass, :definedtype, :provider).sort_by {|o| o.name.to_s }
6
+ objects = run_verifier(objects)
7
+ objects.each {|o| (@objects_by_letter[o.name.to_s[0,1].upcase] ||= []) << o }
8
+ erb(:index)
9
+ end
10
+
11
+ def menu_lists
12
+ [
13
+ {:type => 'puppet_manifest', :title => 'Puppet Manifests', :search_title => "Puppet Manifest List"},
14
+ {:type => 'puppet_plugin', :title => 'Puppet Plugins', :search_title => "Puppet Plugin List"},
15
+ {:type => 'puppet_type', :title => 'Puppet Types', :search_title => "Puppet Type List"},
16
+ {:type => 'puppet_provider', :title => 'Puppet Providers', :search_title => "Puppet Provider List"},
17
+ ] + super
18
+ end
@@ -0,0 +1,17 @@
1
+ <h1>Method: <%= object.path %></h1>
2
+ <div class="box_info">
3
+ <dl>
4
+ <dt class="">Defined in:</dt>
5
+ <dd class="">
6
+ <%= object.file %><% if object.files.size > 1 %><span class="defines">,<br />
7
+ <%= object.files[1..-1].map {|f| f.first }.join(",<br /> ") %></div>
8
+ <% end %>
9
+ </dd>
10
+ </dl>
11
+ </div>
12
+
13
+ <div class="method_details_list">
14
+ <div id="method_details">
15
+ <%= yieldall :index => 0 %>
16
+ </div>
17
+ </div>
@@ -0,0 +1,21 @@
1
+ include T('default/module')
2
+ require File.join(File.dirname(__FILE__),'../html_helper')
3
+ require File.join(File.dirname(__FILE__),'../template_helper')
4
+
5
+ def init
6
+ sections :header, [:method_signature, T('docstring'), :source]
7
+ parents = YARD::Registry.all(:method).reject do |item|
8
+ item.name == object.name and item.namespace === PuppetX::PuppetLabs::Strings::YARD::CodeObjects::PuppetNamespaceObject
9
+ end
10
+ if parents.length == 0
11
+ @template_helper = TemplateHelper.new
12
+ @template_helper.check_parameters_match_docs object
13
+ end
14
+ end
15
+
16
+ def source
17
+ return if owner != object.namespace
18
+ return if Tags::OverloadTag === object
19
+ return if object.source.nil?
20
+ erb(:source)
21
+ end
@@ -0,0 +1,8 @@
1
+ <h2>Commands Summary</h2>
2
+ <div class="tags">
3
+ <ul class="command">
4
+ <% @command_details.each do |command| %>
5
+ <li><tt><%= command %></tt></li>
6
+ <% end %>
7
+ </ul>
8
+ </div>
@@ -0,0 +1,10 @@
1
+ <h2>Confines</h2>
2
+ <% if @confine_details != {} %>
3
+ <div class="tags">
4
+ <ul class="command">
5
+ <% @confine_details.each_pair do |key, value| %>
6
+ <li><tt><%= key %> - <%= value %></tt></li>
7
+ <% end %>
8
+ </ul>
9
+ </div>
10
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <h2>Defaults</h2>
2
+ <% if @default_details != {} %>
3
+ <div class="tags">
4
+ <ul class="command">
5
+ <% @default_details.each_pair do |key, value| %>
6
+ <li><tt><%= key %> - <%= value %></tt></li>
7
+ <% end %>
8
+ </ul>
9
+ </div>
10
+ <% end %>
@@ -0,0 +1,34 @@
1
+ <div class="docstring">
2
+ <div class="discussion">
3
+ <p><%= htmlify(Puppet::Util::Docs::scrub(@class_details[:desc])) %></p>
4
+ </div>
5
+ </div>
6
+ <div class="tags">
7
+ <% if @class_details[:examples] != {}%>
8
+ <div class="examples">
9
+ <p class="tag_title">Examples:</p>
10
+ <% @class_details[:examples].each do |title, text| %>
11
+ <div class="inline"><p><%= title %></p></div>
12
+ <pre class="example code"><code><span><%= text %></span></code></pre>
13
+ <% end %>
14
+ </div>
15
+ <% end %>
16
+ <% if @class_details[:since] %>
17
+ <p class="tag_title">Since:</p>
18
+ <ul class="since">
19
+ <li>
20
+ <div class="inline">
21
+ <p><%= @class_details[:since] %></p>
22
+ </div>
23
+ </li>
24
+ </ul>
25
+ <% end %>
26
+ <% if @class_details[:return] %>
27
+ <p class="tag_title">Return:</p>
28
+ <ul class="return">
29
+ <li>
30
+ <%= @html_helper.generate_return_types(@class_details[:return][1], @class_details[:return][0]) %>
31
+ </li>
32
+ </ul>
33
+ <% end %>
34
+ </div>
@@ -0,0 +1,10 @@
1
+ <h2>Features</h2>
2
+ <% if @feature_details != [] %>
3
+ <div class="tags">
4
+ <ul class="command">
5
+ <% @feature_details.each do |feature| %>
6
+ <li><tt><%= feature %></tt></li>
7
+ <% end %>
8
+ </ul>
9
+ </div>
10
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <div class='module_header'>
2
+ <h1>
3
+ <%= @header_text %>
4
+ </h1>
5
+ </div>
@@ -0,0 +1,50 @@
1
+ include T('default/module')
2
+
3
+ require File.join(File.dirname(__FILE__),'../html_helper')
4
+ require File.join(File.dirname(__FILE__),'../template_helper')
5
+
6
+ def init
7
+ sections :header, :box_info, :pre_docstring, :docstring, :command_details, :confine_details, :default_details, :feature_details
8
+
9
+ @template_helper = TemplateHelper.new
10
+ @html_helper = HTMLHelper.new
11
+ end
12
+
13
+ def header
14
+ @header_text = object.header_name
15
+
16
+ erb(:header)
17
+ end
18
+
19
+ def command_details
20
+ @command_details = object.commands
21
+ erb(:command_details)
22
+ end
23
+
24
+ def confine_details
25
+ @confine_details = object.confines
26
+ erb(:confine_details)
27
+ end
28
+
29
+ def default_details
30
+ @default_details = object.defaults
31
+ erb(:default_details)
32
+ end
33
+
34
+ def feature_details
35
+ @feature_details = object.features
36
+ erb(:feature_details)
37
+ end
38
+
39
+ def header
40
+ @header_text = "Puppet Provider: #{object.name}"
41
+
42
+ erb(:header)
43
+ end
44
+
45
+ def docstring
46
+
47
+ @class_details = @template_helper.extract_tag_data(object)
48
+
49
+ erb(:docstring)
50
+ end
@@ -0,0 +1,11 @@
1
+ <dl class="box">
2
+ <dt class="r1 last" style="height: 16px;">Defined in:</dt>
3
+ <dd class="r1 last">
4
+ <% @source_files.each do |file| %>
5
+ <em><%= file[0] %></em>:
6
+ <%= file[1] %>
7
+ <br/>
8
+ <% end %>
9
+ </dd>
10
+ </dl>
11
+ <div class ="clear"></div>
@@ -0,0 +1,5 @@
1
+ <div class='module_header'>
2
+ <h1>
3
+ <%= @header_text %>
4
+ </h1>
5
+ </div>
@@ -0,0 +1,53 @@
1
+ <h2>Function Details</h2>
2
+ <% @class_details.each do |func| %>
3
+ <h3 class="signature" id = <%= "#{func[:name]}-instance_method" %>>
4
+ <strong>
5
+ <% if func[:return] %>
6
+ <%= @html_helper.generate_return_types(func[:return][1]) %>
7
+ <% end %>
8
+ <%= func[:name] %>
9
+ </strong>
10
+ </h3>
11
+ <div class="docstring">
12
+ <div class="discussion">
13
+ <p><%= htmlify(func[:desc]) %></p>
14
+ </div>
15
+ </div>
16
+ <div class="tags">
17
+ <% if func[:examples] != {}%>
18
+ <div class="examples">
19
+ <p class="tag_title">Examples:</p>
20
+ <% func[:examples].each do |title, text| %>
21
+ <div class="inline"><p><%= title %></p></div>
22
+ <pre class="example code"><code><span><%= text %></span></code></pre>
23
+ <% end %>
24
+ </div>
25
+ <% end %>
26
+ <% if func[:since] %>
27
+ <p class="tag_title">Since:</p>
28
+ <ul class="since">
29
+ <li>
30
+ <div class="inline">
31
+ <p><%= func[:since] %></p>
32
+ </div>
33
+ </li>
34
+ </ul>
35
+ <% end %>
36
+ <% if func[:return] %>
37
+ <p class="tag_title">Returns:</p>
38
+ <ul class="return">
39
+ <li>
40
+ <%= @html_helper.generate_return_types(func[:return][1], func[:return][0]) %>
41
+ </li>
42
+ </ul>
43
+ <% end %>
44
+ <% if func[:params] != nil %>
45
+ <p class="tag_title">Parameters:</p>
46
+ <div class="tags">
47
+ <ul class="param">
48
+ <%= @html_helper.generate_parameters(func[:params], object.child) %>
49
+ </ul>
50
+ </div>
51
+ <% end %>
52
+ </div>
53
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <h2>Available Functions</h2>
2
+ <ul class="summary">
3
+ <% @method_details.each do |method| %>
4
+ <li class = "private">
5
+ <span class = "summary_signature">
6
+ <a href =<%= "##{method[:name]}-instance_method"%>>
7
+ <% if ! method[:return_types].nil? %>
8
+ <%= @html_helper.generate_return_types(method[:return_types]) %>
9
+ <% end %>
10
+ -
11
+ <strong><%= method[:name] %></strong>
12
+ </span>
13
+ </li></a>
14
+ <span class = "summary_desc">
15
+ <div class = "inline">
16
+ <p><%= method[:short_desc] %></p>
17
+ </div>
18
+ </span>
19
+ <% end %>
20
+ </ul>