Skip to content

Commit 506723f

Browse files
committed
clean_blank_lines: Add a new function to clean blank Lines
This functions removes all blan lines from a block of text e.g input = ``` foo bar foobar ``` output=``` foo bar foobar ```
1 parent 1fbe9cc commit 506723f

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

REFERENCE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Thus making it directly usable with the values from facter.
2929
* [`extlib::random_password`](#extlib--random_password): A function to return a string of arbitrary length that contains randomly selected characters.
3030
* [`extlib::read_url`](#extlib--read_url): Fetch a string from a URL (should only be used with 'small' remote files). This function should only be used with trusted/internal sources.
3131
* [`extlib::remote_pql_query`](#extlib--remote_pql_query): Perform a PuppetDB query on an arbitrary PuppetDB server If you need to query a PuppetDB server that is not connected to your Puppet Server
32+
* [`extlib::remove_blank_lines`](#extlib--remove_blank_lines): Remove blank lines from a string
3233
* [`extlib::resources_deep_merge`](#extlib--resources_deep_merge): Deeply merge a "defaults" hash into a "resources" hash like the ones expected by `create_resources()`.
3334
* [`extlib::sort_by_version`](#extlib--sort_by_version): A function that sorts an array of version numbers.
3435
* [`extlib::to_ini`](#extlib--to_ini): This converts a puppet hash to an INI string.
@@ -1054,6 +1055,24 @@ Data type: `Optional[Hash]`
10541055

10551056
PuppetDB query options. (See https://www.puppet.com/docs/puppetdb/8/api/query/v4/paging)
10561057

1058+
### <a name="extlib--remove_blank_lines"></a>`extlib::remove_blank_lines`
1059+
1060+
Type: Puppet Language
1061+
1062+
Remove blank lines from a string
1063+
1064+
#### `extlib::remove_blank_lines(String[1] $content)`
1065+
1066+
The extlib::remove_blank_lines function.
1067+
1068+
Returns: `String[1]` The content with blank lines removed
1069+
1070+
##### `content`
1071+
1072+
Data type: `String[1]`
1073+
1074+
The content to remove blank lines from
1075+
10571076
### <a name="extlib--resources_deep_merge"></a>`extlib::resources_deep_merge`
10581077

10591078
Type: Ruby 4.x API

functions/remove_blank_lines.pp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# @summary Remove blank lines from a string
2+
# @param content The content to remove blank lines from
3+
# @return The content with blank lines removed
4+
function extlib::remove_blank_lines (
5+
String[1] $content,
6+
) >> String[1] {
7+
return $content.split("\n").filter |$x| { !$x.empty }.join("\n")
8+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
input = <<-TEXT
6+
string_name: "string_value"
7+
8+
int_name: 42
9+
10+
true_name: yes
11+
TEXT
12+
output = <<-TEXT.chomp
13+
string_name: "string_value"
14+
int_name: 42
15+
true_name: yes
16+
TEXT
17+
18+
describe 'extlib::remove_blank_lines' do
19+
it { is_expected.to run.with_params(input).and_return(output) }
20+
end

0 commit comments

Comments
 (0)