hash_rocket 0.2.7 → 0.2.8
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/.gitignore +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +7 -6
- data/lib/hash_rocket/version.rb +1 -1
- data/lib/hash_rocket.rb +7 -6
- data/lib/tasks/hash_rocket.rake +1 -1
- data/spec/data/Gemfile +18 -0
- data/spec/hash_rocket_spec.rb +10 -8
- metadata +4 -1
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,12 +8,7 @@ by the other ruby symbolize keys convention ->
|
|
8
8
|
|
9
9
|
symbolize_key: 'value'
|
10
10
|
|
11
|
-
Supported formats:
|
12
|
-
|
13
|
-
rb
|
14
|
-
erb
|
15
|
-
html
|
16
|
-
haml
|
11
|
+
Supported formats: ( rb, erb, html, haml, spec ) + Gemfile
|
17
12
|
|
18
13
|
## Installation
|
19
14
|
|
@@ -43,6 +38,12 @@ Specify a single file path:
|
|
43
38
|
|
44
39
|
rake hash_rocket:convert TARGET="/complete/path/to/file"
|
45
40
|
|
41
|
+
Specify verbose mode (print all the matching string):
|
42
|
+
|
43
|
+
rake hash_rocket:convert VERBOSE="true"
|
44
|
+
|
45
|
+
You can pass more than one option as well
|
46
|
+
|
46
47
|
Notes:
|
47
48
|
|
48
49
|
This script will prompt you the files he cannot parse
|
data/lib/hash_rocket/version.rb
CHANGED
data/lib/hash_rocket.rb
CHANGED
@@ -6,14 +6,14 @@ module HashRocket
|
|
6
6
|
require "hash_rocket/railtie"
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.convert(folder=nil, path=nil)
|
9
|
+
def self.convert(folder=nil, path=nil, verbose=nil)
|
10
10
|
file_names = path_parameters(folder, path)
|
11
11
|
file_names.each do |fn|
|
12
|
-
if fn =~
|
12
|
+
if fn =~ /(Gemfile|\.(erb|rb|html|haml|spec))/
|
13
13
|
begin
|
14
14
|
text = retreive_file(folder, path, fn)
|
15
15
|
text = solve_invalid_byte_sequence_in_utf8(text)
|
16
|
-
text = organize_symbols(text)
|
16
|
+
text = organize_symbols(text, verbose)
|
17
17
|
File.open(fn, "w") {|file| file.puts text }
|
18
18
|
rescue
|
19
19
|
puts "ERROR ON #{fn}"
|
@@ -37,15 +37,16 @@ private
|
|
37
37
|
return text.encode!('UTF-8')
|
38
38
|
end
|
39
39
|
|
40
|
-
def self.organize_symbols(text)
|
40
|
+
def self.organize_symbols(text, verbose)
|
41
41
|
result = text.scan(/((\ |^(?!::)):\w{1,}(\ {1,}|[\ {1,}]?)=>(\ {1,}|[\ ]?))/).flatten
|
42
|
-
text = match_symbols(text, result) if result
|
42
|
+
text = match_symbols(text, result, verbose) if result
|
43
43
|
text
|
44
44
|
end
|
45
45
|
|
46
|
-
def self.match_symbols(text, strings)
|
46
|
+
def self.match_symbols(text, strings, verbose)
|
47
47
|
strings.uniq.each do |str|
|
48
48
|
unless str.blank?
|
49
|
+
puts str if verbose
|
49
50
|
start, symbol, hash_rocket = str.match(/(^\ ?:*)(.+)((\ {1,}|[\ {1,}]?)=>(\ {1,}|[\ ]?))/).captures
|
50
51
|
text = text.gsub(str, start.gsub(':','') + symbol.gsub(/\ /, "") + ": ")
|
51
52
|
end
|
data/lib/tasks/hash_rocket.rake
CHANGED
data/spec/data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Example
|
2
|
+
|
3
|
+
def foo
|
4
|
+
:no_ident => 'value'
|
5
|
+
::Class => 'value'
|
6
|
+
s::Class => 'value'
|
7
|
+
:normal => 'value'
|
8
|
+
:1digit => 'value'
|
9
|
+
:Capital => 'value'
|
10
|
+
:under_score => 'value'
|
11
|
+
:no_space=>'value'
|
12
|
+
:right_space=> 'value'
|
13
|
+
:left_space =>'value'
|
14
|
+
:left_double_space => 'value'
|
15
|
+
:right_double_space => 'value'
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/spec/hash_rocket_spec.rb
CHANGED
@@ -5,14 +5,12 @@ describe HashRocket do
|
|
5
5
|
let(:folder) { File.expand_path('../..',__FILE__) + "/spec/data" }
|
6
6
|
let(:result) { "/result.txt" }
|
7
7
|
|
8
|
-
pending "write it"
|
9
|
-
|
10
8
|
describe "hash_rocket should be replaced if the file extention is supported: " do
|
11
9
|
|
12
10
|
before :each do
|
13
11
|
@file = folder + example.metadata[:file_ext]
|
14
12
|
@backup = File.read(@file)
|
15
|
-
HashRocket.convert(nil, @file)
|
13
|
+
HashRocket.convert(nil, @file, true)
|
16
14
|
@conversion = File.read(@file)
|
17
15
|
end
|
18
16
|
|
@@ -21,23 +19,27 @@ describe HashRocket do
|
|
21
19
|
@backup.should eq File.read(@file)
|
22
20
|
end
|
23
21
|
|
24
|
-
it "
|
22
|
+
it "Gemfile", file_ext: "/Gemfile" do
|
23
|
+
@conversion.should eq File.read(folder + result)
|
24
|
+
end
|
25
|
+
|
26
|
+
it ".rb", file_ext: "/file.rb" do
|
25
27
|
@conversion.should eq File.read(folder + result)
|
26
28
|
end
|
27
29
|
|
28
|
-
it ".erb", :
|
30
|
+
it ".erb", file_ext: "/file.erb" do
|
29
31
|
@conversion.should eq File.read(folder + result)
|
30
32
|
end
|
31
33
|
|
32
|
-
it ".html", :
|
34
|
+
it ".html", file_ext: "/file.html" do
|
33
35
|
@conversion.should eq File.read(folder + result)
|
34
36
|
end
|
35
37
|
|
36
|
-
it ".haml", :
|
38
|
+
it ".haml", file_ext: "/file.haml" do
|
37
39
|
@conversion.should eq File.read(folder + result)
|
38
40
|
end
|
39
41
|
|
40
|
-
it ".yml", :
|
42
|
+
it ".yml", file_ext: "/file.yml" do
|
41
43
|
@conversion.should_not eq File.read(folder + result)
|
42
44
|
end
|
43
45
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_rocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- lib/hash_rocket/railtie.rb
|
76
76
|
- lib/hash_rocket/version.rb
|
77
77
|
- lib/tasks/hash_rocket.rake
|
78
|
+
- spec/data/Gemfile
|
78
79
|
- spec/data/file.erb
|
79
80
|
- spec/data/file.haml
|
80
81
|
- spec/data/file.html
|
@@ -108,6 +109,7 @@ signing_key:
|
|
108
109
|
specification_version: 3
|
109
110
|
summary: hash rocket explode
|
110
111
|
test_files:
|
112
|
+
- spec/data/Gemfile
|
111
113
|
- spec/data/file.erb
|
112
114
|
- spec/data/file.haml
|
113
115
|
- spec/data/file.html
|
@@ -116,3 +118,4 @@ test_files:
|
|
116
118
|
- spec/data/result.txt
|
117
119
|
- spec/hash_rocket_spec.rb
|
118
120
|
- spec/spec_helper.rb
|
121
|
+
has_rdoc:
|