Skip to content

Commit 5ad2eb3

Browse files
authored
Merge pull request #378 from envato/improve_format_lines_for_cloudformation
Improve `#format_lines_for_cloudformation` for readability and performance
2 parents de715c4 + 2479523 commit 5ad2eb3

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The format is based on [Keep a Changelog], and this project adheres to
2424
- Introduce `user_data_file`, `user_data_file_as_lines`, and `include_file`
2525
convenience methods to the YAML ERB template compiler ([#377]).
2626

27-
[2.13.4]: https://github.com/envato/stack_master/compare/v2.13.4...v2.14.0
27+
[2.14.0]: https://github.com/envato/stack_master/compare/v2.13.4...v2.14.0
2828
[#375]: https://github.com/envato/stack_master/pull/375
2929
[#376]: https://github.com/envato/stack_master/pull/376
3030
[#377]: https://github.com/envato/stack_master/pull/377

lib/stack_master/cloudformation_interpolating_eruby.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ def format_lines_for_cloudformation(source)
5050
lines = lines.to_s if lines.is_a?(Symbol)
5151
next(lines) unless lines.is_a?(String)
5252

53-
newlines = Array.new(lines.count("\n"), "\n")
54-
newlines = lines.split("\n").map { |line| "#{line}#{newlines.pop}" }
55-
newlines.insert(0, "\n") if lines.start_with?("\n")
56-
newlines
53+
lines.scan(/[^\n]*\n?/).reject { |x| x == '' }
5754
end
5855
end
5956
end

0 commit comments

Comments
 (0)