heredoc_unindent 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/History.rdoc +7 -0
- data/Manifest.txt +0 -1
- data/README.rdoc +5 -0
- data/Rakefile +2 -2
- data/lib/heredoc_unindent.rb +38 -16
- data/test/test_heredoc_unindent.rb +34 -1
- metadata +59 -72
- data.tar.gz.sig +0 -2
- data/Wishlist.rdoc +0 -13
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 41c021e05c7d7bb60f8054d3e6a11737018c0023
|
4
|
+
data.tar.gz: 3af02278e9f69a68cbee27098483010f5a345da9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 780ebd1db7ee9e65ccfb58442492e66192806c112f711bda413e4ca86a7364d65aa92e6a2ec439e696562d4986e058ede65baecab3df5302addbbea98debfdb4
|
7
|
+
data.tar.gz: 03537bbacb8caebeac8c2495d6158485313284e18dd330b7e31f0eaae77eeb8ad3e5ef7bd298b9c76502f67b666035a97ce7b0e310f567034d1a3b87854abf8d
|
data/.gemtest
ADDED
File without changes
|
data/History.rdoc
CHANGED
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
@@ -37,6 +37,11 @@ will probably be an issue and hence this gem.
|
|
37
37
|
s.unindent! #=> nil
|
38
38
|
s #=> "foo"
|
39
39
|
|
40
|
+
u = " 1\n \n\n"
|
41
|
+
u.unindent == u #=> true
|
42
|
+
u.unindent(ignore_empty: true) #=> " 1\n\n\n"
|
43
|
+
u.unindent(ignore_blank: true) #=> "1\n\n\n"
|
44
|
+
|
40
45
|
== FEATURES:
|
41
46
|
|
42
47
|
* Tested on all major Ruby interpreters (100% coverage, 0% failure):
|
data/Rakefile
CHANGED
@@ -6,11 +6,11 @@ require 'hoe'
|
|
6
6
|
Hoe.spec 'heredoc_unindent' do
|
7
7
|
developer('Adriano Mitre', 'adriano.mitre@gmail.com')
|
8
8
|
|
9
|
-
self.version = '1.
|
9
|
+
self.version = '1.2.0'
|
10
10
|
|
11
11
|
self.readme_file = 'README.rdoc'
|
12
12
|
self.history_file = 'History.rdoc'
|
13
|
-
self.extra_rdoc_files += ['README.rdoc', 'History.rdoc'
|
13
|
+
self.extra_rdoc_files += ['README.rdoc', 'History.rdoc']
|
14
14
|
|
15
15
|
# self.rubyforge_name = 'heredoc_unindentx' # if different than 'heredoc_unindent'
|
16
16
|
end
|
data/lib/heredoc_unindent.rb
CHANGED
@@ -8,6 +8,11 @@ module CoreExt
|
|
8
8
|
|
9
9
|
private
|
10
10
|
|
11
|
+
# Good for compatibility with older Ruby versions, bad for YARD/RDoc.
|
12
|
+
DefaultUnindentBaseNewArgs = {
|
13
|
+
:ignore_empty => false,
|
14
|
+
:ignore_blank => false
|
15
|
+
}
|
11
16
|
# Actual implementations of the unindentation mechanism,
|
12
17
|
# both for in and out-of-place processing.
|
13
18
|
#
|
@@ -18,25 +23,39 @@ module CoreExt
|
|
18
23
|
#
|
19
24
|
# @param [Boolean] warn_first_not_min
|
20
25
|
# @param [Boolean] in_place
|
26
|
+
# @param [Hash] args Optional flags: ignore_empty and ignore_blank (the
|
27
|
+
# latter imply the former).
|
21
28
|
# @return [String, nil]
|
22
29
|
#
|
23
|
-
|
24
30
|
# about 50% faster in jruby, 56% in ruby-1.9.2, 62% in rbx-1.2.0 (new vs old)
|
25
31
|
#
|
26
|
-
def unindent_base_new(in_place, warn_first_not_min)
|
32
|
+
def unindent_base_new(in_place, warn_first_not_min, args)
|
33
|
+
args = DefaultUnindentBaseNewArgs.merge(args)
|
27
34
|
m_first = nil
|
28
35
|
m_min = nil
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
if args[:ignore_empty] || args[:ignore_blank]
|
37
|
+
rl = self.lines # relevant lines
|
38
|
+
if args[:ignore_blank]
|
39
|
+
rl.reject! {|l| l[/^[ \t]*$/] }
|
40
|
+
elsif
|
41
|
+
rl.reject! {|l| l.chomp.empty? }
|
42
|
+
end
|
43
|
+
margins = rl.map {|l| l.gsub(/(\s*)\S?.*\n/,'\1').size }
|
44
|
+
m_first = margins.first
|
45
|
+
m_min = margins.min
|
46
|
+
else
|
47
|
+
self.scan(/^[ \t]*/) do |m|
|
48
|
+
ms = m.size
|
49
|
+
m_first ||= ms
|
50
|
+
m_min = ms if !m_min || ms < m_min
|
51
|
+
# break if ms == 0 ## only worth if the probability of marginless line above certain threshold
|
52
|
+
end
|
34
53
|
end
|
35
54
|
if m_first != m_min && warn_first_not_min
|
36
55
|
puts "warning: margin of the first line differs from minimum margin"
|
37
56
|
end
|
38
57
|
return in_place ? nil : self.dup unless m_min > 0
|
39
|
-
re = Regexp.new('
|
58
|
+
re = Regexp.new('^[ \t]{,' + m_min.to_s + '}' )
|
40
59
|
in_place ? gsub!(re, '') : gsub(re, '')
|
41
60
|
end
|
42
61
|
|
@@ -53,10 +72,12 @@ module CoreExt
|
|
53
72
|
in_place ? gsub!(re, '') : gsub(re, '')
|
54
73
|
end
|
55
74
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
75
|
+
def unindent_base(in_place, warn_first_not_min, args)
|
76
|
+
if !args.empty? || RUBY_VERSION >= '1.9' || defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /jruby|rubinius/i
|
77
|
+
unindent_base_new(in_place, warn_first_not_min, args)
|
78
|
+
else
|
79
|
+
unindent_base_old(in_place, warn_first_not_min)
|
80
|
+
end
|
60
81
|
end
|
61
82
|
|
62
83
|
public
|
@@ -87,8 +108,9 @@ module CoreExt
|
|
87
108
|
# @param [Boolean] warn_first_not_min toggle warning if the margin of the first line differs from minimum margin
|
88
109
|
# @return [::String] unindented string
|
89
110
|
#
|
90
|
-
def heredoc_unindent(warn_first_not_min=true)
|
91
|
-
|
111
|
+
def heredoc_unindent(warn_first_not_min=true, args={})
|
112
|
+
args, warn_first_not_min = warn_first_not_min, true if warn_first_not_min.is_a? Hash
|
113
|
+
unindent_base(false, warn_first_not_min, args)
|
92
114
|
end
|
93
115
|
alias unindent heredoc_unindent
|
94
116
|
|
@@ -115,8 +137,8 @@ module CoreExt
|
|
115
137
|
# @param [Boolean] warn_first_dif_min toggle warning if the margin of the first line differs from minimum margin
|
116
138
|
# @return [::String, NilClass] unindented self, or nil if no changes were made
|
117
139
|
#
|
118
|
-
def heredoc_unindent!(warn_first_not_min=true)
|
119
|
-
unindent_base(true, warn_first_not_min)
|
140
|
+
def heredoc_unindent!(warn_first_not_min=true, args={})
|
141
|
+
unindent_base(true, warn_first_not_min, args)
|
120
142
|
end
|
121
143
|
alias unindent! heredoc_unindent!
|
122
144
|
end
|
@@ -64,6 +64,39 @@ EOS
|
|
64
64
|
return ugly, pretty
|
65
65
|
end
|
66
66
|
|
67
|
+
# Test new flags.
|
68
|
+
#
|
69
|
+
def test_ignore_empty_and_ignore_blank
|
70
|
+
ugly = <<-EOS
|
71
|
+
foo
|
72
|
+
|
73
|
+
bar
|
74
|
+
|
75
|
+
|
76
|
+
baz
|
77
|
+
EOS
|
78
|
+
pretty_e1b0 = <<EOS
|
79
|
+
foo
|
80
|
+
|
81
|
+
bar
|
82
|
+
|
83
|
+
|
84
|
+
baz
|
85
|
+
EOS
|
86
|
+
pretty_e0b1 = ugly.clone
|
87
|
+
pretty_e1b1 = <<EOS
|
88
|
+
foo
|
89
|
+
|
90
|
+
bar
|
91
|
+
|
92
|
+
|
93
|
+
baz
|
94
|
+
EOS
|
95
|
+
assert_equal pretty_e1b0, ugly.unindent(false, ignore_empty: true, ignore_blank: false)
|
96
|
+
assert_equal pretty_e0b1, ugly.unindent(false, ignore_empty: false, ignore_blank: false)
|
97
|
+
assert_equal pretty_e1b1, ugly.unindent(false, ignore_empty: true, ignore_blank: true)
|
98
|
+
end
|
99
|
+
|
67
100
|
def prep_mult
|
68
101
|
ugly = <<-BEGIN + " <--- middle --->\n" + <<-END
|
69
102
|
This is the beginning:
|
@@ -77,7 +110,7 @@ This is the beginning:
|
|
77
110
|
EOS
|
78
111
|
return ugly, pretty
|
79
112
|
end
|
80
|
-
|
113
|
+
|
81
114
|
def test_unindent
|
82
115
|
1.upto(4) do |n|
|
83
116
|
m = method "prep_sing#{n}"
|
metadata
CHANGED
@@ -1,107 +1,94 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: heredoc_unindent
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 1.1.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Adriano Mitre
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
|
-
cert_chain:
|
12
|
-
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
A0jJ6rCWowdBhfV2Lc3GvqGWKpFkZiujRWEjf3DuyRJALUjRFt3og5S1LFTC/E8k
|
23
|
-
22l7fNhFtQQWIQ0bvWgr1CVjaC+Mj7Yd/dH1YjFjNSGjeVC70uvwcpa+GAHUTvW+
|
24
|
-
3MJwcABAEx3/k1dVAgMBAAGjOTA3MAkGA1UdEwQCMAAwHQYDVR0OBBYEFCe5ttae
|
25
|
-
SfcWo9+mP1ZzFzPfo2N1MAsGA1UdDwQEAwIEsDANBgkqhkiG9w0BAQUFAAOCAQEA
|
26
|
-
NWDEWS5ZRu2tDbMmAHsNqjxQmdbICp0GiUa4LT5ihdRpaObHp9r+DbcHXmshYiTg
|
27
|
-
rJmflLzpoUvuNYkvgMOXtu7zzLlrm7RsY2r0Z/BbHkxSdX0dpg6s0PcROUnUCdbZ
|
28
|
-
CLiXywPX9ZUvOcF35Cz/HZkWo1zSBz5WtUjSodH9L0ASMboQIIWM8aNd80aV+qYC
|
29
|
-
3UBBz1sni91YXPxf7FQxJtIXlNO04DAAHy9J7M22zWpUFRZOJynnDZWsOx3lifKX
|
30
|
-
1PyL4lke+kXB8DF3QA2RqMPmEZp/FgDqYZy1VT1ROlxyatgDgcFBmrsyjnb9hi9N
|
31
|
-
9u8N6mQNneIVRh6Xfdko/Q==
|
32
|
-
-----END CERTIFICATE-----
|
33
|
-
|
34
|
-
date: 2011-02-07 00:00:00 -02:00
|
35
|
-
default_executable:
|
36
|
-
dependencies:
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: hoe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rdoc
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :development
|
39
21
|
prerelease: false
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hoe
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.13'
|
46
34
|
type: :development
|
47
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.13'
|
48
41
|
description: |-
|
49
42
|
This gem removes common margin from indented strings, such as the ones
|
50
43
|
produced by indented heredocs. In other words, it strips out leading whitespace
|
51
44
|
chars at the beggining of each line, but only as much as the line with the
|
52
45
|
smallest margin.
|
53
|
-
|
46
|
+
|
54
47
|
It is acknowledged that many strings defined by heredocs are just code and fact
|
55
48
|
is that most parsers are insensitive to indentation. If, however, the strings
|
56
49
|
are to be used otherwise, be it for printing or testing, the extra indentation
|
57
50
|
will probably be an issue and hence this gem.
|
58
|
-
email:
|
51
|
+
email:
|
59
52
|
- adriano.mitre@gmail.com
|
60
53
|
executables: []
|
61
|
-
|
62
54
|
extensions: []
|
63
|
-
|
64
|
-
|
55
|
+
extra_rdoc_files:
|
56
|
+
- History.rdoc
|
65
57
|
- Manifest.txt
|
66
58
|
- README.rdoc
|
67
|
-
|
68
|
-
-
|
69
|
-
files:
|
59
|
+
files:
|
60
|
+
- ".gemtest"
|
70
61
|
- History.rdoc
|
71
62
|
- Manifest.txt
|
72
63
|
- README.rdoc
|
73
64
|
- Rakefile
|
74
|
-
- Wishlist.rdoc
|
75
65
|
- lib/heredoc_unindent.rb
|
76
66
|
- test/test_heredoc_unindent.rb
|
77
|
-
has_rdoc: true
|
78
67
|
homepage: https://github.com/adrianomitre/heredoc_unindent
|
79
|
-
licenses:
|
80
|
-
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
81
71
|
post_install_message:
|
82
|
-
rdoc_options:
|
83
|
-
- --main
|
72
|
+
rdoc_options:
|
73
|
+
- "--main"
|
84
74
|
- README.rdoc
|
85
|
-
require_paths:
|
75
|
+
require_paths:
|
86
76
|
- lib
|
87
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
-
|
89
|
-
requirements:
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
90
79
|
- - ">="
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version:
|
93
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
-
|
95
|
-
requirements:
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
96
84
|
- - ">="
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version:
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
99
87
|
requirements: []
|
100
|
-
|
101
|
-
|
102
|
-
rubygems_version: 1.5.0
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.4.5
|
103
90
|
signing_key:
|
104
|
-
specification_version:
|
105
|
-
summary: This gem removes common margin from indented strings, such as the ones produced
|
106
|
-
|
107
|
-
|
91
|
+
specification_version: 4
|
92
|
+
summary: This gem removes common margin from indented strings, such as the ones produced
|
93
|
+
by indented heredocs
|
94
|
+
test_files: []
|
data.tar.gz.sig
DELETED
data/Wishlist.rdoc
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
== SUGGESTIONS
|
2
|
-
|
3
|
-
* added a mechanism for "ignoring" blank lines, i.e.,
|
4
|
-
* not include the margin of blank lines in the minimum calculation
|
5
|
-
* let them untouched (i.e., unprocessed)
|
6
|
-
* possible implementation:
|
7
|
-
re = Regexp.new '^\s{' + n.to_s + '}(\S+)$'
|
8
|
-
s.gsub(re,'\1')
|
9
|
-
instead of
|
10
|
-
re = Regexp.new '^\s{' + n.to_s + '}'
|
11
|
-
s.gsub(re, '')
|
12
|
-
* re-benchmark to make sure it does not hurt performance and performance
|
13
|
-
figures in README are still valid
|
metadata.gz.sig
DELETED
Binary file
|