yard-chefdoc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +15 -0
  3. data/LICENSE +20 -0
  4. data/README.md +103 -0
  5. data/Rakefile +30 -0
  6. data/lib/yard/cli/stats.rb +142 -0
  7. data/lib/yard-chefdoc/code_objects/attribute.rb +43 -0
  8. data/lib/yard-chefdoc/code_objects/chef.rb +116 -0
  9. data/lib/yard-chefdoc/code_objects/cookbook.rb +55 -0
  10. data/lib/yard-chefdoc/code_objects/recipe.rb +29 -0
  11. data/lib/yard-chefdoc/code_objects/resource.rb +70 -0
  12. data/lib/yard-chefdoc/handlers/attribute.rb +32 -0
  13. data/lib/yard-chefdoc/handlers/base.rb +36 -0
  14. data/lib/yard-chefdoc/handlers/cookbook.rb +40 -0
  15. data/lib/yard-chefdoc/handlers/recipe.rb +15 -0
  16. data/lib/yard-chefdoc/handlers/resource_action.rb +31 -0
  17. data/lib/yard-chefdoc/handlers/resource_default_action.rb +16 -0
  18. data/lib/yard-chefdoc/handlers/resource_property.rb +54 -0
  19. data/lib/yard-chefdoc/handlers/resource_resource_name.rb +16 -0
  20. data/lib/yard-chefdoc/template_helpers/chef.rb +24 -0
  21. data/lib/yard-chefdoc/version.rb +9 -0
  22. data/lib/yard-chefdoc.rb +50 -0
  23. data/spec/attributes_spec.rb +19 -0
  24. data/spec/home_spec.rb +42 -0
  25. data/spec/recipes_spec.rb +15 -0
  26. data/spec/resources_spec.rb +11 -0
  27. data/spec/spec_helper.rb +32 -0
  28. data/templates/default/attribute/html/attribute.erb +30 -0
  29. data/templates/default/attribute/html/setup.rb +5 -0
  30. data/templates/default/cookbook/html/attributes.erb +14 -0
  31. data/templates/default/cookbook/html/cookbook_title.erb +2 -0
  32. data/templates/default/cookbook/html/docstring.erb +1 -0
  33. data/templates/default/cookbook/html/element_details.erb +3 -0
  34. data/templates/default/cookbook/html/generated_docs.erb +2 -0
  35. data/templates/default/cookbook/html/libraries.erb +13 -0
  36. data/templates/default/cookbook/html/metadata.erb +86 -0
  37. data/templates/default/cookbook/html/recipes.erb +14 -0
  38. data/templates/default/cookbook/html/resources.erb +14 -0
  39. data/templates/default/cookbook/html/setup.rb +9 -0
  40. data/templates/default/fulldoc/html/css/chefdoc.css +52 -0
  41. data/templates/default/fulldoc/html/full_list_attributes.erb +14 -0
  42. data/templates/default/fulldoc/html/full_list_libraries.erb +6 -0
  43. data/templates/default/fulldoc/html/full_list_recipes.erb +13 -0
  44. data/templates/default/fulldoc/html/full_list_resources.erb +13 -0
  45. data/templates/default/fulldoc/html/setup.rb +117 -0
  46. data/templates/default/layout/html/layout.erb +24 -0
  47. data/templates/default/layout/html/setup.rb +81 -0
  48. data/templates/default/layout/html/title.erb +1 -0
  49. data/templates/default/recipe/html/recipe.erb +8 -0
  50. data/templates/default/recipe/html/setup.rb +8 -0
  51. data/templates/default/recipe/html/source.erb +10 -0
  52. data/templates/default/resource/html/actions.erb +19 -0
  53. data/templates/default/resource/html/properties.erb +18 -0
  54. data/templates/default/resource/html/resource.erb +3 -0
  55. data/templates/default/resource/html/setup.rb +15 -0
  56. metadata +111 -0
