Skip to content

Commit

Permalink
Merge pull request #239 from voxpupuli/clean_blank_lines
Browse files Browse the repository at this point in the history
clean_blank_lines: Add a new function to clean blank Lines
  • Loading branch information
bastelfreak authored Jan 18, 2025
2 parents 1fbe9cc + 506723f commit b9a30d6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
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

0 comments on commit b9a30d6

Please sign in to comment.