ruby-beautify 0.94.1 → 0.94.2
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.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/WHATSNEW.md +5 -1
- data/bin/rbeautify +13 -2
- data/bin/ruby-beautify +13 -2
- data/lib/ruby-beautify/version.rb +1 -1
- data/spec/example.rb +30 -0
- data/spec/example_beautified.rb +30 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0200f47ad7a7b3b4db0cc305cc01c58e5f33e06f
|
4
|
+
data.tar.gz: bbc3bb4107a01d04cecfefb3437388749cd7cf8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 159b269436d56dce50cd217743b5423f7b6206a5ae64368b0a0aa60461f58fb8d95f030447c75787bac7eadab920c86801765561ef131485fdcc1cdaf3360f9c
|
7
|
+
data.tar.gz: 3c03b30b349a34338caf00e6686eafe3f13ec49e30e18737c57daa058c20a55683c07688daebdfd9ae1404c4b757093f706fbcac062ca105398a8e677ef6c120
|
data/README.md
CHANGED
@@ -56,6 +56,9 @@ Please feel free to open issues, I am actively working on this project again, th
|
|
56
56
|
* Add overwrite in place to files.
|
57
57
|
* Add 'best guest' for files that fail syntax checking.
|
58
58
|
* Add syntax checking to files rendered via STDIN.
|
59
|
+
* Seperate the content of the main bin into a proper namespace/library (so it doesn't pollute by default).
|
60
|
+
* Split up the spec into multiple specs.
|
61
|
+
* remove the link to rbeautify (by 1.0).
|
59
62
|
|
60
63
|
Longer term I'd like to do some more to assignment, line wrapping, and spacing in/around keywords.
|
61
64
|
|
data/WHATSNEW.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
## 0.94.
|
1
|
+
## 0.94.2
|
2
|
+
* Support for case statements thanks to @pkuykendall.
|
3
|
+
* @pkuykendall also brings us proper syntax formatting for assignments from the return value of an if check (that's a mouth full).
|
4
|
+
|
5
|
+
## 0.94.1
|
2
6
|
* Multiline string and embedded doc support thanks to @veelenga.
|
3
7
|
|
4
8
|
## 0.94.0
|
data/bin/rbeautify
CHANGED
@@ -12,8 +12,8 @@ Options = OptionParser.new do |opts|
|
|
12
12
|
end
|
13
13
|
Options.parse!
|
14
14
|
|
15
|
-
@open_block_start = ["module", "class", "begin", "def", 'if', 'while', 'unless']
|
16
|
-
@both_block = ["else", "elsif", 'rescue']
|
15
|
+
@open_block_start = ["module", "class", "begin", "def", 'if', 'while', 'unless', 'case']
|
16
|
+
@both_block = ["else", "elsif", 'rescue', 'when']
|
17
17
|
@open_block_do = ['do', '{']
|
18
18
|
@close_block = ['end', '}']
|
19
19
|
|
@@ -81,6 +81,7 @@ end
|
|
81
81
|
|
82
82
|
# is the first word a key word?
|
83
83
|
def starts_block?(line_lex)
|
84
|
+
return true if contains_block_assignment? line_lex
|
84
85
|
line_lex.each do |x|
|
85
86
|
# search for a first non-space token
|
86
87
|
if not x[1] == :on_sp
|
@@ -147,6 +148,16 @@ def closing_assignment?(line_lex)
|
|
147
148
|
return true if closes > opens
|
148
149
|
end
|
149
150
|
|
151
|
+
# test for assignment from a block
|
152
|
+
def contains_block_assignment?(line_lex)
|
153
|
+
compacted_line = line_lex.reject{|x| x[1] == :on_sp} #remove spaces
|
154
|
+
idx = compacted_line.find_index{|x| x[2] == '='} #find first equal sign
|
155
|
+
if idx
|
156
|
+
return @open_block_start.include?(compacted_line[idx+1][2]) #check for if/begin block
|
157
|
+
end
|
158
|
+
return false
|
159
|
+
end
|
160
|
+
|
150
161
|
# is this ruby file valid syntax?
|
151
162
|
def valid_syntax?(file)
|
152
163
|
#ugly but fast, ruby returns stdout if it's ok, and stderr if not.
|
data/bin/ruby-beautify
CHANGED
@@ -12,8 +12,8 @@ Options = OptionParser.new do |opts|
|
|
12
12
|
end
|
13
13
|
Options.parse!
|
14
14
|
|
15
|
-
@open_block_start = ["module", "class", "begin", "def", 'if', 'while', 'unless']
|
16
|
-
@both_block = ["else", "elsif", 'rescue']
|
15
|
+
@open_block_start = ["module", "class", "begin", "def", 'if', 'while', 'unless', 'case']
|
16
|
+
@both_block = ["else", "elsif", 'rescue', 'when']
|
17
17
|
@open_block_do = ['do', '{']
|
18
18
|
@close_block = ['end', '}']
|
19
19
|
|
@@ -81,6 +81,7 @@ end
|
|
81
81
|
|
82
82
|
# is the first word a key word?
|
83
83
|
def starts_block?(line_lex)
|
84
|
+
return true if contains_block_assignment? line_lex
|
84
85
|
line_lex.each do |x|
|
85
86
|
# search for a first non-space token
|
86
87
|
if not x[1] == :on_sp
|
@@ -147,6 +148,16 @@ def closing_assignment?(line_lex)
|
|
147
148
|
return true if closes > opens
|
148
149
|
end
|
149
150
|
|
151
|
+
# test for assignment from a block
|
152
|
+
def contains_block_assignment?(line_lex)
|
153
|
+
compacted_line = line_lex.reject{|x| x[1] == :on_sp} #remove spaces
|
154
|
+
idx = compacted_line.find_index{|x| x[2] == '='} #find first equal sign
|
155
|
+
if idx
|
156
|
+
return @open_block_start.include?(compacted_line[idx+1][2]) #check for if/begin block
|
157
|
+
end
|
158
|
+
return false
|
159
|
+
end
|
160
|
+
|
150
161
|
# is this ruby file valid syntax?
|
151
162
|
def valid_syntax?(file)
|
152
163
|
#ugly but fast, ruby returns stdout if it's ok, and stderr if not.
|
data/spec/example.rb
CHANGED
@@ -92,3 +92,33 @@ puts "This is multi line interpolated string #{
|
|
92
92
|
x
|
93
93
|
}"
|
94
94
|
end
|
95
|
+
|
96
|
+
# Test to validate case statements
|
97
|
+
def case_test opts=nil
|
98
|
+
case test_case
|
99
|
+
when 'Passing'
|
100
|
+
call(:pass)
|
101
|
+
when 'Failing'
|
102
|
+
call(:fail)
|
103
|
+
when 'Error'
|
104
|
+
call(:error)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Test for variable assignment from an if statement
|
109
|
+
@products = if params[:category]
|
110
|
+
Category.find(params[:category]).products
|
111
|
+
else
|
112
|
+
Product.all
|
113
|
+
end
|
114
|
+
|
115
|
+
# Test for variable assignment from a block
|
116
|
+
response = begin
|
117
|
+
if true?
|
118
|
+
api_call(test)
|
119
|
+
else
|
120
|
+
rejected
|
121
|
+
end
|
122
|
+
rescue
|
123
|
+
'FALSE'
|
124
|
+
end
|
data/spec/example_beautified.rb
CHANGED
@@ -92,3 +92,33 @@ def m (x)
|
|
92
92
|
x
|
93
93
|
}"
|
94
94
|
end
|
95
|
+
|
96
|
+
# Test to validate case statements
|
97
|
+
def case_test opts=nil
|
98
|
+
case test_case
|
99
|
+
when 'Passing'
|
100
|
+
call(:pass)
|
101
|
+
when 'Failing'
|
102
|
+
call(:fail)
|
103
|
+
when 'Error'
|
104
|
+
call(:error)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Test for variable assignment from an if statement
|
109
|
+
@products = if params[:category]
|
110
|
+
Category.find(params[:category]).products
|
111
|
+
else
|
112
|
+
Product.all
|
113
|
+
end
|
114
|
+
|
115
|
+
# Test for variable assignment from a block
|
116
|
+
response = begin
|
117
|
+
if true?
|
118
|
+
api_call(test)
|
119
|
+
else
|
120
|
+
rejected
|
121
|
+
end
|
122
|
+
rescue
|
123
|
+
'FALSE'
|
124
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-beautify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.94.
|
4
|
+
version: 0.94.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Brodeur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|