whiteout 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/bin/whiteout +4 -0
- data/lib/whiteout/version.rb +3 -0
- data/lib/whiteout.rb +49 -0
- data/spec/whiteout_spec.rb +27 -0
- data/whiteout.gemspec +25 -0
- metadata +70 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
Whiteout
|
2
|
+
========
|
3
|
+
|
4
|
+
Remove annoying trailing whitespace from files.
|
5
|
+
|
6
|
+
**Warning:** this is alpha-quality code written with the assistance of
|
7
|
+
several glasses of gin. It's entirely possibly that it may eat your
|
8
|
+
files, your children, or your future, and I disclaim responsibility
|
9
|
+
for any of that.
|
10
|
+
|
11
|
+
Installation
|
12
|
+
------------
|
13
|
+
|
14
|
+
RubyGems:
|
15
|
+
|
16
|
+
```bash
|
17
|
+
$ gem install whiteout
|
18
|
+
$ whiteout -h
|
19
|
+
```
|
20
|
+
|
21
|
+
Use
|
22
|
+
---
|
23
|
+
|
24
|
+
```bash
|
25
|
+
$ echo -e "foo \nbar" | whiteout
|
26
|
+
foo
|
27
|
+
bar
|
28
|
+
$ whiteout file1.rb file2.rb # modified in place
|
29
|
+
```
|
30
|
+
|
31
|
+
Issues
|
32
|
+
------
|
33
|
+
|
34
|
+
<http://github.com/camdez/whiteout/issues>
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/whiteout
ADDED
data/lib/whiteout.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require "whiteout/version"
|
2
|
+
require "optparse"
|
3
|
+
|
4
|
+
# TODO handle directories more appropriately
|
5
|
+
# TODO add man page
|
6
|
+
|
7
|
+
module Whiteout
|
8
|
+
def self.execute(*args)
|
9
|
+
opts = OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: whiteout file1 [...]"
|
11
|
+
|
12
|
+
opts.on('-h', '--help', 'Display this screen' ) do
|
13
|
+
puts opts
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
begin
|
19
|
+
opts.parse!
|
20
|
+
|
21
|
+
if !$stdin.tty? || args[0] == '-'
|
22
|
+
puts self.clean($stdin.read)
|
23
|
+
else
|
24
|
+
if args.empty?
|
25
|
+
puts opts
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
|
29
|
+
args.each do |file|
|
30
|
+
abort "Can't find #{file}" unless File.exists?(file)
|
31
|
+
|
32
|
+
contents = File.read(file)
|
33
|
+
|
34
|
+
# TODO consider writing to a temporary file and moving into place
|
35
|
+
File.open(file, 'w') do |f|
|
36
|
+
f.write(self.clean(contents))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
rescue OptionParser::InvalidOption => e
|
41
|
+
warn e
|
42
|
+
puts opts
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.clean(str)
|
47
|
+
str.gsub(/[ \t]+$/, '')
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "whiteout"
|
2
|
+
|
3
|
+
describe Whiteout do
|
4
|
+
it "cleans trailing spaces" do
|
5
|
+
Whiteout.clean("foo \n").should eql("foo\n")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "cleans trailing tabs" do
|
9
|
+
Whiteout.clean("bar\t\t\n").should eql("bar\n")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "leaves non-trailing whitespace intact" do
|
13
|
+
baz = "\t\tbaz baz\n"
|
14
|
+
Whiteout.clean(baz).should eql(baz)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "leaves consecutive newlines intact" do
|
18
|
+
baz = "foo\n\nbar\b"
|
19
|
+
Whiteout.clean(baz).should eql(baz)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can handle a more complex case" do
|
23
|
+
input = "int foo() \t\n{\n // Returns 42 \n\treturn 42;\n} \n"
|
24
|
+
output = "int foo()\n{\n // Returns 42\n\treturn 42;\n}\n"
|
25
|
+
Whiteout.clean(input).should eql(output)
|
26
|
+
end
|
27
|
+
end
|
data/whiteout.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "whiteout/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "whiteout"
|
7
|
+
s.version = Whiteout::VERSION
|
8
|
+
s.authors = ["Cameron Desautels"]
|
9
|
+
s.email = ["camdez@gmail.com"]
|
10
|
+
s.homepage = "http://github.com/camdez/#{s.name}"
|
11
|
+
s.summary = %q{Remove trailing whitespace from files.}
|
12
|
+
s.description = <<desc
|
13
|
+
Removes trailing whitespace from standard input or from named files.
|
14
|
+
desc
|
15
|
+
|
16
|
+
s.rubyforge_project = s.name
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
# s.add_runtime_dependency "rest-client"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: whiteout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Cameron Desautels
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-13 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70298507611100 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70298507611100
|
25
|
+
description: ! ' Removes trailing whitespace from standard input or from named files.
|
26
|
+
|
27
|
+
'
|
28
|
+
email:
|
29
|
+
- camdez@gmail.com
|
30
|
+
executables:
|
31
|
+
- whiteout
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- Gemfile
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- bin/whiteout
|
40
|
+
- lib/whiteout.rb
|
41
|
+
- lib/whiteout/version.rb
|
42
|
+
- spec/whiteout_spec.rb
|
43
|
+
- whiteout.gemspec
|
44
|
+
homepage: http://github.com/camdez/whiteout
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project: whiteout
|
64
|
+
rubygems_version: 1.8.6
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Remove trailing whitespace from files.
|
68
|
+
test_files:
|
69
|
+
- spec/whiteout_spec.rb
|
70
|
+
has_rdoc:
|