@@ -0,0 +1,52 @@
1
+ table {
2
+ border: 0px;
3
+ }
4
+
5
+ th {
6
+ color: black;
7
+ padding: 5px;
8
+ }
9
+
10
+ td {
11
+ padding: 10px;
12
+ }
13
+
14
+ tr.r1 { background: #FFFFFF; }
15
+ tr.r2 { background: #EFEFEF; }
16
+
17
+ .visible {
18
+ display: table;
19
+ }
20
+
21
+ /* Makes the line below not go under metadata table */
22
+ h2 {
23
+ display: flex
24
+ }
25
+
26
+ .metadata-box {
27
+ width: 24em;
28
+ border-collapse: collapse;
29
+ line-height: 1.2em;
30
+ font-size: 88%;
31
+ border: 1px solid #aaa;
32
+ border-spacing: 3px;
33
+ background-color: #f9f9f9;
34
+ color: black;
35
+ margin: 0.5em 0 0.5em 1em;
36
+ padding: 0.2em;
37
+ float: right;
38
+ clear: right;
39
+ }
40
+
41
+ .metadata-box .merged {
42
+ text-align: center;
43
+ padding: 0.25em 0.33em 0.33em;
44
+ line-height: 1.2em;
45
+ font-size: 1.25em;
46
+ }
47
+
48
+ .metadata-box .section {
49
+ text-align: center;
50
+ padding: 0.25em 0.33em 0.33em;
51
+ background-color: #ebebeb;
52
+ }
@@ -0,0 +1,14 @@
1
+ <% even_odd = 'odd' %>
2
+ <% @items.each do |item| %>
3
+ <% even_odd = (even_odd == 'even' ? 'odd' : 'even') %>
4
+ <li id="object_<%= item.path %>" class="<%= even_odd %>">
5
+ <div class="item" style="padding-left:30px">
6
+ <span class='object_link'>
7
+ <a href="<%= url_for(item) %>" title="<%= item.name %>">
8
+ <%= h(item.name) %>
9
+ </a>
10
+ </span>
11
+ <small class='search_info'><%= item.name %></small>
12
+ </div>
13
+ </li>
14
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <li id="object_" class="odd">
2
+ <div class="item" style="padding-left:30px">
3
+ <%= link_object(Registry.root, Registry.root.title, nil, false) %>
4
+ </div>
5
+ </li>
6
+ <%= class_list %>
@@ -0,0 +1,13 @@
1
+ <% even_odd = 'odd' %>
2
+ <% @items.each do |item| %>
3
+ <% even_odd = (even_odd == 'even' ? 'odd' : 'even') %>
4
+ <li id="object_<%= item.path %>" class="<%= even_odd %>">
5
+ <div class="item" style="padding-left:30px">
6
+ <span class='object_link'>
7
+ <a href="<%= url_for(item) %>" title="<%= item.file %>">
8
+ <%= h(item.name) %>
9
+ </a>
10
+ </span>
11
+ </div>
12
+ </li>
13
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <% even_odd = 'odd' %>
2
+ <% @items.each do |item| %>
3
+ <% even_odd = (even_odd == 'even' ? 'odd' : 'even') %>
4
+ <li id="object_<%= item.path %>" class="<%= even_odd %>">
5
+ <div class="item" style="padding-left:30px">
6
+ <span class='object_link'>
7
+ <a href="<%= url_for(item) %>" title="<%= item.file %>">
8
+ <%= h(item.name) %>
9
+ </a>
10
+ </span>
11
+ </div>
12
+ </li>
13
+ <% end %>
@@ -0,0 +1,117 @@
1
+ include Helpers::ChefHelper
2
+
3
+ # Register custom stylesheets
4
+ def init
5
+ # Maybe add an API endpoint for stats at some time
6
+ # asset('api/stats.json', JSON.pretty_generate(YARD::CLI::Stats.new(false).statistics_hash))
7
+
8
+ asset('css/chefdoc.css', file('css/chefdoc.css', true))
9
+
10
+ super
11
+ end
12
+
13
+ def stylesheets_full_list
14
+ %w[css/full_list.css css/common.css]
15
+ end
16
+
17
+ # Generates searchable recipe list in the output.
18
+ def generate_recipes_list
19
+ recipes = chefsorted_objects(:recipe)
20
+ generate_full_list(recipes, 'Recipe', 'recipes')
21
+ end
22
+
23
+ # Generates searchable attribute list in the output.
24
+ def generate_attributes_list
25
+ attributes = chefsorted_objects(:attribute)
26
+ generate_full_list(attributes, 'Attribute', 'attributes')
27
+ end
28
+
29
+ # Generates searchable resource list in the output.
30
+ def generate_resources_list
31
+ resources = chefsorted_objects(:resource)
32
+ generate_full_list(resources, 'Resource', 'resources')
33
+ end
34
+
35
+ # Called by menu_lists in layout/html/setup.rb by default
36
+ def generate_libraries_list
37
+ libraries = YARD::Registry.all(:cookbook).first.libraries
38
+ generate_full_list(libraries, 'Library', 'libraries')
39
+ end
40
+
41
+ def generate_full_list(objects, title, type)
42
+ @items = objects
43
+ @list_title = "#{title} List"
44
+ @list_type = type.to_s
45
+ asset(url_for_list(@list_type), erb(:full_list))
46
+ end
47
+
48
+ # The Class and class_list definition below are copies taken from YARD.
49
+ # @api private
50
+ class TreeContext
51
+ def initialize
52
+ @depth = 0
53
+ @even_odd = Alternator.new(:even, :odd)
54
+ end
55
+
56
+ def nest
57
+ @depth += 1
58
+ yield
59
+ @depth -= 1
60
+ end
61
+
62
+ # @return [String] Returns a css pixel offset, e.g. "30px"
63
+ def indent
64
+ "#{(@depth + 2) * 15}px"
65
+ end
66
+
67
+ def classes
68
+ classes = []
69
+ classes << 'collapsed' if @depth > 0
70
+ classes << @even_odd.next if @depth < 2
71
+ classes
72
+ end
73
+
74
+ class Alternator
75
+ def initialize(first, second)
76
+ @next = first
77
+ @after = second
78
+ end
79
+
80
+ def next
81
+ @next, @after = @after, @next
82
+ @after
83
+ end
84
+ end
85
+ end
86
+
87
+ # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
88
+ # @return [String] HTML output of the classes to be displayed in the
89
+ # full_list_class template.
90
+ def class_list(root = Registry.root, tree = TreeContext.new)
91
+ out = ''
92
+ children = run_verifier(root.children)
93
+ if root == Registry.root
94
+ children += @items.select { |o| o.namespace.is_a?(CodeObjects::Proxy) }
95
+ end
96
+ children.compact.sort_by(&:path).each do |child|
97
+ next if child.is_a?(::YARD::CodeObjects::Chef::RecipeObject)
98
+ next unless child.is_a?(CodeObjects::NamespaceObject)
99
+ name = child.namespace.is_a?(CodeObjects::Proxy) ? child.path : child.name
100
+ has_children = run_verifier(child.children).any? { |o| o.is_a?(CodeObjects::NamespaceObject) }
101
+ out << "<li id='object_#{child.path}' class='#{tree.classes.join(' ')}'>"
102
+ out << "<div class='item' style='padding-left:#{tree.indent}'>"
103
+ out << "<a class='toggle'></a> " if has_children
104
+ out << linkify(child, name)
105
+ out << " &lt; #{child.superclass.name}" if child.is_a?(CodeObjects::ClassObject) && child.superclass
106
+ out << "<small class='search_info'>"
107
+ out << child.namespace.title
108
+ out << '</small>'
109
+ out << '</div>'
110
+ tree.nest do
111
+ out << "<ul>#{class_list(child, tree)}</ul>" if has_children
112
+ end
113
+ out << '</li>'
114
+ end
115
+ out
116
+ end
117
+ # rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <%= erb(:headers) %>
5
+ </head>
6
+ <body>
7
+ <div class="nav_wrap">
8
+ <iframe id="nav" src="<%= @nav_url %>?1"></iframe>
9
+ <div id="resizer"></div>
10
+ </div>
11
+
12
+ <div id="main" tabindex="-1">
13
+ <div id="header">
14
+ <%= erb(:breadcrumb) %>
15
+ <%= erb(:search) %>
16
+ <div class="clear"></div>
17
+ </div>
18
+
19
+ <div id="content"><%= yieldall %></div>
20
+
21
+ <%= erb(:footer) %>
22
+ </div>
23
+ </body>
24
+ </html>
@@ -0,0 +1,81 @@
1
+ def init
2
+ super
3
+ @page_title = page_title
4
+ if @file
5
+ if @file.attributes[:namespace]
6
+ @object = options.object = Registry.at(@file.attributes[:namespace]) || Registry.root
7
+ end
8
+ @breadcrumb_title = "File: #{@file.title}"
9
+ @page_title = 'Cookbook Documentation'
10
+ sections :layout, [:title, [T('cookbook')]]
11
+ elsif object == '_index.html'
12
+ @object = options.object = Registry.root
13
+ sections :layout, [:title, [T('cookbook')]]
14
+ end
15
+ end
16
+
17
+ def layout
18
+ @nav_url = url_for_list(nav_select(options.index || options.object.type))
19
+
20
+ @path = if !object || object.is_a?(String)
21
+ nil
22
+ elsif @file
23
+ @file.path
24
+ elsif !object.is_a?(YARD::CodeObjects::NamespaceObject)
25
+ object.parent.path
26
+ else
27
+ object.path
28
+ end
29
+
30
+ erb(:layout)
31
+ end
32
+
33
+ def nav_select(type)
34
+ case type.to_s
35
+ when 'recipe'
36
+ 'recipes'
37
+ when 'attribute'
38
+ 'attributes'
39
+ when 'resource'
40
+ 'resources'
41
+ when 'module', 'class'
42
+ 'libraries'
43
+ when 'cookbook', 'root'
44
+ 'file'
45
+ else
46
+ 'recipes'
47
+ end
48
+ end
49
+
50
+ def javascripts
51
+ super
52
+ end
53
+
54
+ def stylesheets
55
+ super + %w[css/chefdoc.css]
56
+ end
57
+
58
+ # Add yard-chef specific menus
59
+ # Methods generate_#{type}_list must be defined in fulldoc/html/setup.rb
60
+ def menu_lists
61
+ [
62
+ { type: 'recipes', title: 'Recipes', search_title: 'Recipe List' },
63
+ { type: 'attributes', title: 'Attributes', search_title: 'Attributes List' },
64
+ { type: 'resources', title: 'Resources', search_title: 'Resource List' },
65
+ { type: 'libraries', title: 'Libraries', search_title: 'Libraries List' },
66
+ { type: 'file', title: 'Files', search_title: 'File List' }
67
+ ]
68
+ end
69
+
70
+ def page_title
71
+ if object == '_index.html'
72
+ 'Cookbook Documentation'
73
+ elsif object.is_a? CodeObjects::Base
74
+ case object.type
75
+ when :cookbook
76
+ "Cookbook: #{object.name}"
77
+ when :module, :class
78
+ format_object_title(object)
79
+ end
80
+ end
81
+ end
@@ -0,0 +1 @@
1
+ <%= yieldall :object => YARD::Registry.all(:cookbook).first %>
@@ -0,0 +1,8 @@
1
+ <h2>Recipe <%= object.name %></h2>
2
+ <div class="method_details">
3
+ <h3 class="signature">
4
+ <a name="<%= object.name %>"><strong><%= object.name %></strong></a>
5
+ </h3>
6
+ <%= htmlify(object.docstring, :markdown) %>
7
+ <%= yieldall :object => object, :owner => object.parent, :index => 1 %>
8
+ </div>
@@ -0,0 +1,8 @@
1
+ def init
2
+ sections.push :recipe, [:source]
3
+ end
4
+
5
+ def source
6
+ return if object.source.nil?
7
+ erb(:source)
8
+ end
@@ -0,0 +1,10 @@
1
+ <table class="source_code visible">
2
+ <tr>
3
+ <td>
4
+ <pre class="lines"><%= "\n\n\n" %><%= h format_lines(object) %></pre>
5
+ </td>
6
+ <td>
7
+ <pre class="code"><span class="info file"># File '<%= h object.file %>'</span><%= "\n\n" %><%= html_syntax_highlight object.source %></pre>
8
+ </td>
9
+ </tr>
10
+ </table>
@@ -0,0 +1,19 @@
1
+ <h2>Actions</h2>
2
+ <h3>Default action: <a href="#action_<%= object.default_action %>"><%= object.default_action %></a></h3>
3
+ <% object.actions.each do |p| %>
4
+ <div>
5
+ <h4><a name="action_<%= p.identifier %>"><%= p.identifier %></a>:</h4>
6
+ <%= htmlify(p.docstring, :markdown) %>
7
+ <span class="showSource">[<a href="#" class="toggleSource">View source</a>]</span>
8
+ <table class="source_code invisible">
9
+ <tr>
10
+ <td>
11
+ <pre class="lines"><%= h format_lines(p) %></pre>
12
+ </td>
13
+ <td>
14
+ <pre class="code"><%= html_syntax_highlight p.source %></pre>
15
+ </td>
16
+ </tr>
17
+ </table>
18
+ </div>
19
+ <% end %>
@@ -0,0 +1,18 @@
1
+ <h2>Properties</h2>
2
+ <% object.properties.each do |p| %>
3
+ <div>
4
+ <h4><%= p.identifier %>:</h4>
5
+ <% unless p.type.nil? %>
6
+ Type: <code><%= p.type %></code>
7
+ <% end %>
8
+ <% unless p.options.nil? %>
9
+ <p>Other options</p>
10
+ <ul>
11
+ <% p.options.each do |option, value| %>
12
+ <li><%= option %>: <code><%= value %></code></li>
13
+ <% end %>
14
+ </ul>
15
+ <% end %>
16
+ <%= htmlify(p.docstring, :markdown) %>
17
+ </div>
18
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <h2>Resource <%= object.name %></h2>
2
+ <%= htmlify(object.docstring, :markdown) %>
3
+ <%= yieldall :object => object, :owner => object.parent, :index => 1 %>
@@ -0,0 +1,15 @@
1
+ include Helpers::ChefHelper
2
+
3
+ def init
4
+ sections.push :resource, %i[properties actions]
5
+ end
6
+
7
+ def properties
8
+ return if object.properties.empty?
9
+ erb(:properties)
10
+ end
11
+
12
+ def name_property?(options)
13
+ return false if options.nil?
14
+ options.key?('name_property') && options['name_property'] == 'true'
15
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yard-chefdoc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jörg Herzinger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.9
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.9
27
+ description:
28
+ email: joerg.herzinger+chefdoc@oiml.at
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/yard-chefdoc.rb
38
+ - lib/yard-chefdoc/code_objects/attribute.rb
39
+ - lib/yard-chefdoc/code_objects/chef.rb
40
+ - lib/yard-chefdoc/code_objects/cookbook.rb
41
+ - lib/yard-chefdoc/code_objects/recipe.rb
42
+ - lib/yard-chefdoc/code_objects/resource.rb
43
+ - lib/yard-chefdoc/handlers/attribute.rb
44
+ - lib/yard-chefdoc/handlers/base.rb
45
+ - lib/yard-chefdoc/handlers/cookbook.rb
46
+ - lib/yard-chefdoc/handlers/recipe.rb
47
+ - lib/yard-chefdoc/handlers/resource_action.rb
48
+ - lib/yard-chefdoc/handlers/resource_default_action.rb
49
+ - lib/yard-chefdoc/handlers/resource_property.rb
50
+ - lib/yard-chefdoc/handlers/resource_resource_name.rb
51
+ - lib/yard-chefdoc/template_helpers/chef.rb
52
+ - lib/yard-chefdoc/version.rb
53
+ - lib/yard/cli/stats.rb
54
+ - spec/attributes_spec.rb
55
+ - spec/home_spec.rb
56
+ - spec/recipes_spec.rb
57
+ - spec/resources_spec.rb
58
+ - spec/spec_helper.rb
59
+ - templates/default/attribute/html/attribute.erb
60
+ - templates/default/attribute/html/setup.rb
61
+ - templates/default/cookbook/html/attributes.erb
62
+ - templates/default/cookbook/html/cookbook_title.erb
63
+ - templates/default/cookbook/html/docstring.erb
64
+ - templates/default/cookbook/html/element_details.erb
65
+ - templates/default/cookbook/html/generated_docs.erb
66
+ - templates/default/cookbook/html/libraries.erb
67
+ - templates/default/cookbook/html/metadata.erb
68
+ - templates/default/cookbook/html/recipes.erb
69
+ - templates/default/cookbook/html/resources.erb
70
+ - templates/default/cookbook/html/setup.rb
71
+ - templates/default/fulldoc/html/css/chefdoc.css
72
+ - templates/default/fulldoc/html/full_list_attributes.erb
73
+ - templates/default/fulldoc/html/full_list_libraries.erb
74
+ - templates/default/fulldoc/html/full_list_recipes.erb
75
+ - templates/default/fulldoc/html/full_list_resources.erb
76
+ - templates/default/fulldoc/html/setup.rb
77
+ - templates/default/layout/html/layout.erb
78
+ - templates/default/layout/html/setup.rb
79
+ - templates/default/layout/html/title.erb
80
+ - templates/default/recipe/html/recipe.erb
81
+ - templates/default/recipe/html/setup.rb
82
+ - templates/default/recipe/html/source.erb
83
+ - templates/default/resource/html/actions.erb
84
+ - templates/default/resource/html/properties.erb
85
+ - templates/default/resource/html/resource.erb
86
+ - templates/default/resource/html/setup.rb
87
+ homepage: https://github.com/chefdoc/yard-chefdoc
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.5.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: A ruby yard extension for docuementing Chef cookbooks
111
+ test_files: []