heredoc_unindent 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ p���x[ΙXh��I�3$�ku;#.�^�&�9i{{�uc4�nN����>�S�{�MN����Д� ��I�?�]�"���}���,8�"ȉT}��� ��h��4<�+~���<š��AB�c񀜏1%Kг�CT�#J�E}թ�?}�5.5�N
2
+ >?�B' /Z�5)BP�+k?zP/��h�n��eBS8�����
data/History.rdoc ADDED
@@ -0,0 +1,21 @@
1
+ === 1.0.1 / 2011-01-26
2
+
3
+ * 7 minor enhancements
4
+
5
+ * One test added for 100% code coverage
6
+ * Changed extension of History and Wishlist from _txt_ to _rdoc_ so
7
+ that GitHub parses them accordingly
8
+ * Added History and Wishlist to the RDoc documentation (extra_rdoc_files)
9
+ * Minor additions/editions to README
10
+ * Refactored HeredocUnindent module into CoreExt::String::HeredocUnindent
11
+ * Moved version information from VERSION constant in HeredocUnindent module
12
+ to <tt>self.version = 'x.x.x'</tt> in Rakefile
13
+ * Removed irrelevant Rakefile comments
14
+
15
+
16
+ === 1.0.0 / 2011-01-16
17
+
18
+ * 1 major enhancement
19
+
20
+ * Birthday!
21
+
data/Manifest.txt CHANGED
@@ -1,6 +1,7 @@
1
- History.txt
1
+ History.rdoc
2
2
  Manifest.txt
3
3
  README.rdoc
4
4
  Rakefile
5
+ Wishlist.rdoc
5
6
  lib/heredoc_unindent.rb
6
7
  test/test_heredoc_unindent.rb
data/README.rdoc CHANGED
@@ -8,28 +8,35 @@ Removes common margin from indented strings such as the ones produced by
8
8
  heredocs, i.e., strips out leading whitespace chars at the beggining of
9
9
  each line (but only as much as the line with the smallest margin).
10
10
 
11
+ It is acknowledged that many strings defined in heredocs contain nothing but
12
+ code to be read exclusively by parsers (e.g., Kernel#eval or web browser's),
13
+ which are basically insensitive to extra indentation. Nevertheless, in cases
14
+ when the string is printed or displayed, the unintended indentation is rarely
15
+ innocuous -- and thus the reason for this gem.
16
+
11
17
  == SYNOPSIS:
12
18
 
13
19
  if true
14
20
  puts <<-EOS.unindent
15
- How wonderful it is
21
+ "How wonderful it is
16
22
  to be able
17
- to unindent heredocs
23
+ to unindent heredocs"
18
24
  EOS
19
25
  end
20
26
 
21
27
  produces
22
28
 
23
- How wonderful it is
29
+ "How wonderful it is
24
30
  to be able
25
- to unindent heredocs
31
+ to unindent heredocs"
26
32
 
27
33
  instead of
28
34
 
29
- How wonderful it is
35
+ "How wonderful it is
30
36
  to be able
31
- to unindent heredocs
32
-
37
+ to unindent heredocs"
38
+
39
+ which would result without #unindent.
33
40
 
34
41
  == REQUIREMENTS:
35
42
 
data/Rakefile CHANGED
@@ -3,25 +3,14 @@
3
3
  require 'rubygems'
4
4
  require 'hoe'
5
5
 
6
- # Hoe.plugin :compiler
7
- # Hoe.plugin :cucumberfeatures
8
- # Hoe.plugin :gem_prelude_sucks
9
- # Hoe.plugin :inline
10
- # Hoe.plugin :manifest
11
- # Hoe.plugin :newgem
12
- # Hoe.plugin :racc
13
- # Hoe.plugin :rubyforge
14
- # Hoe.plugin :website
15
-
16
6
  Hoe.spec 'heredoc_unindent' do
17
- # HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then
18
- # you'll never have to touch them again!
19
- # (delete this comment too, of course)
20
-
21
7
  developer('Adriano Mitre', 'adriano.mitre@gmail.com')
22
8
 
9
+ self.version = '1.0.1'
10
+
23
11
  self.readme_file = 'README.rdoc'
24
- self.extra_rdoc_files << 'README.rdoc'
12
+ self.history_file = 'History.rdoc'
13
+ self.extra_rdoc_files += ['README.rdoc', 'History.rdoc', 'Wishlist.rdoc']
25
14
 
26
15
  # self.rubyforge_name = 'heredoc_unindentx' # if different than 'heredoc_unindent'
27
16
  end
@@ -31,4 +20,3 @@ end
31
20
  task :tests => [:test] do
32
21
  # aliasing :test with :tests for RVM ('rvm tests')
33
22
  end
34
-
data/Wishlist.rdoc ADDED
@@ -0,0 +1,10 @@
1
+ == SUGGESTIONS
2
+
3
+ * Benchmark heredoc_unindent against alternatives:
4
+ * outdent
5
+ * unindent
6
+ * the code posted by Rene Saarsoo in his answer in StackOverflow.
7
+ and then
8
+ * if there are significant performance differences, contact the other authors
9
+ and suggest unifying gems, keeping the fastest implementation
10
+ * mention the results in README (table?)
@@ -1,42 +1,41 @@
1
- # This module, which is included in String, define the heredoc unindentation method
2
- # +heredoc_unindent+ and alias it as +unindent+.
3
- #
4
- module HeredocUnindent
1
+ module CoreExt
2
+ module String
3
+ module HeredocUnindent
4
+ #
5
+ # This module, which is included in String, define the heredoc unindentation method
6
+ # +heredoc_unindent+ and alias it as +unindent+.
7
+ ##
8
+
9
+ # Removes common margin from indented strings such as the ones produced by
10
+ # heredocs, i.e., strips out leading whitespace chars at the beggining of
11
+ # each line (but only as much as the line with the smallest margin).
12
+ #
13
+ # Unless the optional argument +warn_first_dif_min+ is set to false or nil, a
14
+ # warning is produced when the margin of the first line differs from the minimum.
15
+ #
16
+ def heredoc_unindent(warn_first_dif_min=true)
17
+ min_margin = self.scan(/^\s*/).map(&:size).min
18
+ if warn_first_dif_min
19
+ first_margin = self[/^\s*/].size
20
+ if first_margin != min_margin
21
+ puts "warning: margin of the first line differs from minimum margin"
22
+ end
23
+ end
24
+ re = Regexp.new('^\s{0,' + min_margin.to_s + '}' ) # omitting the lower limit produces warnings and wrong behavior in ruby-1.8.7-p330 and ree-1.8.7-2010.02
25
+ self.gsub(re, '')
26
+ end
27
+ alias unindent heredoc_unindent
5
28
 
6
- VERSION = '1.0.0'
7
-
8
- # Removes common margin from indented strings such as the ones produced by
9
- # heredocs, i.e., strips out leading whitespace chars at the beggining of
10
- # each line (but only as much as the line with the smallest margin).
11
- #
12
- # Unless the optional argument +warn_first_dif_min+ is set to false or nil, a
13
- # warning is produced when the margin of the first line differs from the minimum.
14
- #
15
- def heredoc_unindent(warn_first_dif_min=true)
16
- min_margin = self.scan(/^\s*/).map(&:size).min
17
- if warn_first_dif_min
18
- first_margin = self[/^\s*/].size
19
- if first_margin != min_margin
20
- puts "warning: margin of the first line differs from minimum margin"
29
+ # Performs HeredocUnindent#heredoc_unindent in place, returning self, or nil if no changes were made
30
+ #
31
+ def heredoc_unindent!(warn_first_dif_min=true)
32
+ orig = self.dup
33
+ self.replace(self.heredoc_unindent(warn_first_dif_min))
34
+ self != orig ? self : nil
21
35
  end
36
+ alias unindent! heredoc_unindent!
22
37
  end
23
- re = Regexp.new('^\s{0,' + min_margin.to_s + '}' ) # omitting the lower limit produces warnings and wrong behavior in ruby-1.8.7-p330 and ree-1.8.7-2010.02
24
- self.gsub(re, '')
25
- end
26
- alias unindent heredoc_unindent
27
-
28
- # Performs HeredocUnindent#heredoc_unindent in place, returning self, or nil if no changes were made
29
- #
30
- def heredoc_unindent!(warn_first_dif_min=true)
31
- orig = self.dup
32
- self.replace(self.heredoc_unindent(warn_first_dif_min))
33
- self != orig ? self : nil
38
+
39
+ ::String.class_eval { include ::CoreExt::String::HeredocUnindent }
34
40
  end
35
- alias unindent! heredoc_unindent!
36
-
37
41
  end
38
-
39
- class String # :nodoc:
40
- include HeredocUnindent
41
- end
42
-
@@ -83,4 +83,16 @@ EOS
83
83
  assert_equal nil, ugly.unindent!(false)
84
84
  end
85
85
 
86
+ def test_warning
87
+ ugly, pretty = prep_sing1
88
+ filename = "/tmp/#{rand(2**64)}"
89
+ File.open(filename, "w") do |f|
90
+ $stdout = f
91
+ ugly.unindent(true)
92
+ $stdout = STDOUT
93
+ end
94
+ assert File.exist?(filename), "file should exist"
95
+ assert_equal File.read(filename).chomp, "warning: margin of the first line differs from minimum margin"
96
+ end
97
+
86
98
  end
metadata CHANGED
@@ -1,21 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heredoc_unindent
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
7
  - 0
9
- - 0
10
- version: 1.0.0
8
+ - 1
9
+ version: 1.0.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Adriano Mitre
14
13
  autorequire:
15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z/HZkWo1zSBz5WtUjSodH9L0ASMboQIIWM8aNd80aV+qYC
33
+ 3UBBz1sni91YXPxf7FQxJtIXlNO04DAAHy9J7M22zWpUFRZOJynnDZWsOx3lifKX
34
+ 1PyL4lke+kXB8DF3QA2RqMPmEZp/FgDqYZy1VT1ROlxyatgDgcFBmrsyjnb9hi9N
35
+ 9u8N6mQNneIVRh6Xfdko/Q==
36
+ -----END CERTIFICATE-----
17
37
 
18
- date: 2011-01-17 00:00:00 -02:00
38
+ date: 2011-01-26 00:00:00 -02:00
19
39
  default_executable:
20
40
  dependencies:
21
41
  - !ruby/object:Gem::Dependency
@@ -26,7 +46,6 @@ dependencies:
26
46
  requirements:
27
47
  - - ">="
28
48
  - !ruby/object:Gem::Version
29
- hash: 47
30
49
  segments:
31
50
  - 2
32
51
  - 8
@@ -38,6 +57,12 @@ description: |-
38
57
  Removes common margin from indented strings such as the ones produced by
39
58
  heredocs, i.e., strips out leading whitespace chars at the beggining of
40
59
  each line (but only as much as the line with the smallest margin).
60
+
61
+ It is acknowledged that many strings defined in heredocs contain nothing but
62
+ code to be read exclusively by parsers (e.g., Kernel#eval or web browser's),
63
+ which are basically insensitive to extra indentation. Nevertheless, in cases
64
+ when the string is printed or displayed, the unintended indentation is rarely
65
+ innocuous -- and thus the reason for this gem.
41
66
  email:
42
67
  - adriano.mitre@gmail.com
43
68
  executables: []
@@ -45,14 +70,16 @@ executables: []
45
70
  extensions: []
46
71
 
47
72
  extra_rdoc_files:
48
- - History.txt
49
73
  - Manifest.txt
50
74
  - README.rdoc
75
+ - History.rdoc
76
+ - Wishlist.rdoc
51
77
  files:
52
- - History.txt
78
+ - History.rdoc
53
79
  - Manifest.txt
54
80
  - README.rdoc
55
81
  - Rakefile
82
+ - Wishlist.rdoc
56
83
  - lib/heredoc_unindent.rb
57
84
  - test/test_heredoc_unindent.rb
58
85
  has_rdoc: true
@@ -70,7 +97,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
97
  requirements:
71
98
  - - ">="
72
99
  - !ruby/object:Gem::Version
73
- hash: 3
74
100
  segments:
75
101
  - 0
76
102
  version: "0"
@@ -79,7 +105,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
105
  requirements:
80
106
  - - ">="
81
107
  - !ruby/object:Gem::Version
82
- hash: 3
83
108
  segments:
84
109
  - 0
85
110
  version: "0"
@@ -89,6 +114,6 @@ rubyforge_project: heredoc_unindent
89
114
  rubygems_version: 1.3.7
90
115
  signing_key:
91
116
  specification_version: 3
92
- summary: Removes common margin from indented strings such as the ones produced by heredocs, i.e., strips out leading whitespace chars at the beggining of each line (but only as much as the line with the smallest margin).
117
+ summary: Removes common margin from indented strings such as the ones produced by heredocs, i.e., strips out leading whitespace chars at the beggining of each line (but only as much as the line with the smallest margin)
93
118
  test_files:
94
119
  - test/test_heredoc_unindent.rb
metadata.gz.sig ADDED
Binary file
data/History.txt DELETED
@@ -1,6 +0,0 @@
1
- === 1.0.0 / 2011-01-16
2
-
3
- * 1 major enhancement
4
-
5
- * Birthday!
6
-