unindent 0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright © 2009 Martin Aumont (mynyml)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,11 @@
1
+ .gitignore
2
+ LICENSE
3
+ Manifest
4
+ README.md
5
+ Rakefile
6
+ examples.rb
7
+ lib/unindent.rb
8
+ specs.watchr
9
+ test/test_helper.rb
10
+ test/test_unindent.rb
11
+ unindent.gemspec
@@ -0,0 +1,27 @@
1
+ ### Summary
2
+
3
+ Simple Ruby method, `String#unindent`, to unindent strings. Useful for
4
+ multi-line strings embeded in already indented code.
5
+
6
+ ### Examples
7
+
8
+ class Profile
9
+ def default_text
10
+ <<-STR
11
+ Anonymous Coward
12
+ - Community Guest
13
+ STR
14
+ end
15
+ end
16
+
17
+ puts Profile.new.default_text
18
+ # Anonymous Coward
19
+ # - Community Guest
20
+
21
+ puts Profile.new.default_text.unindent
22
+ #Anonymous Coward
23
+ # - Community Guest
24
+
25
+ ### Install
26
+
27
+ gem install unindent
@@ -0,0 +1,39 @@
1
+ def gem_opt
2
+ defined?(Gem) ? "-rubygems" : ""
3
+ end
4
+
5
+ # --------------------------------------------------
6
+ # Tests
7
+ # --------------------------------------------------
8
+ task(:default => :'test:all')
9
+
10
+ namespace(:test) do
11
+ desc "Run tests"
12
+ task(:all) do
13
+ exit system("ruby #{gem_opt} -I.:lib test/test_unindent.rb")
14
+ end
15
+
16
+ desc "Run tests on multiple ruby versions (requires rvm)"
17
+ task(:portability) do
18
+ versions = %w( 1.8.6 1.8.7 1.9 1.9.2 )
19
+ versions.each do |version|
20
+ system <<-BASH
21
+ bash -c 'source ~/.rvm/scripts/rvm;
22
+ rvm use #{version};
23
+ echo "--------- #{version} ----------";
24
+ rake -s test:all'
25
+ BASH
26
+ end
27
+ end
28
+ end
29
+
30
+ # --------------------------------------------------
31
+ # Docs
32
+ # --------------------------------------------------
33
+ desc "Generate YARD Documentation"
34
+ task(:yardoc) do
35
+ require 'yard'
36
+ files = %w( lib/**/*.rb )
37
+ options = %w( -o doc/yard --readme README --files LICENSE )
38
+ YARD::CLI::Yardoc.run *(options + files)
39
+ end
@@ -0,0 +1,20 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname.parent + 'lib/unindent'
3
+
4
+ class Profile
5
+ def default_text
6
+ <<-STR
7
+ Anonymous Coward
8
+ - Community Guest
9
+ STR
10
+ end
11
+ end
12
+
13
+ puts Profile.new.default_text
14
+ # Anonymous Coward
15
+ # - Community Guest
16
+
17
+ puts Profile.new.default_text.unindent
18
+ #Anonymous Coward
19
+ # - Community Guest
20
+
@@ -0,0 +1,9 @@
1
+ class String
2
+ def unindent
3
+ indent = self.split("\n").select {|line| !line.strip.empty? }.map {|line| line.index(/[^\s]/) }.compact.min
4
+ self.gsub(/^[[:blank:]]{#{indent}}/, '')
5
+ end
6
+ def unindent!
7
+ self.replace(self.unindent)
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ # Run me with:
2
+ # $ watchr specs.watchr
3
+
4
+ # --------------------------------------------------
5
+ # Watchr Rules
6
+ # --------------------------------------------------
7
+ watch( '^(lib|test)/.*\.rb' ) { rake }
8
+
9
+ # --------------------------------------------------
10
+ # Signal Handling
11
+ # --------------------------------------------------
12
+ Signal.trap('QUIT') { rake } # Ctrl-\
13
+ Signal.trap('INT' ) { abort("\n") } # Ctrl-C
14
+
15
+ # --------------------------------------------------
16
+ # Helpers
17
+ # --------------------------------------------------
18
+ def rake(task='')
19
+ system "rake -s #{task}"
20
+ end
@@ -0,0 +1,13 @@
1
+ require 'nanotest'
2
+ begin
3
+ require 'ruby-debug'
4
+ require 'redgreen' # gem: mynyml-redgreen
5
+ require 'nanotest/focus' # gem: nanotest_extensions
6
+ require 'nanotest/stats' # gem: nanotest_extensions
7
+ rescue LoadError, RuntimeError
8
+ # pass
9
+ end
10
+
11
+ require 'unindent'
12
+
13
+ include Nanotest
@@ -0,0 +1,20 @@
1
+ require 'test/test_helper'
2
+
3
+ ## simple indentation
4
+
5
+ assert { "\s\sabc" .unindent == "abc" } # removes space indentation
6
+ assert { "\tabc" .unindent == "abc" } # removes tab indentation
7
+ assert { "\t\s\sabc".unindent == "abc" } # removes space/tab indentation
8
+
9
+ ## multi-line indentation
10
+
11
+ assert { "\tabc\n\tabc" .unindent == "abc\nabc" } # removes space/tab indentation
12
+ assert { "\tabc\n\t\tabc" .unindent == "abc\n\tabc" } # keeps relative indentation
13
+ assert { "\n\tabc\n\n\t\tabc\n".unindent == "\nabc\n\n\tabc\n" } # ignores blank lines for indent calculation
14
+
15
+ ## unindent!
16
+
17
+ # test: modifies string in place
18
+ source = "\s\sabc"
19
+ source.unindent!
20
+ assert { source == "abc" }
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "unindent"
3
+ s.version = "0.9"
4
+ s.summary = "Ruby method to unindent strings."
5
+ s.description = "Ruby method to unindent strings. Useful for multiline strings embeded in already indented code."
6
+ s.author = "mynyml"
7
+ s.email = "mynyml@gmail.com"
8
+ s.homepage = "http://github.com/mynyml/unindent"
9
+ s.rubyforge_project = "unindent"
10
+ s.has_rdoc = false
11
+ s.require_path = "lib"
12
+ s.files = File.read("Manifest").strip.split("\n")
13
+
14
+ s.add_development_dependency 'nanotest'
15
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unindent
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.9"
5
+ platform: ruby
6
+ authors:
7
+ - mynyml
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-08 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nanotest
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Ruby method to unindent strings. Useful for multiline strings embeded in already indented code.
26
+ email: mynyml@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - .gitignore
35
+ - LICENSE
36
+ - Manifest
37
+ - README.md
38
+ - Rakefile
39
+ - examples.rb
40
+ - lib/unindent.rb
41
+ - specs.watchr
42
+ - test/test_helper.rb
43
+ - test/test_unindent.rb
44
+ - unindent.gemspec
45
+ has_rdoc: false
46
+ homepage: http://github.com/mynyml/unindent
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: unindent
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Ruby method to unindent strings.
73
+ test_files: []
74
+