ruby_beautifier 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +30 -0
- data/Rakefile +1 -0
- data/lib/ruby_beautifier.rb +26 -0
- data/lib/ruby_beautifier/regex_definitions.rb +21 -0
- data/lib/ruby_beautifier/version.rb +3 -0
- data/ruby_beautifier.gemspec +20 -0
- data/spec/ruby_beautifier_spec.rb +51 -0
- data/spec/spec_helper.rb +1 -0
- metadata +76 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Pratik Khadloya
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# RubyBeautifier
|
2
|
+
|
3
|
+
This gem is for beautifiying ruby code. It uses tradional regular expression parsing and is only intended to fix very common spacing issues.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ruby_beautifier'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ruby_beautifier
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require 'ruby_beautifier'
|
22
|
+
RubyBeautifier.run
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
1. Fork it
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
30
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'ruby_beautifier/version'
|
2
|
+
require 'ruby_beautifier/regex_definitions'
|
3
|
+
|
4
|
+
module RubyBeautifier
|
5
|
+
def self.files
|
6
|
+
Dir["**/*.rb"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.run
|
10
|
+
files.each do |file|
|
11
|
+
text = File.read(file)
|
12
|
+
|
13
|
+
REGEX.keys.each do |regex|
|
14
|
+
self.send regex, text
|
15
|
+
end
|
16
|
+
|
17
|
+
File.open(file, "w") { |file| file.puts text }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
REGEX.keys.each do |key|
|
22
|
+
define_singleton_method key do |text|
|
23
|
+
text.gsub!(REGEX[key][:search], REGEX[key][:replace])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
REGEX = {
|
2
|
+
missing_space_before_hash_rocket: {
|
3
|
+
search: /(?<![ \<])=>/, # /(?<! )(?<!\<)=>/, /(?<!( |\<))=>/
|
4
|
+
replace: ' =>'
|
5
|
+
},
|
6
|
+
|
7
|
+
missing_space_after_hash_rocket: {
|
8
|
+
search: /=>(?! )/,
|
9
|
+
replace: '=> '
|
10
|
+
},
|
11
|
+
|
12
|
+
missing_space_after_comma: {
|
13
|
+
search: /,(?!( |'\)|"\)|\/\)|\n))/, # /(,(?! ))(?!'\))(?!"\))(?!\/\))(?!\n)/
|
14
|
+
replace: ', '
|
15
|
+
},
|
16
|
+
|
17
|
+
missing_new_line_after_method: {
|
18
|
+
search: /end(\n)def/,
|
19
|
+
replace: '\n\n'
|
20
|
+
}
|
21
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruby_beautifier/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "ruby_beautifier"
|
8
|
+
gem.version = RubyBeautifier::VERSION
|
9
|
+
gem.authors = ["Pratik Khadloya"]
|
10
|
+
gem.email = ["tispratik@gmail.com"]
|
11
|
+
gem.description = %q{This gem is for beautifiying ruby code. It uses tradional regular expression parsing.}
|
12
|
+
gem.summary = %q{Shell script based ruby beautifier}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_development_dependency 'rspec'
|
20
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RubyBeautifier do
|
4
|
+
|
5
|
+
describe '#missing_space_before_hash_rocket' do
|
6
|
+
# http://rubular.com/r/TGwSyNOveS
|
7
|
+
|
8
|
+
it 'a=>b should convert to a =>b' do
|
9
|
+
text = 'my test a=>b string'
|
10
|
+
RubyBeautifier.missing_space_before_hash_rocket(text).should == 'my test a =>b string'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'a=> b should convert to a => b' do
|
14
|
+
text = 'my test a=> b string'
|
15
|
+
RubyBeautifier.missing_space_before_hash_rocket(text).should == 'my test a => b string'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'a =>b should be unchanged' do
|
19
|
+
text = 'my test a =>b string'
|
20
|
+
RubyBeautifier.missing_space_before_hash_rocket(text).should == nil # unchanged
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'a => b should be unchanged' do
|
24
|
+
text = 'my test a => b string'
|
25
|
+
RubyBeautifier.missing_space_before_hash_rocket(text).should == nil # unchanged
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#missing_space_after_hash_rocket' do
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#missing_space_after_comma' do
|
34
|
+
# http://rubular.com/r/WjrwSnmzyP
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#missing_new_line_after_method' do
|
38
|
+
# http://rubular.com/r/hROOd59cmg
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Add space after comma, following cases have been tested
|
43
|
+
# [a,b,c,d] => [a, b, c, d]
|
44
|
+
# [a, b, c,d] => [a, b, c, d]
|
45
|
+
# (a,b,c,d) => (a, b, c, d)
|
46
|
+
# (a, b, c, d) => no change
|
47
|
+
# a.join(',') => no change
|
48
|
+
# a.join(/,/) => no change
|
49
|
+
# a.join(",") => no change
|
50
|
+
# ["a","b", "c","d","e", "f"] => ["a", "b", "c", "d", "e", "f"]
|
51
|
+
# ["a","b", "c","d","e", "f"], => ["a", "b", "c", "d", "e", "f"],
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'ruby_beautifier'
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_beautifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pratik Khadloya
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: This gem is for beautifiying ruby code. It uses tradional regular expression
|
31
|
+
parsing.
|
32
|
+
email:
|
33
|
+
- tispratik@gmail.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- .rspec
|
40
|
+
- Gemfile
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- lib/ruby_beautifier.rb
|
45
|
+
- lib/ruby_beautifier/regex_definitions.rb
|
46
|
+
- lib/ruby_beautifier/version.rb
|
47
|
+
- ruby_beautifier.gemspec
|
48
|
+
- spec/ruby_beautifier_spec.rb
|
49
|
+
- spec/spec_helper.rb
|
50
|
+
homepage: ''
|
51
|
+
licenses: []
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.25
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Shell script based ruby beautifier
|
74
|
+
test_files:
|
75
|
+
- spec/ruby_beautifier_spec.rb
|
76
|
+
- spec/spec_helper.rb
|