tabs2spaces 0.0.6 → 0.0.7

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/README.md CHANGED
@@ -30,13 +30,25 @@ Parameters
30
30
  tabs2paces -n NUMBER -p "PATTERN" -i
31
31
 
32
32
  NUMBER: number of spaces to replace the tab by default is 2 (OPTIONAL)
33
+
33
34
  PATTERN: Pattern to determine the files by default is "*.rb", use "*.js" (OPTIONAL)
35
+
34
36
  INVERSED: -i parameter set the script to convert spaces into tabs using NUMBER y PATTERN
35
37
 
36
38
  Sintaxis
37
39
 
38
40
  tabs2paces [options] DIRECTORY
39
41
 
42
+ ### switch between indentation schemes
43
+
44
+ if you want to convert all the files in a folder from indentation scheme.
45
+
46
+ Example: If yours files are using 2 spaces indentation and you want to switch to 4 spaces indentation
47
+
48
+ tabs2spaces -n 2 --convert 4
49
+
50
+ That will convert your 2 spaces indentation in 4 spaces indentation
51
+
40
52
  ## Contributing
41
53
 
42
54
  1. Fork it
data/Rakefile CHANGED
@@ -3,8 +3,8 @@ require "bundler/gem_tasks"
3
3
  desc 'Tags version, pushes to remote, and pushes gem'
4
4
  task :release => :build do
5
5
  sh "git tag v#{Tabs2spaces::VERSION}"
6
- sh "git push github master"
7
- sh "git push github v#{Tabs2spaces::VERSION}"
8
- sh "gem push mercadopago-api-#{Tabs2spaces::VERSION}.gem"
6
+ sh "git push origin master"
7
+ sh "git push origin v#{Tabs2spaces::VERSION}"
8
+ sh "gem push tabs2spaces-#{Tabs2spaces::VERSION}.gem"
9
9
  end
10
10
 
data/bin/tabs2spaces CHANGED
@@ -11,6 +11,8 @@ options = {
11
11
  }
12
12
  OptionParser.new do |opts|
13
13
  opts.banner = "Usage: tabs2spaces.rb [options] DIRECTORY"
14
+ opts.separator ""
15
+ opts.separator "Optional configuration"
14
16
 
15
17
  opts.on("-n", "--number [NUMBER]", Integer, "Number of spaces to remplace a tab (default: 2)") do |number|
16
18
  options[:number] = number
@@ -23,6 +25,26 @@ OptionParser.new do |opts|
23
25
  opts.on("-i", "--[no-]inversed", "Do the inverse process, convert spaces into tabs") do |inverse|
24
26
  options[:inversed] = inverse
25
27
  end
28
+
29
+ opts.separator ""
30
+ opts.separator "Options to convert between to spaces indentation schemes"
31
+
32
+ opts.on("--convert [NUMBER]", Integer, "Convert indentation scheme from -n to --convert") do |convertion|
33
+ options[:convertion] = convertion
34
+ end
35
+
36
+ opts.separator ""
37
+ opts.separator "Common Options"
38
+
39
+ opts.on_tail("-h", "--help", "Show help") do
40
+ puts opts
41
+ exit
42
+ end
43
+
44
+ opts.on_tail("--version", "Show version") do
45
+ puts "Tabs2spaces" + Tabs2spaces::VERSION
46
+ exit
47
+ end
26
48
  end.parse!
27
49
 
28
50
  tabs2spaces = Tabs2spaces::Converter.new(ARGV[0], options)
data/lib/tabs2spaces.rb CHANGED
@@ -9,12 +9,13 @@ module Tabs2spaces
9
9
  end
10
10
 
11
11
  def file_expand(file)
12
+ number = @options[:number]
12
13
  unless @options[:inversed]
13
14
  puts "Expanding tabs on: " + file
14
- return `expand -i -t #{@options[:number]} #{file}`
15
+ return `expand -i -t #{number} #{file}`
15
16
  else
16
17
  puts "Unexpanding spaces on: " + file
17
- return `unexpand --first-only -t #{@options[:number]} #{file}`
18
+ return `unexpand --first-only -t #{number} #{file}`
18
19
  end
19
20
  end
20
21
 
@@ -30,17 +31,40 @@ module Tabs2spaces
30
31
  end
31
32
  end
32
33
 
33
- def convert
34
+ def file_expand_and_write(file)
35
+ file_write file, file_expand(file)
36
+ end
37
+
38
+ def folder_expand_and_write(folder)
39
+ files = File.join(@folder, '**', @options[:pattern])
40
+ Dir.glob(files).each do |file|
41
+ file_expand_and_write file
42
+ end
43
+ end
44
+
45
+ def simple_convert
34
46
  unless File.directory?(@folder)
35
- new_file = file_expand @folder
36
- file_write @folder, new_file
47
+ file_expand_and_write @folder
37
48
  else
38
- folder = File.join(@folder, '**', @options[:pattern])
39
- Dir.glob(folder).each do |file|
40
- new_file = file_expand file
41
- file_write file, new_file
42
- end
49
+ folder_expand_and_write(@folder)
43
50
  end
44
51
  end
52
+
53
+ def convert_between
54
+ @options[:inversed] = true
55
+ simple_convert
56
+ @options[:inversed] = false
57
+ @options[:number] = @options[:convertion]
58
+ simple_convert
59
+ end
60
+
61
+ def convert
62
+ if @options[:convertion].nil?
63
+ simple_convert
64
+ else
65
+ convert_between
66
+ end
67
+ end
68
+
45
69
  end
46
70
  end
@@ -1,3 +1,4 @@
1
1
  module Tabs2spaces
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
4
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabs2spaces
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-15 00:00:00.000000000 Z
12
+ date: 2013-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler