wstrip 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/wstrip.rb +79 -0
  2. metadata +61 -0
data/lib/wstrip.rb ADDED
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+ require 'terrun'
3
+
4
+ class WStrip < TerminalRunner
5
+ name "WStrip"
6
+
7
+ param "input", "The file or directory of files to strip whitespace from."
8
+
9
+ option "--help", 0, "", "Shows this help file."
10
+ option "--recursive", 0, "", "Recursively get files from directories."
11
+ option "--extension", 1, "<extension_list>", "Only apply to files with the specified extensions."
12
+
13
+ option_alias "--recursive", "-r"
14
+ option_alias "--extension", "-e"
15
+
16
+ help <<EOS
17
+ Removes all extra whitespace from the end of lines.
18
+
19
+ The format used for the <extension_list> is as follows:
20
+ rb : Single extension
21
+ "rb|js" : Multiple extensions (note, there are no spaces).
22
+ EOS
23
+
24
+ def self.run
25
+ if @@options.include? "--help"
26
+ show_usage
27
+ exit
28
+ end
29
+
30
+ ext = @@options.include?("--extension") ? @@options["--extension"][0].split("|") : nil
31
+
32
+ ws = WStrip.new(@@params["input"], @@options.include?("--recursive"), ext)
33
+ end
34
+
35
+ def initialize(input, r, ext)
36
+ unless File.exists? input
37
+ puts "Could not find input file."
38
+ exit
39
+ end
40
+
41
+ strip_file(input, r, ext)
42
+ end
43
+
44
+ def strip_file(file, r, ext)
45
+ if File.directory? file
46
+ Dir.entries(file).select do |f|
47
+ if (f != "." && f != "..")
48
+ file_full = "#{file}/#{f}"
49
+ if File.directory?(file_full)
50
+ if r
51
+ strip_file(file_full, r, ext)
52
+ end
53
+ else
54
+ strip_file(file_full, r, ext)
55
+ end
56
+ end
57
+ end
58
+ else
59
+
60
+ if ext.nil? || ext.include?(File.extname(file)[1..-1])
61
+ puts "Fixing #{file}"
62
+ lines = []
63
+ File.open(file, 'r').each_line do |line|
64
+ lines << line.rstrip
65
+ end
66
+ File.open(file, 'w') do |f|
67
+ lines.each do |line|
68
+ f.puts line
69
+ end
70
+ end
71
+ end
72
+
73
+ end
74
+ end
75
+ end
76
+
77
+ if __FILE__ == $0
78
+ x = WStrip.start(ARGV)
79
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wstrip
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Caleb Simpson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: terrun
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: A command line based application to remove trailing whitespace en-masse
31
+ email: the.foner@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/wstrip.rb
37
+ homepage: http://www.pac.lifemakesuslaugh.com
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.8.24
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: Strips whitespace
61
+ test_files: []