diff options
author | José Valim <jose.valim@gmail.com> | 2010-08-30 15:55:07 -0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-08-30 15:55:10 -0300 |
commit | d37a65307d280e47eb5c15b61c0b20ac6cab6a84 (patch) | |
tree | 39f6e9036ab11b5059f34e72e65dfeca84bcbbff /activesupport/lib | |
parent | 3c8e1f99b9613cca4813e2a1b062d58ec4b2627b (diff) | |
parent | b422cda2ebfff4032f4c18271e96ad329c413dcc (diff) | |
download | rails-d37a65307d280e47eb5c15b61c0b20ac6cab6a84.tar.gz rails-d37a65307d280e47eb5c15b61c0b20ac6cab6a84.tar.bz2 rails-d37a65307d280e47eb5c15b61c0b20ac6cab6a84.zip |
Merge josevalim/deprecations branch.
I maintained on purpose the DeprecatedUrlOptions in ActionMailer and the Deprecated configuration in Railties because they were already addressed by Piotr in his RSoC work.
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string.rb | 3 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/strip.rb | 26 |
2 files changed, 28 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/string.rb b/activesupport/lib/active_support/core_ext/string.rb index d8d1f9436e..8fb8c31ade 100644 --- a/activesupport/lib/active_support/core_ext/string.rb +++ b/activesupport/lib/active_support/core_ext/string.rb @@ -9,4 +9,5 @@ require 'active_support/core_ext/string/behavior' require 'active_support/core_ext/string/interpolation' require 'active_support/core_ext/string/output_safety' require 'active_support/core_ext/string/exclude' -require 'active_support/core_ext/string/encoding'
\ No newline at end of file +require 'active_support/core_ext/string/encoding' +require 'active_support/core_ext/string/strip' diff --git a/activesupport/lib/active_support/core_ext/string/strip.rb b/activesupport/lib/active_support/core_ext/string/strip.rb new file mode 100644 index 0000000000..086c610976 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/string/strip.rb @@ -0,0 +1,26 @@ +require 'active_support/core_ext/object/try' + +class String + # Strips indentation in heredocs. + # + # For example in + # + # if options[:usage] + # puts <<-USAGE.strip_heredoc + # This command does such and such. + # + # Supported options are: + # -h This message + # ... + # USAGE + # end + # + # the user would see the usage message aligned against the left margin. + # + # Technically, it looks for the least indented line in the whole string, and removes + # that amount of leading whitespace. + def strip_heredoc + indent = scan(/^[ \t]*(?=\S)/).min.try(:size) || 0 + gsub(/^[ \t]{#{indent}}/, '') + end +end |