Skip to content

Commit be43075

Browse files
authored
Merge pull request #218 from seanmil/add_enum_html
Add missing HTML output support for enum tag
2 parents 7eae230 + adb5906 commit be43075

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

lib/puppet-strings/yard/tags/enum_tag.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ class PuppetStrings::Yard::Tags::EnumTag < YARD::Tags::OptionTag
77
# @return [void]
88
def self.register!
99
YARD::Tags::Library.define_tag("puppet.enum", :enum, :with_enums)
10+
YARD::Tags::Library.visible_tags.place(:enum).after(:option)
1011
end
1112
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<% if object.has_tag?(:enum) %>
2+
<% object.parameters.each do |param, default| %>
3+
<% tags = object.tags(:enum).select {|x| x.name.to_s == param.to_s.sub(/^\*+|:$/, '') } %>
4+
<% next if tags.empty? %>
5+
<p class="tag_title">Enum Options (<tt><%= param %></tt>):</p>
6+
<ul class="option">
7+
<% for tag in tags %>
8+
<li>
9+
<span class="name"><%= tag.pair.name %></span>
10+
<% if tag.pair.text && tag.pair.text =~ /\S/ %>
11+
&mdash; <%= htmlify_line(tag.pair.text) %>
12+
<% end %>
13+
</li>
14+
<% end %>
15+
</ul>
16+
<% end %>
17+
<% end %>

lib/puppet-strings/yard/templates/default/tags/setup.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ def param
1616
def overload
1717
erb(if object.type == :puppet_function then :puppet_overload else :overload end)
1818
end
19+
20+
# Renders the enum section.
21+
# @return [String] Returns the rendered section.
22+
def enum
23+
erb(:enum)
24+
end

spec/acceptance/running_strings_generate_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,14 @@ def expect_file_contain(path, expected_contents)
7575
'A simple elephant type.',
7676
])
7777
end
78+
79+
it 'should generate documentation for enum tag' do
80+
expect_file_contain('doc/puppet_classes/test.html', [
81+
'<p class="tag_title">Enum Options (<tt>myenum</tt>):</p>',
82+
'<span class="name">a</span>',
83+
"&mdash; <div class='inline'>\n<p>Option A</p>\n</div>",
84+
'<span class="name">b</span>',
85+
"&mdash; <div class='inline'>\n<p>Option B</p>\n</div>",
86+
])
87+
end
7888
end

spec/fixtures/acceptance/modules/test/manifests/init.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
#
88
# @param package_name The name of the package
99
# @param service_name The name of the service
10+
# @param myenum
11+
# @enum myenum a Option A
12+
# @enum myenum b Option B
1013
class test (
1114
$package_name = $test::params::package_name,
1215
$service_name = $test::params::service_name,
16+
Enum['a', 'b'] $myenum = 'a',
1317

1418
) inherits test::params {
1519

0 commit comments

Comments
 (0)