lstrip-on-steroids 0.9.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -4
- data/lib/lstrip-on-steroids.rb +1 -0
- data/lib/lstrip_on_steroids.rb +5 -4
- data/spec/lstrip_on_steroids_spec.rb +76 -0
- metadata +25 -42
data/Rakefile
CHANGED
@@ -2,13 +2,13 @@ require "rake/gempackagetask"
|
|
2
2
|
|
3
3
|
spec = Gem::Specification.new do |s|
|
4
4
|
s.name = "lstrip-on-steroids"
|
5
|
-
s.version = "0.
|
6
|
-
s.
|
7
|
-
s.email =
|
5
|
+
s.version = "1.0.0"
|
6
|
+
s.authors = ["Caius Durling", "Ash Moran"]
|
7
|
+
s.email = %w[ dev@caius.name ash.moran@patchspace.co.uk ]
|
8
8
|
s.homepage = "http://github.com/caius/lstrip-on-steroids"
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.summary = "Intelligently strips leading whitespace from a multiline string"
|
11
|
-
s.files = FileList["lib/**/*.rb", "[A-Z]*"].to_a
|
11
|
+
s.files = FileList["lib/**/*.rb", "spec/**/*.rb", "[A-Z]*"].to_a
|
12
12
|
s.has_rdoc = false
|
13
13
|
end
|
14
14
|
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'lstrip_on_steroids'
|
data/lib/lstrip_on_steroids.rb
CHANGED
@@ -6,17 +6,18 @@ module LStripOnSteroids
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def strip
|
9
|
-
@lines.map {|line| line.sub(/^ {#{whitespace_trim_length}}/, "") }
|
9
|
+
@lines.map {|line| line.sub(/^\s*$/, "").sub(/^ {#{whitespace_trim_length}}/, "") }
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def whitespace_trim_length
|
15
|
-
@whitespace_trim_length ||=
|
15
|
+
@whitespace_trim_length ||=
|
16
|
+
@lines.reject { |line| line =~ /^\s*$/ }.map { |line| indent_size(line) }.min
|
16
17
|
end
|
17
18
|
|
18
19
|
def strip_bare_top_and_bottom
|
19
|
-
[0, -1].each {|i| @lines.delete_at(i) if bare?(@lines[i]) }
|
20
|
+
[0, -1].each { |i| @lines.delete_at(i) if bare?(@lines[i]) }
|
20
21
|
end
|
21
22
|
|
22
23
|
def indent_size line
|
@@ -29,7 +30,7 @@ module LStripOnSteroids
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def -@
|
32
|
-
JuicedStripper.new(split("\n")).strip.join("\n")
|
33
|
+
JuicedStripper.new(split("\n")).strip.join("\n").sub(/\n*\Z/, "")
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "lstrip_on_steroids")
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
describe "#-@" do
|
5
|
+
it "removes whitespace" do
|
6
|
+
string = -%{
|
7
|
+
foo
|
8
|
+
bar
|
9
|
+
baz
|
10
|
+
}
|
11
|
+
|
12
|
+
string.should == "foo\n bar\nbaz"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "handles indented first lines" do
|
16
|
+
string = -%{
|
17
|
+
foo
|
18
|
+
bar
|
19
|
+
baz
|
20
|
+
}
|
21
|
+
|
22
|
+
string.should == " foo\nbar\n baz"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "handles lines with really long indents" do
|
26
|
+
# In case we do the space removal naively
|
27
|
+
|
28
|
+
string = -%{
|
29
|
+
foo
|
30
|
+
bar
|
31
|
+
baz
|
32
|
+
}
|
33
|
+
|
34
|
+
string.should == "foo\n bar\nbaz"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "handles empty lines in the middle" do
|
38
|
+
string = -%{
|
39
|
+
foo
|
40
|
+
|
41
|
+
baz
|
42
|
+
}
|
43
|
+
|
44
|
+
string.should == "foo\n\nbaz"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "handles whitespace-only lines in the middle" do
|
48
|
+
original_string = %{
|
49
|
+
foo
|
50
|
+
|
51
|
+
baz
|
52
|
+
}.sub("\n\n", "\n \n")
|
53
|
+
|
54
|
+
(-original_string).should == "foo\n\nbaz"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "removes blank lines from the end" do
|
58
|
+
original_string =
|
59
|
+
" foo\n" +
|
60
|
+
" \n" +
|
61
|
+
" \n"
|
62
|
+
|
63
|
+
(-original_string).should == "foo"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "works with heredoc strings" do
|
67
|
+
string = -<<-end
|
68
|
+
foo
|
69
|
+
bar
|
70
|
+
baz
|
71
|
+
end
|
72
|
+
|
73
|
+
string.should == "foo\n bar\nbaz"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,68 +1,51 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: lstrip-on-steroids
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 9
|
9
|
-
- 5
|
10
|
-
version: 0.9.5
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Caius Durling
|
9
|
+
- Ash Moran
|
14
10
|
autorequire:
|
15
11
|
bindir: bin
|
16
12
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2010-08-20 00:00:00 +01:00
|
19
|
-
default_executable:
|
13
|
+
date: 2011-08-27 00:00:00.000000000Z
|
20
14
|
dependencies: []
|
21
|
-
|
22
15
|
description:
|
23
|
-
email:
|
16
|
+
email:
|
17
|
+
- dev@caius.name
|
18
|
+
- ash.moran@patchspace.co.uk
|
24
19
|
executables: []
|
25
|
-
|
26
20
|
extensions: []
|
27
|
-
|
28
21
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
|
22
|
+
files:
|
23
|
+
- lib/lstrip-on-steroids.rb
|
31
24
|
- lib/lstrip_on_steroids.rb
|
25
|
+
- spec/lstrip_on_steroids_spec.rb
|
32
26
|
- Rakefile
|
33
|
-
has_rdoc: true
|
34
27
|
homepage: http://github.com/caius/lstrip-on-steroids
|
35
28
|
licenses: []
|
36
|
-
|
37
29
|
post_install_message:
|
38
30
|
rdoc_options: []
|
39
|
-
|
40
|
-
require_paths:
|
31
|
+
require_paths:
|
41
32
|
- lib
|
42
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
34
|
none: false
|
44
|
-
requirements:
|
45
|
-
- -
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
|
48
|
-
|
49
|
-
- 0
|
50
|
-
version: "0"
|
51
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
40
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
segments:
|
58
|
-
- 0
|
59
|
-
version: "0"
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
60
45
|
requirements: []
|
61
|
-
|
62
46
|
rubyforge_project:
|
63
|
-
rubygems_version: 1.
|
47
|
+
rubygems_version: 1.8.9
|
64
48
|
signing_key:
|
65
49
|
specification_version: 3
|
66
50
|
summary: Intelligently strips leading whitespace from a multiline string
|
67
51
|
test_files: []
|
68
|
-
|