Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Vendor a version of ActiveSupport’s strip_heredoc.

  • Loading branch information...
commit 6408f62f2a057987f55f3065b426e2a48bf62b3f 1 parent e7c22ae
@alloy alloy authored
Showing with 22 additions and 7 deletions.
  1. +2 −3 examples/make.rb
  2. +14 −2 lib/claide.rb
  3. +6 −2 spec/claide_spec.rb
View
5 examples/make.rb
@@ -4,10 +4,9 @@
require 'claide'
-# Loading these third-party gems will automatically color some of CLAide’s
-# output and strip heredoc strings from its indentation.
+# Loading this third-part gem will automatically cause CLAide to color some of
+# its output.
require 'colored'
-require 'active_support/core_ext/string/strip'
class BeverageMaker < CLAide::Command
self.abstract_command = true
View
16 lib/claide.rb
@@ -382,7 +382,8 @@ class << self
# @return [String]
#
# A longer description of the command, which is shown underneath the
- # usage section of the command’s help banner.
+ # usage section of the command’s help banner. Any indentation in this
+ # value will be ignored.
#
attr_accessor :description
@@ -633,7 +634,7 @@ def formatted_options_description
# @visibility private
def formatted_usage_description
if message = self.class.description || self.class.summary
- message = message.strip_heredoc if message.respond_to?(:strip_heredoc)
+ message = strip_heredoc(message)
message = message.split("\n").map { |line| " #{line}" }.join("\n")
args = " #{self.class.arguments}" if self.class.arguments
" $ #{self.class.full_command}#{args}\n\n#{message}"
@@ -685,6 +686,17 @@ def formatted_banner
def help!(error_message = nil)
raise Help.new(self, error_message)
end
+
+ private
+
+ # Lifted straight from ActiveSupport. Thanks guys!
+ def strip_heredoc(string)
+ if min = string.scan(/^[ \t]*(?=\S)/).min
+ string.gsub(/^[ \t]{#{min.size}}/, '')
+ else
+ string
+ end
+ end
end
end
View
8 spec/claide_spec.rb
@@ -101,7 +101,10 @@ class Repo < Lint
class Create < SpecFile
self.summary = 'Creates a spec file stub.'
- self.description = 'Creates a spec file called NAME and populates it with defaults.'
+ self.description = <<-DESC
+ Creates a spec file called NAME
+ and populates it with defaults.
+ DESC
self.arguments = '[NAME]'
attr_reader :spec
@@ -225,7 +228,8 @@ module CLAide
Fixture::Command::SpecFile::Create.parse([]).formatted_usage_description.should == <<-USAGE.rstrip
$ bin spec-file create [NAME]
- Creates a spec file called NAME and populates it with defaults.
+ Creates a spec file called NAME
+ and populates it with defaults.
USAGE
end
Please sign in to comment.
Something went wrong with that request. Please try again.