Skip to content

Commit ff63023

Browse files
committed
[Spec] Strip indentation to prefix_header and to prepare_command
Closes #51
1 parent 96aff70 commit ff63023

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# CocoaPods Core Changelog
22

3+
## Master
4+
5+
##### Enhancements
6+
7+
* The specification now strips the indentation of the `prefix_header` and
8+
`prepare_command` to aide their declaration as a here document (similarly to
9+
what it already does with the description).
10+
[Fabio Pelosin][irrationalfab]
11+
[#51](https://github.com/CocoaPods/Core/issues/51)
12+
313
## 0.31.0
414

515
##### Enhancements
@@ -18,3 +28,6 @@
1828
## 0.30.0
1929

2030
Introduction of the Changelog.
31+
32+
[irrationalfab]: https://github.com/irrationalfab
33+

lib/cocoapods-core/specification/consumer.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,10 @@ def prepare_hook_name(attr)
347347
# @return [String] the prefix header.
348348
#
349349
def _prepare_prefix_header_contents(value)
350-
value.is_a?(Array) ? value * "\n" : value
350+
if value
351+
value = value.join("\n") if value.is_a?(Array)
352+
value.strip_heredoc.chomp
353+
end
351354
end
352355

353356
# Ensures that the file patterns of the resource bundles are contained in

lib/cocoapods-core/specification/root_attribute_accessors.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def summary
121121
#
122122
def description
123123
description = attributes_hash["description"]
124-
description.strip_heredoc if description
124+
description.strip_heredoc.chomp if description
125125
end
126126

127127
# @return [Array<String>] The list of the URL for the screenshots of
@@ -143,7 +143,8 @@ def documentation_url
143143
# @return [String, Nil] The prepare command of the Pod if specified.
144144
#
145145
def prepare_command
146-
attributes_hash["prepare_command"]
146+
command = attributes_hash["prepare_command"]
147+
command.strip_heredoc.chomp if command
147148
end
148149

149150
#---------------------------------------------------------------------#

spec/specification/consumer_spec.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,16 @@ module Pod
179179
end
180180

181181
it "allows to specify the contents of the prefix header as an array" do
182-
@spec.prefix_header_contents = '#import <UIKit/UIKit.h>', '#import <Foundation/Foundation.h>'
182+
@spec.prefix_header_contents = ['#import <UIKit/UIKit.h>', '#import <Foundation/Foundation.h>']
183+
@consumer.prefix_header_contents.should == "#import <UIKit/UIKit.h>\n#import <Foundation/Foundation.h>"
184+
end
185+
186+
it "strips the indentation of the prefix headers" do
187+
headers = <<-DESC
188+
#import <UIKit/UIKit.h>
189+
#import <Foundation/Foundation.h>
190+
DESC
191+
@spec.prefix_header_contents = headers
183192
@consumer.prefix_header_contents.should == "#import <UIKit/UIKit.h>\n#import <Foundation/Foundation.h>"
184193
end
185194

spec/specification/root_attribute_accessors_spec.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ module Pod
114114
Line2
115115
DESC
116116
@spec.description = desc
117-
@spec.description.should == "Line1\nLine2\n"
117+
@spec.description.should == "Line1\nLine2"
118118
end
119119

120120
it "returns the screenshots" do
@@ -127,8 +127,11 @@ module Pod
127127
@spec.screenshots.should == ['www.example.com/img1.png']
128128
end
129129

130-
it "returns the prepare_command" do
131-
@spec.prepare_command = 'ruby prepare_script.rb'
130+
it "returns the prepare command stripping the indentation" do
131+
command = <<-DESC
132+
ruby prepare_script.rb
133+
DESC
134+
@spec.prepare_command = command
132135
@spec.prepare_command.should == 'ruby prepare_script.rb'
133136
end
134137

0 commit comments

Comments
 (0)