Skip to content

Commit 7c06ed7

Browse files
committed
(PDOC-184) block pointless output and re-add options
This makes sure the markdown doesn't include section headers that have no content. e.g. '## Classes' does not get put in if there are no classes. Also, we should deprecate --emit-json and --emit-json-stdout instead of just killing them.
1 parent 1374b67 commit 7c06ed7

7 files changed

Lines changed: 33 additions & 12 deletions

File tree

lib/puppet-strings.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def self.generate(search_patterns = DEFAULT_SEARCH_PATTERNS, options = {})
2929
args << '--backtrace' if options[:backtrace]
3030
args << "-m#{options[:markup] || 'markdown'}"
3131

32+
file = nil
3233
if options[:json] || options[:markdown]
3334
file = options[:path]
3435
# Disable output and prevent stats/progress when writing to STDOUT
@@ -47,12 +48,12 @@ def self.generate(search_patterns = DEFAULT_SEARCH_PATTERNS, options = {})
4748

4849
# If outputting JSON, render the output
4950
if options[:json]
50-
render_json(options[:path])
51+
render_json(file)
5152
end
5253

5354
# If outputting Markdown, render the output
5455
if options[:markdown]
55-
render_markdown(options[:path])
56+
render_markdown(file)
5657
end
5758
end
5859

lib/puppet-strings/markdown/puppet_classes.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
module PuppetStrings::Markdown
44
module PuppetClasses
5+
6+
# @return [Array] list of classes
57
def self.in_classes
68
YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash)
79
end
810

911
def self.render
10-
final = "## Classes\n\n"
12+
final = in_classes.length > 0 ? "## Classes\n\n" : ""
1113
in_classes.each do |klass|
1214
final << PuppetStrings::Markdown::PuppetClass.new(klass).render
1315
end

lib/puppet-strings/markdown/puppet_defined_types.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
module PuppetStrings::Markdown
44
module PuppetDefinedTypes
5+
6+
# @return [Array] list of defined types
57
def self.in_dtypes
68
YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash)
79
end
810

911
def self.render
10-
final = "## Defined types\n\n"
12+
final = in_dtypes.length > 0 ? "## Defined types\n\n" : ""
1113
in_dtypes.each do |type|
1214
final << PuppetStrings::Markdown::PuppetDefinedType.new(type).render
1315
end

lib/puppet-strings/markdown/puppet_functions.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
module PuppetStrings::Markdown
44
module PuppetFunctions
5+
6+
# @return [Array] list of functions
57
def self.in_functions
68
YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash)
79
end
810

911
def self.render
10-
final = "## Functions\n\n"
12+
final = in_functions.length > 0 ? "## Functions\n\n" : ""
1113
in_functions.each do |func|
1214
final << PuppetStrings::Markdown::PuppetFunction.new(func).render
1315
end

lib/puppet-strings/markdown/puppet_resource_types.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
module PuppetStrings::Markdown
44
module PuppetResourceTypes
5+
6+
# @return [Array] list of resource types
57
def self.in_rtypes
68
YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash)
79
end
810

911
def self.render
10-
final = "## Resource types\n\n"
12+
final = in_rtypes.length > 0 ? "## Resource types\n\n" : ""
1113
in_rtypes.each do |type|
1214
final << PuppetStrings::Markdown::PuppetResourceType.new(type).render
1315
end

lib/puppet-strings/markdown/templates/table_of_contents.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
<% if puppet_classes -%>
1+
<% if puppet_classes.length > 0 -%>
22
## Classes
33
<% puppet_classes.each do |klassy| -%>
44
* [`<%= klassy[:name] %>`](#<%= klassy[:link] %>): <%= klassy[:desc] %>
55
<% end -%>
66
<% end -%>
7-
<% if puppet_defined_types -%>
7+
<% if puppet_defined_types.length > 0 -%>
88
## Defined types
99
<% puppet_defined_types.each do |dtype| -%>
1010
* [`<%= dtype[:name] %>`](#<%= dtype[:link] %>): <%= dtype[:desc] %>
1111
<% end -%>
1212
<% end -%>
13-
<% if puppet_resource_types -%>
13+
<% if puppet_resource_types.length > 0 -%>
1414
## Resource types
1515
<% puppet_resource_types.each do |rtype| -%>
1616
* [`<%= rtype[:name] %>`](#<%= rtype[:link] %>): <%= rtype[:desc] %>
1717
<% end -%>
1818
<% end -%>
19-
<% if puppet_functions -%>
19+
<% if puppet_functions.length > 0 -%>
2020
## Functions
2121
<% puppet_functions.each do |func| -%>
2222
* [`<%= func[:name] %>`](#<%= func[:link] %>): <%= func[:desc] %>

lib/puppet/face/strings.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
option '--markup FORMAT' do
1717
summary "The markup format to use for docstring text (defaults to 'markdown')."
1818
end
19+
option '--emit-json-stdout' do
20+
summary 'DEPRECATED: Print JSON representation of the documentation to stdout.'
21+
end
22+
option '--emit-json PATH' do
23+
summary 'DEPRECATED: Write JSON representation of the documentation to the given file.'
24+
end
1925

2026
summary 'Generate documentation from files.'
2127
arguments '[[search_pattern] ...]'
@@ -94,14 +100,20 @@ def build_generate_options(options = nil, *yard_args)
94100
generate_options[:yard_args] = yard_args unless yard_args.empty?
95101

96102
if options
103+
if options[:emit_json]
104+
$stderr.puts "WARNING: '--emit-json PATH' is deprecated. Use '--format json --out PATH' instead."
105+
end
106+
if options[:emit_json_stdout]
107+
$stderr.puts "WARNING: '--emit-json-stdout' is deprecated. Use '--format json' instead."
108+
end
97109
markup = options[:markup]
98110
generate_options[:markup] = markup if markup
99111
generate_options[:path] = options[:out] if options[:out]
100112
generate_options[:stdout] = options[:stdout]
101113
format = options[:format] || ""
102-
if format.casecmp 'markdown'
114+
if format.casecmp('markdown') == 0
103115
generate_options[:markdown] = true
104-
elsif format.casecmp 'json'
116+
elsif format.casecmp('json') == 0 || options[:emit_json] || options[:emit_json_stdout]
105117
generate_options[:json] = true
106118
end
107119
end

0 commit comments

Comments
 (0)