spacerace 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +23 -0
- data/bin/spacerace +62 -0
- data/lib/spacerace.rb +47 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a3a490453ae16605c001b680e3fde7670a80bfd6
|
4
|
+
data.tar.gz: 2c70b537dd5aa307a615ca1f3db6ad1b4bdbe64b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b99ca20428f12df459adbaa6f62df968440d13970ed7b2a2736f8c3d7d10b7b026169b336287cc45e4d6c4c4d030a83c6781d5b5c5c428d7fa6b3d833f26f6e5
|
7
|
+
data.tar.gz: 9f645bc9a1ebda8cee1e358d41951fed60b4dd24859118735fd41ef604d6a66ed5e991c8cc810f1f1cb608212c32dbe25de2517a97a073a7dc0a806690c79d3a
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Alex Clink
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#SpaceRace
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/spacerace.svg)](https://badge.fury.io/rb/spacerace)
|
4
|
+
|
5
|
+
Replace spaces in source files
|
6
|
+
|
7
|
+
##Examples
|
8
|
+
|
9
|
+
####To replace tabs with two spaces:
|
10
|
+
|
11
|
+
```bash
|
12
|
+
spacerace filename -s $'\t' -r ' '
|
13
|
+
```
|
14
|
+
|
15
|
+
In bash you specify a literal tab with: `$'\t'`
|
16
|
+
|
17
|
+
####To replace two spaces with 1 tab:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
spacerace filename -r $'\t' -s ' ' -d 2
|
21
|
+
```
|
22
|
+
|
23
|
+
The `-d` option reduces the existing space.
|
data/bin/spacerace
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
# require_relative '../lib/spacerace.rb'
|
6
|
+
|
7
|
+
TOOL_NAME = "spacerace"
|
8
|
+
HOME_PAGE = "https://github.com/sleepinginsomniac/spacerace"
|
9
|
+
USAGE = "Usage: #{TOOL_NAME} (FILES|GLOBS)... [options]"
|
10
|
+
|
11
|
+
options = Hash.new
|
12
|
+
OptionParser.new do |opts|
|
13
|
+
opts.banner = <<-BANNER
|
14
|
+
#{TOOL_NAME} version #{SpaceRace::VERSION}
|
15
|
+
#{USAGE}
|
16
|
+
|
17
|
+
BANNER
|
18
|
+
|
19
|
+
opts.on "-s SPACE", "--space SPACE", "Space character" do |o|
|
20
|
+
options[:space] = o
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on "-r REPLACEMENT", "--replacement REPLACEMENT", "Replacement character" do |o|
|
24
|
+
options[:replacement] = o
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on "-d AMOUNT", "--reduce AMOUNT", "Divide number of 'space characters' by this (useful for converting spaces to tabs)" do |o|
|
28
|
+
options[:reduce] = o
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on "--no-backup", "Do not create a backup of the original" do
|
32
|
+
options[:nobackup] = true
|
33
|
+
end
|
34
|
+
|
35
|
+
# ==================
|
36
|
+
# = Common Options =
|
37
|
+
# ==================
|
38
|
+
|
39
|
+
opts.separator ""
|
40
|
+
opts.separator "Common options:"
|
41
|
+
|
42
|
+
opts.on "-v", "--version", "Print version" do
|
43
|
+
puts "#{TOOL_NAME} - version #{SpaceRace::VERSION}", HOME_PAGE
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on "-h", "--help", "Prints this help" do
|
48
|
+
puts opts
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
|
52
|
+
end.parse!
|
53
|
+
|
54
|
+
if ARGV.empty?
|
55
|
+
puts USAGE
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
|
59
|
+
puts ARGV
|
60
|
+
|
61
|
+
replacer = SpaceRace.new(options)
|
62
|
+
ARGV.each { |path| replacer.respace_file(path) }
|
data/lib/spacerace.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
class SpaceRace
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
VERSION = '0.0.3'
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
@space = options[:space] || '\t'
|
8
|
+
@replacement = options[:replacement] || " "
|
9
|
+
@reduce = options[:reduce] || 1
|
10
|
+
@no_backup = options[:nobackup] || false
|
11
|
+
|
12
|
+
# puts "Space: `#{@space}`", "Replacement: `#{@replacement}`", "Reduce: #{@reduce}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def respace_line(line)
|
16
|
+
regex = /^#{@space}*/
|
17
|
+
white_space = line.scan(regex).first
|
18
|
+
if (white_space)
|
19
|
+
amount = white_space.length
|
20
|
+
line.gsub(regex, padd((amount.to_i/@reduce.to_i).to_i, @replacement))
|
21
|
+
else
|
22
|
+
line
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def respace_file(file)
|
27
|
+
original = "#{file}.original"
|
28
|
+
FileUtils.copy file, original
|
29
|
+
|
30
|
+
out_file = File.open file, "w"
|
31
|
+
|
32
|
+
File.foreach original do |line|
|
33
|
+
out_file.write respace_line(line)
|
34
|
+
# puts respace_line(line, @space, @replacement, @reduce)
|
35
|
+
end
|
36
|
+
|
37
|
+
out_file.close
|
38
|
+
FileUtils.rm(original) if @no_backup
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def padd(amount, string)
|
44
|
+
padded = ""; amount.times { padded << string }; padded
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spacerace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Clink
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Replace indentation in your source code. Meant to help deal with differences
|
14
|
+
in coding styles and getting back to consistent use of indentation.
|
15
|
+
email: code@alexclink.com
|
16
|
+
executables:
|
17
|
+
- spacerace
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- LICENSE
|
22
|
+
- README.md
|
23
|
+
- bin/spacerace
|
24
|
+
- lib/spacerace.rb
|
25
|
+
homepage: https://github.com/sleepinginsomniac/spacerace
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.5.1
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Replace indentation in your source code
|
49
|
+
test_files: []
|