From ff63023cb554bb07705df1bd6e692609e3ec74ae Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Tue, 1 Apr 2014 13:02:19 +0200 Subject: [PATCH] [Spec] Strip indentation to prefix_header and to prepare_command Closes #51 --- CHANGELOG.md | 13 +++++++++++++ lib/cocoapods-core/specification/consumer.rb | 5 ++++- .../specification/root_attribute_accessors.rb | 5 +++-- spec/specification/consumer_spec.rb | 11 ++++++++++- spec/specification/root_attribute_accessors_spec.rb | 9 ++++++--- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33b7b67d90..78d95e2074 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # CocoaPods Core Changelog +## Master + +##### Enhancements + +* The specification now strips the indentation of the `prefix_header` and + `prepare_command` to aide their declaration as a here document (similarly to + what it already does with the description). + [Fabio Pelosin][irrationalfab] + [#51](https://github.com/CocoaPods/Core/issues/51) + ## 0.31.0 ##### Enhancements @@ -18,3 +28,6 @@ ## 0.30.0 Introduction of the Changelog. + +[irrationalfab]: https://github.com/irrationalfab + diff --git a/lib/cocoapods-core/specification/consumer.rb b/lib/cocoapods-core/specification/consumer.rb index 3d24bf7dbc..b9f3f2767f 100644 --- a/lib/cocoapods-core/specification/consumer.rb +++ b/lib/cocoapods-core/specification/consumer.rb @@ -347,7 +347,10 @@ def prepare_hook_name(attr) # @return [String] the prefix header. # def _prepare_prefix_header_contents(value) - value.is_a?(Array) ? value * "\n" : value + if value + value = value.join("\n") if value.is_a?(Array) + value.strip_heredoc.chomp + end end # Ensures that the file patterns of the resource bundles are contained in diff --git a/lib/cocoapods-core/specification/root_attribute_accessors.rb b/lib/cocoapods-core/specification/root_attribute_accessors.rb index ead37cc0db..c381e55cb3 100644 --- a/lib/cocoapods-core/specification/root_attribute_accessors.rb +++ b/lib/cocoapods-core/specification/root_attribute_accessors.rb @@ -121,7 +121,7 @@ def summary # def description description = attributes_hash["description"] - description.strip_heredoc if description + description.strip_heredoc.chomp if description end # @return [Array] The list of the URL for the screenshots of @@ -143,7 +143,8 @@ def documentation_url # @return [String, Nil] The prepare command of the Pod if specified. # def prepare_command - attributes_hash["prepare_command"] + command = attributes_hash["prepare_command"] + command.strip_heredoc.chomp if command end #---------------------------------------------------------------------# diff --git a/spec/specification/consumer_spec.rb b/spec/specification/consumer_spec.rb index ac1a4aa597..0ee33cc3ce 100644 --- a/spec/specification/consumer_spec.rb +++ b/spec/specification/consumer_spec.rb @@ -179,7 +179,16 @@ module Pod end it "allows to specify the contents of the prefix header as an array" do - @spec.prefix_header_contents = '#import ', '#import ' + @spec.prefix_header_contents = ['#import ', '#import '] + @consumer.prefix_header_contents.should == "#import \n#import " + end + + it "strips the indentation of the prefix headers" do + headers = <<-DESC + #import + #import + DESC + @spec.prefix_header_contents = headers @consumer.prefix_header_contents.should == "#import \n#import " end diff --git a/spec/specification/root_attribute_accessors_spec.rb b/spec/specification/root_attribute_accessors_spec.rb index eccb03ab21..82bc960abe 100644 --- a/spec/specification/root_attribute_accessors_spec.rb +++ b/spec/specification/root_attribute_accessors_spec.rb @@ -114,7 +114,7 @@ module Pod Line2 DESC @spec.description = desc - @spec.description.should == "Line1\nLine2\n" + @spec.description.should == "Line1\nLine2" end it "returns the screenshots" do @@ -127,8 +127,11 @@ module Pod @spec.screenshots.should == ['www.example.com/img1.png'] end - it "returns the prepare_command" do - @spec.prepare_command = 'ruby prepare_script.rb' + it "returns the prepare command stripping the indentation" do + command = <<-DESC + ruby prepare_script.rb + DESC + @spec.prepare_command = command @spec.prepare_command.should == 'ruby prepare_script.rb' end