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

remove_blank_lines: Add a new function to remove blank Line #239

Merged
merged 1 commit into from
Jan 18, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Thus making it directly usable with the values from facter.
* [`extlib::random_password`](#extlib--random_password): A function to return a string of arbitrary length that contains randomly selected characters.
* [`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.
* [`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
* [`extlib::remove_blank_lines`](#extlib--remove_blank_lines): Remove blank lines from a string
* [`extlib::resources_deep_merge`](#extlib--resources_deep_merge): Deeply merge a "defaults" hash into a "resources" hash like the ones expected by `create_resources()`.
* [`extlib::sort_by_version`](#extlib--sort_by_version): A function that sorts an array of version numbers.
* [`extlib::to_ini`](#extlib--to_ini): This converts a puppet hash to an INI string.
Expand Down Expand Up @@ -1054,6 +1055,24 @@ Data type: `Optional[Hash]`

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

### <a name="extlib--remove_blank_lines"></a>`extlib::remove_blank_lines`

Type: Puppet Language

Remove blank lines from a string

#### `extlib::remove_blank_lines(String[1] $content)`

The extlib::remove_blank_lines function.

Returns: `String[1]` The content with blank lines removed

##### `content`

Data type: `String[1]`

The content to remove blank lines from

### <a name="extlib--resources_deep_merge"></a>`extlib::resources_deep_merge`

Type: Ruby 4.x API
Expand Down
8 changes: 8 additions & 0 deletions functions/remove_blank_lines.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# @summary Remove blank lines from a string
# @param content The content to remove blank lines from
# @return The content with blank lines removed
function extlib::remove_blank_lines (
String[1] $content,
) >> String[1] {
return $content.split("\n").filter |$x| { !$x.empty }.join("\n")
}
20 changes: 20 additions & 0 deletions spec/functions/remove_blank_lines_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require 'spec_helper'

input = <<-TEXT
string_name: "string_value"

int_name: 42

true_name: yes
TEXT
output = <<-TEXT.chomp
string_name: "string_value"
int_name: 42
true_name: yes
TEXT

describe 'extlib::remove_blank_lines' do
it { is_expected.to run.with_params(input).and_return(output) }
end
Loading