Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) Improve Puppet::Util::Docs.scrub's handling of one-liners #2361

Merged
merged 1 commit into from Feb 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/puppet/util/docs.rb
Expand Up @@ -112,8 +112,8 @@ def markdown_definitionlist(term, definition)
#
# See tests in spec/unit/util/docs_spec.rb for examples.
def scrub(text)
# One-liners are easy!
return text.strip if text !~ /\n/
# One-liners are easy! (One-liners may be buffered with extra newlines.)
return text.strip if text.strip !~ /\n/
excluding_first_line = text.partition("\n").last
indent = excluding_first_line.scan(/^[ \t]*(?=\S)/).min || '' # prevent nil
# Clean hanging indent, if any
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/util/docs_spec.rb
Expand Up @@ -85,6 +85,15 @@
expect(Puppet::Util::Docs.scrub(my_cleaned_output)).to eq my_cleaned_output
end

it "trims leading space from one-liners (even when they're buffered with extra newlines)" do
input = "
Updates values in the `puppet.conf` configuration file.
"
expected_output = "Updates values in the `puppet.conf` configuration file."
output = Puppet::Util::Docs.scrub(input)
expect(output).to eq expected_output
end


end
end
Expand Down