alpaca_complete 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +6 -6
- data/README.md +14 -61
- data/VERSION +1 -1
- data/alpaca_complete.gemspec +0 -2
- data/autoload/neocomplcache/sources/locale_complete.vim +64 -56
- data/lib/AlpacaComplete/detect.rb +3 -7
- data/lib/AlpacaComplete/locale_complete.rb +28 -86
- data/lib/AlpacaComplete/utils.rb +53 -54
- data/lib/AlpacaComplete.rb +3 -12
- data/lib/Hash.rb +36 -0
- data/lib/Object.rb +9 -0
- data/preview1.png +0 -0
- data/spec/hash_spec.rb +51 -0
- data/spec/locale_complete_spec.rb +0 -28
- data/spec/utils_spec.rb +2 -4
- data/spec/version_spec.rb +2 -6
- metadata +7 -3
data/Gemfile.lock
CHANGED
@@ -12,9 +12,9 @@ GEM
|
|
12
12
|
git (>= 1.2.5)
|
13
13
|
rake
|
14
14
|
rdoc
|
15
|
-
json (1.7.
|
16
|
-
multi_json (1.
|
17
|
-
rake (0.
|
15
|
+
json (1.7.6)
|
16
|
+
multi_json (1.5.0)
|
17
|
+
rake (10.0.3)
|
18
18
|
rdoc (3.12)
|
19
19
|
json (~> 1.4)
|
20
20
|
rspec (2.8.0)
|
@@ -27,10 +27,10 @@ GEM
|
|
27
27
|
rspec-instafail (0.2.4)
|
28
28
|
rspec-mocks (2.8.0)
|
29
29
|
ruby-progressbar (1.0.2)
|
30
|
-
simplecov (0.
|
30
|
+
simplecov (0.7.1)
|
31
31
|
multi_json (~> 1.0)
|
32
|
-
simplecov-html (~> 0.
|
33
|
-
simplecov-html (0.
|
32
|
+
simplecov-html (~> 0.7.1)
|
33
|
+
simplecov-html (0.7.1)
|
34
34
|
|
35
35
|
PLATFORMS
|
36
36
|
ruby
|
data/README.md
CHANGED
@@ -1,66 +1,25 @@
|
|
1
1
|
# alpaca_complete
|
2
2
|
|
3
|
-
|
4
|
-
railsを使っていて気が遠くなるくらいの単語数に嫌気がさし、
|
5
|
-
僕はエディタを乗り換えてIDEを使おうか迷っていました。
|
6
|
-
|
7
|
-
そんなとき出会ったのが、[RubyMine]( http://www.jetbrains.com/ruby/ )。
|
8
|
-
|
9
|
-
「RubyMineすげぇ。やべぇ。vim敵わん。。」
|
10
|
-
さすが、IDE。補完からビジュアルから、素晴らしい機能が満載でした。
|
11
|
-
それからというもの、RubyMineの虜になっていました。
|
12
|
-
|
13
|
-
しかし、IDE。vimキーバインドはガラクタでした。
|
14
|
-
vim病が再発しそうなころ、神の声が聞こえました。
|
15
|
-
|
16
|
-
**「それ、vimで出来るよ」**
|
17
|
-
|
18
|
-
さぁ、楽しい開発の始まりです。
|
19
|
-
|
20
|
-
RoR & vimユーザーの為の最強補完プラグインを作成しております。
|
3
|
+
RoR & vimユーザーの為の補完プラグインを作成しております。
|
21
4
|
目標はRubyMineの補完機能を超えることです。
|
22
5
|
|
23
6
|
## install
|
24
7
|
|
25
|
-
neocomplcacheを未インストールの方はさきにこちらをインストールしてください。
|
26
|
-
|
27
8
|
```vim:.vimrc
|
28
|
-
NeoBundle 'taichouchou2/alpaca_complete'
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
`gem install alpaca_complete`
|
9
|
+
NeoBundle 'taichouchou2/alpaca_complete',{
|
10
|
+
\ 'depends' : 'tpope/vim-rails',
|
11
|
+
\ 'build' : {
|
12
|
+
\ 'mac' : 'gem install alpaca_complete',
|
13
|
+
\ 'unix' : 'gem install alpaca_complete',
|
14
|
+
\}}
|
35
15
|
```
|
36
16
|
|
37
|
-
|
38
|
-
|
39
|
-
```shell
|
40
|
-
rake build
|
41
|
-
rake install
|
42
|
-
```
|
17
|
+
![locale補完](https://github.com/taichouchou2/alpaca_complete/blob/master/preview1.png?raw=true)
|
43
18
|
|
44
|
-
|
19
|
+
NeoBundle以外の人は、下記を実行してください
|
45
20
|
|
46
21
|
```shell
|
47
|
-
|
48
|
-
Successfully built RubyGem
|
49
|
-
Name: alpaca_complete
|
50
|
-
Version: 0.1.0
|
51
|
-
File: alpaca_complete-0.1.0.gem
|
52
|
-
taichou@tai-no-MacBook-Air:~/.bundle/alpaca_complete $
|
53
|
-
rake install
|
54
|
-
Successfully built RubyGem
|
55
|
-
Name: alpaca_complete
|
56
|
-
Version: 0.1.0
|
57
|
-
File: alpaca_complete-0.1.0.gem
|
58
|
-
Executing "ruby -S gem install ./pkg/alpaca_complete-0.1.0.gem":
|
59
|
-
ruby -S gem install ./pkg/alpaca_complete-0.1.0.gem
|
60
|
-
Successfully installed alpaca_complete-0.1.0
|
61
|
-
1 gem installed
|
62
|
-
Installing ri documentation for alpaca_complete-0.1.0...
|
63
|
-
Installing RDoc documentation for alpaca_complete-0.1.0...
|
22
|
+
`gem install alpaca_complete`
|
64
23
|
```
|
65
24
|
|
66
25
|
### TODO
|
@@ -68,31 +27,26 @@ rake install
|
|
68
27
|
下記の機能を実装予定です。(優先順位順)
|
69
28
|
それぞれの補完は説明や引数付きで補完する予定です。
|
70
29
|
|
71
|
-
-
|
30
|
+
- locales(I18n.t)補完
|
31
|
+
- chaching機能
|
72
32
|
- migrate補完
|
73
33
|
- view補完
|
74
34
|
- controller補完
|
75
35
|
- models補完
|
76
36
|
- validate
|
77
37
|
- 推奨構文
|
78
|
-
- chaching機能
|
79
38
|
|
80
39
|
### お願い
|
81
40
|
|
82
|
-
「こんな補完が欲しい」っていうのがあるかたは、
|
83
|
-
Issuesか、twitterに書き込んでください。
|
84
|
-
|
41
|
+
「こんな補完が欲しい」っていうのがあるかたは、 Issuesか、twitterに書き込んでください。
|
85
42
|
あと、コミッターも募集しています。
|
86
43
|
|
87
44
|
## and more
|
88
45
|
|
89
|
-
**FEATURES**
|
90
|
-
|
91
|
-
1. coloring function
|
92
|
-
|
93
46
|
**AUTHOR**
|
94
47
|
|
95
48
|
Hiroyuki Ishii \<alprhcp666@gmail.com\>
|
49
|
+
@alpaca_taichou
|
96
50
|
|
97
51
|
**COPYRIGHT**
|
98
52
|
|
@@ -104,4 +58,3 @@ Copyright (c) 2012, Hiroyuki Ishii \<alprhcp666@gmail.com\>
|
|
104
58
|
|
105
59
|
[MIT]: http://www.opensource.org/licenses/mit-license.php
|
106
60
|
|
107
|
-
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/alpaca_complete.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
"=============================================================================
|
2
2
|
" FILE: locale_complete.Vim
|
3
3
|
" AUTHOR: Hiroyuki Ishii <alprhcp666@gmail.com>
|
4
|
-
" Last Modified: 2012-
|
4
|
+
" Last Modified: 2012-12-12
|
5
5
|
" License: MIT license {{{
|
6
6
|
" Permission is hereby granted, free of charge, to any person obtaining
|
7
7
|
" a copy of this software and associated documentation files (the
|
@@ -24,22 +24,30 @@
|
|
24
24
|
" }}}
|
25
25
|
"=============================================================================
|
26
26
|
|
27
|
+
if exists('g:loaded_alpaca_complete') || &cp || v:version < 700
|
28
|
+
finish
|
29
|
+
endif
|
30
|
+
|
31
|
+
if !executable('alpaca_complete') "{{{
|
32
|
+
echohl ErrorMsg
|
33
|
+
echo 'requires gem ins alpaca_complete'
|
34
|
+
echohl None
|
35
|
+
if executable('gem')
|
36
|
+
call system('gem ins alpaca_complete')
|
37
|
+
endif
|
38
|
+
finish
|
39
|
+
endif "}}}
|
40
|
+
|
41
|
+
let g:loaded_alpaca_complete = 1
|
42
|
+
|
27
43
|
let s:save_cpo = &cpo
|
28
44
|
set cpo&vim
|
29
45
|
|
30
|
-
"
|
31
|
-
|
46
|
+
" Initialize "{{{
|
47
|
+
let g:alpaca_complete_caching_list = {}
|
32
48
|
let s:source = {
|
33
|
-
\ 'name' : '
|
34
|
-
\ 'kind' : '
|
35
|
-
\ 'filetypes' : {
|
36
|
-
\ 'ruby' : 1,
|
37
|
-
\ 'eruby' : 1,
|
38
|
-
\ 'haml' : 1,
|
39
|
-
\ 'yaml' : 1,
|
40
|
-
\ 'javascript' : 1,
|
41
|
-
\ 'coffee' : 1,
|
42
|
-
\ },
|
49
|
+
\ 'name' : 'locale_complete',
|
50
|
+
\ 'kind' : 'complfunc',
|
43
51
|
\}
|
44
52
|
|
45
53
|
if !exists('g:source_locale_complete_length')
|
@@ -49,96 +57,97 @@ endif
|
|
49
57
|
if !exists('g:source_locale_complete_rank')
|
50
58
|
let g:source_locale_complete_rank = 200
|
51
59
|
endif
|
52
|
-
|
53
|
-
if !exists('g:source_locale_complete_enable_dup')
|
54
|
-
let g:source_locale_complete_enable_dup = 1
|
55
|
-
endif
|
56
|
-
|
57
60
|
"}}}
|
58
61
|
|
59
|
-
function! s:source.initialize()
|
62
|
+
function! s:source.initialize() "{{{
|
60
63
|
call neocomplcache#set_completion_length('locale_complete', g:source_locale_complete_length)
|
61
64
|
call neocomplcache#set_dictionary_helper(g:neocomplcache_source_rank,
|
62
65
|
\ 'locale_complete', g:source_locale_complete_rank)
|
63
66
|
|
64
67
|
" Initialize.
|
65
|
-
let s:complete_list = {}
|
66
68
|
|
67
69
|
" Create cache directory.
|
68
70
|
if !isdirectory(neocomplcache#get_temporary_directory() . '/alpaca_complete')
|
69
71
|
call mkdir(neocomplcache#get_temporary_directory() . '/alpaca_complete')
|
70
72
|
endif
|
73
|
+
endfunction "}}}
|
71
74
|
|
72
|
-
|
73
|
-
|
74
|
-
autocmd BufReadPost * call s:check_recache()
|
75
|
-
endfunction
|
75
|
+
function! s:source.finalize() " {{{
|
76
|
+
endfunction " }}}
|
76
77
|
|
77
|
-
function! s:source.
|
78
|
-
|
79
|
-
|
80
|
-
function! s:source.get_keyword_pos(cur_text)"{{{
|
81
|
-
" XXX vim-ref の availableみたいな機構ないのかな。
|
82
|
-
if !exists('b:rails_root')
|
83
|
-
return -1
|
84
|
-
endif
|
85
|
-
if a:cur_text =~ '.*I18n\.t.*'
|
86
|
-
let cur_pos = match(a:cur_text, '[a-zA-Z]\+[a-zA-Z._:]*$')
|
78
|
+
function! s:source.get_keyword_pos(cur_text) "{{{
|
79
|
+
if exists('b:rails_root') && a:cur_text =~ '.*I18n\.t\A.*\|\(\A\|^\)t\A'
|
80
|
+
let cur_pos = match( a:cur_text, '[a-zA-Z]\+[a-zA-Z0-9._:-]*$' )
|
87
81
|
|
88
82
|
return cur_pos < 0 ? -1 : cur_pos
|
89
83
|
end
|
84
|
+
|
90
85
|
return -1
|
91
|
-
endfunction"}}}
|
86
|
+
endfunction "}}}
|
92
87
|
|
93
|
-
function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str)"{{{
|
88
|
+
function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str) "{{{
|
89
|
+
if !exists('b:rails_root')|return|endif
|
94
90
|
let line = a:cur_keyword_str
|
95
91
|
|
96
92
|
let input_first = match(line, '[a-zA-Z._:]*$')
|
97
93
|
let input_obj = line[input_first :]
|
98
94
|
|
99
|
-
if input_obj ==# '' || input_obj ==# "\s"
|
95
|
+
if input_obj ==# '' || input_obj ==# "\s"
|
100
96
|
return []
|
101
97
|
endif
|
102
98
|
|
103
|
-
|
99
|
+
let cache_name = s:get_cache_name()
|
100
|
+
if !has_key(g:alpaca_complete_caching_list, cache_name)
|
101
|
+
" load cache
|
104
102
|
let keyword_lists = neocomplcache#cache#index_load_from_cache(
|
105
|
-
\ 'alpaca_complete',
|
103
|
+
\ 'alpaca_complete', cache_name)
|
106
104
|
if !empty(keyword_lists)
|
105
|
+
let g:alpaca_complete_caching_list[cache_name] = keyword_lists
|
106
|
+
|
107
107
|
" Caching from cache.
|
108
|
-
let s:complete_list[s:get_cache_name()] = keyword_lists
|
109
108
|
return neocomplcache#dictionary_filter(keyword_lists, input_obj)
|
110
109
|
else
|
110
|
+
call neocomplcache#sources#locale_complete#check_recache()
|
111
111
|
return []
|
112
112
|
endif
|
113
113
|
else
|
114
|
-
|
115
|
-
return neocomplcache#dictionary_filter(
|
114
|
+
" use caching
|
115
|
+
return neocomplcache#dictionary_filter(
|
116
|
+
\ g:alpaca_complete_caching_list[cache_name] , input_obj)
|
116
117
|
endif
|
117
|
-
endfunction"}}}
|
118
|
+
endfunction "}}}
|
118
119
|
|
119
|
-
function!
|
120
|
-
|
120
|
+
function! neocomplcache#sources#locale_complete#check_recache() "{{{
|
121
|
+
let list_key = s:get_cache_name()
|
122
|
+
" if !list_key |return -1| endif
|
121
123
|
|
122
|
-
if !has_key(
|
123
|
-
call
|
124
|
+
if !has_key(g:alpaca_complete_caching_list, list_key)
|
125
|
+
call neocomplcache#sources#locale_complete#caching()
|
124
126
|
endif
|
125
|
-
endfunction
|
127
|
+
endfunction "}}}
|
126
128
|
|
127
|
-
function! s:
|
129
|
+
function! s:get_rails_directory_name() "{{{
|
130
|
+
if !exists('b:rails_root')|return ''|endif
|
131
|
+
return b:rails_root[match(b:rails_root, '\/[^/]\+$') + 1:]
|
132
|
+
endfunction "}}}
|
133
|
+
|
134
|
+
function! s:get_cache_name() "{{{
|
135
|
+
if !exists('b:rails_root')|return -1|endif
|
128
136
|
return "locale_" . b:rails_root . "_locale"
|
129
|
-
endfunction
|
137
|
+
endfunction"}}}
|
130
138
|
|
131
|
-
function! neocomplcache#sources#locale_complete#get_cur_text()"{{{
|
139
|
+
function! neocomplcache#sources#locale_complete#get_cur_text() "{{{
|
132
140
|
return [line('.')]
|
133
|
-
endfunction"}}}
|
141
|
+
endfunction "}}}
|
134
142
|
|
135
|
-
function! neocomplcache#sources#locale_complete#define()"{{{
|
143
|
+
function! neocomplcache#sources#locale_complete#define() "{{{
|
136
144
|
return s:source
|
137
145
|
endfunction"}}}
|
138
146
|
|
139
147
|
" caching
|
140
|
-
"
|
141
|
-
|
148
|
+
function! neocomplcache#sources#locale_complete#caching() "{{{
|
149
|
+
if !exists('b:rails_root')|return -1|endif
|
150
|
+
|
142
151
|
" RoRの補完プラグインalpaca_completeを使う
|
143
152
|
let mf0 = neocomplcache#system( 'alpaca_complete -l -f ' . expand("%:p") )
|
144
153
|
let mf_list = split(mf0, '\n')
|
@@ -164,7 +173,6 @@ function! s:caching()
|
|
164
173
|
\ "word" : locale.key[strlen(locale.type) + 1 :],
|
165
174
|
\ "kind" : "[alpl_" . locale.type . "]",
|
166
175
|
\ "menu" : locale.value,
|
167
|
-
\ "dup" : g:source_locale_complete_enable_dup
|
168
176
|
\})
|
169
177
|
endfor
|
170
178
|
|
@@ -1,10 +1,8 @@
|
|
1
|
-
|
2
1
|
module AlpacaComplete::Detect
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def detect filename
|
3
|
+
# program portability from rails.vim
|
4
|
+
# return rails root path
|
5
|
+
def self.detect( filename )
|
8
6
|
fn = filename.gsub('\c^file://', '')
|
9
7
|
|
10
8
|
if File.readable?("#{fn}/config/environment.rb")
|
@@ -34,7 +32,5 @@ module AlpacaComplete::Detect
|
|
34
32
|
|
35
33
|
return nil
|
36
34
|
end
|
37
|
-
|
38
|
-
module_function :detect
|
39
35
|
end
|
40
36
|
|
@@ -1,110 +1,52 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
require 'yaml'
|
4
|
-
|
5
|
-
# hash extend deep_merge
|
6
|
-
class Hash
|
7
|
-
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
8
|
-
def deep_merge(other_hash)
|
9
|
-
dup.deep_merge!(other_hash)
|
10
|
-
end
|
11
|
-
|
12
|
-
# Same as +deep_merge+, but modifies +self+.
|
13
|
-
def deep_merge!(other_hash)
|
14
|
-
other_hash.each_pair do |k,v|
|
15
|
-
tv = self[k]
|
16
|
-
self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
|
17
|
-
end
|
18
|
-
self
|
19
|
-
end
|
20
|
-
|
21
|
-
def full_join( str = ".", key="" )
|
22
|
-
dup.full_join! str, key
|
23
|
-
end
|
24
|
-
|
25
|
-
def full_join!( str = ".", key="")
|
26
|
-
res = {}
|
27
|
-
self.each do |k, v|
|
28
|
-
full_key = key.empty? ? k : "#{key}.#{k}"
|
29
|
-
if v.is_a?(Hash)
|
30
|
-
res.deep_merge!( v.full_join( str, full_key ) )
|
31
|
-
else
|
32
|
-
res[full_key] = v
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
res
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
def join_to_str( list, str = "" )
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
3
|
|
45
4
|
module AlpacaComplete::LocaleComplete
|
46
|
-
Version = "1.0"
|
47
5
|
LOCALE_PATH = 'config/locales'
|
48
6
|
|
49
|
-
|
7
|
+
class << self
|
8
|
+
# return array of list to match word
|
9
|
+
def complete( path, word )
|
10
|
+
opt = { "path" => path }
|
11
|
+
comp = Regexp.new("^#{word}")
|
50
12
|
|
51
|
-
|
52
|
-
|
53
|
-
opt = { "path" => path}
|
54
|
-
comp = Regexp.new("^#{word}")
|
13
|
+
get_locale_hash( opt ).select {|v| v.match comp }
|
14
|
+
end
|
55
15
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
16
|
+
# return array of locale list.
|
17
|
+
def get_locale_list( opt={} )
|
18
|
+
locales = get_locale_hash(opt)
|
60
19
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
20
|
+
res = []
|
21
|
+
locales.each do |k, v|
|
22
|
+
res << k
|
23
|
+
end
|
65
24
|
|
66
|
-
|
67
|
-
|
68
|
-
locales = get_locale_hash(opt)
|
25
|
+
res
|
26
|
+
end
|
69
27
|
|
70
|
-
|
71
|
-
|
72
|
-
|
28
|
+
# return hash of locale list. hash key is full_name.
|
29
|
+
def get_locale_hash( opt={} )
|
30
|
+
get_locale( opt["path"] ).join_keys(".")
|
73
31
|
end
|
74
32
|
|
75
|
-
|
76
|
-
|
33
|
+
# return hash deep_merged config/locales/**/*.yml
|
34
|
+
def get_locale( file_path )
|
35
|
+
require 'yaml'
|
77
36
|
|
78
|
-
|
79
|
-
|
80
|
-
rails_root = detect( file_path )
|
81
|
-
locale_path = "#{rails_root}/#{LOCALE_PATH}"
|
37
|
+
rails_root = ::AlpacaComplete::Detect.detect( file_path )
|
38
|
+
locale_path = "#{rails_root}/#{LOCALE_PATH}"
|
82
39
|
|
83
|
-
|
84
|
-
|
40
|
+
# hash
|
41
|
+
locales = Hash.new
|
85
42
|
|
86
|
-
|
87
|
-
begin
|
43
|
+
Dir.glob( "#{locale_path}/**/*.yml" ).each do |file|
|
88
44
|
locale_hash = YAML::load_file( file )
|
89
45
|
locales.deep_merge!(locale_hash)
|
90
|
-
rescue
|
91
|
-
# TODO yamlにエラーがあった場合の処理
|
92
|
-
|
93
46
|
end
|
94
|
-
end
|
95
47
|
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
# return methods of i18n as string
|
100
|
-
def self.get_methods
|
101
|
-
require 'i18n'
|
102
|
-
concat = []
|
103
|
-
I18n.methods.each do |m|
|
104
|
-
concat << m.to_s
|
48
|
+
locales
|
105
49
|
end
|
106
|
-
|
107
|
-
concat.join("\n")
|
108
50
|
end
|
109
51
|
|
110
52
|
end
|
data/lib/AlpacaComplete/utils.rb
CHANGED
@@ -1,71 +1,70 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
require 'optparse'
|
4
|
-
require 'yaml'
|
5
4
|
|
6
5
|
module AlpacaComplete::Utils
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
class << self
|
7
|
+
def option_parser args
|
8
|
+
args << '-h' if args.empty?
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
optparse = OptionParser.new do |opts|
|
12
|
+
opts.banner = get_banner.gsub(/^\s*/, '')
|
13
|
+
|
14
|
+
opts.on('-h','--help','HELP') do
|
15
|
+
puts opts
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on('-l', '--locale', 'locale complete') do |l|
|
20
|
+
options[:locale] = l
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on('-w VAL', '--word VAL', 'uncomplete word') do |l|
|
24
|
+
options[:word] = l
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on('-f VAL', '--filepath VAL', 'rails path') do |l|
|
28
|
+
options[:path] = l
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on('-v', '--version', 'Version') do
|
32
|
+
puts ::AlpacaComplete::VERSION
|
33
|
+
exit
|
34
|
+
end
|
18
35
|
end
|
19
36
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
37
|
+
optparse.parse! args
|
38
|
+
options[:files] = args.to_a
|
23
39
|
|
24
|
-
|
25
|
-
options[:
|
26
|
-
|
40
|
+
{
|
41
|
+
locale: options[:locale],
|
42
|
+
path: options[:path],
|
43
|
+
word: options[:word],
|
44
|
+
uncomplete: options[:locale]
|
45
|
+
}
|
46
|
+
end
|
27
47
|
|
28
|
-
|
29
|
-
|
30
|
-
|
48
|
+
def get_banner
|
49
|
+
return <<-BANNAR
|
50
|
+
Usage:
|
51
|
+
alpacaComplete [OPTIONS]
|
52
|
+
---------------------------------------------------------------------
|
53
|
+
BANNAR
|
54
|
+
end
|
31
55
|
|
32
|
-
|
33
|
-
|
34
|
-
|
56
|
+
def run( cmd, path, uncomplete="" )
|
57
|
+
case cmd
|
58
|
+
when "locale"
|
59
|
+
puts AlpacaComplete::LocaleComplete.complete path, uncomplete
|
35
60
|
end
|
36
|
-
|
37
61
|
end
|
38
62
|
|
39
|
-
|
40
|
-
|
63
|
+
def load_yaml( path )
|
64
|
+
return nil until File.exist?(path)
|
41
65
|
|
42
|
-
|
43
|
-
|
44
|
-
path: options[:path],
|
45
|
-
word: options[:word],
|
46
|
-
uncomplete: options[:locale]
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.get_banner
|
51
|
-
return <<-BANNAR
|
52
|
-
Usage:
|
53
|
-
alpacaComplete [OPTIONS]
|
54
|
-
---------------------------------------------------------------------
|
55
|
-
BANNAR
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.run cmd, path, uncomplete=""
|
59
|
-
case cmd
|
60
|
-
when "locale"
|
61
|
-
puts AlpacaComplete::LocaleComplete.complete path, uncomplete
|
66
|
+
require 'yaml'
|
67
|
+
YAML::load_file( path )
|
62
68
|
end
|
63
69
|
end
|
64
|
-
|
65
|
-
def load_yaml( path )
|
66
|
-
return nil until File.exist?(path)
|
67
|
-
|
68
|
-
YAML::load_file( path )
|
69
|
-
end
|
70
|
-
|
71
70
|
end
|
data/lib/AlpacaComplete.rb
CHANGED
@@ -1,19 +1,10 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
class Object
|
6
|
-
def blank?
|
7
|
-
if self.respond_to? :"empty?"
|
8
|
-
self.nil? or self.empty?
|
9
|
-
else
|
10
|
-
self.nil?
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
3
|
+
require 'Hash'
|
4
|
+
require 'Object'
|
14
5
|
|
15
6
|
module AlpacaComplete
|
16
|
-
|
7
|
+
VERSION = "0.1.4"
|
17
8
|
|
18
9
|
autoload :LocaleComplete, 'AlpacaComplete/locale_complete'
|
19
10
|
autoload :Utils, 'AlpacaComplete/utils'
|
data/lib/Hash.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# hash extend deep_merge
|
2
|
+
class Hash
|
3
|
+
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
4
|
+
def deep_merge(other_hash)
|
5
|
+
dup.deep_merge!(other_hash)
|
6
|
+
end
|
7
|
+
|
8
|
+
# Same as +deep_merge+, but modifies +self+.
|
9
|
+
def deep_merge!(other_hash)
|
10
|
+
other_hash.each_pair do |k,v|
|
11
|
+
tv = self[k]
|
12
|
+
self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
|
13
|
+
end
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def join_keys( str = ".", key="" )
|
18
|
+
dup.join_keys! str, key
|
19
|
+
end
|
20
|
+
|
21
|
+
def join_keys!( str = ".", key="")
|
22
|
+
res = {}
|
23
|
+
each do |k, v|
|
24
|
+
full_key = key.empty? ? k : "#{key}#{str}#{k}"
|
25
|
+
if v.is_a?(Hash)
|
26
|
+
res.deep_merge!( v.join_keys( str, full_key ) )
|
27
|
+
else
|
28
|
+
res[full_key] = v
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
clear
|
33
|
+
self.merge! res
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
data/lib/Object.rb
ADDED
data/preview1.png
ADDED
Binary file
|
data/spec/hash_spec.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hash do
|
4
|
+
let(:hash_empty) { {} }
|
5
|
+
let(:hash_not_empty) { { hoge: 1, hoge2: 2} }
|
6
|
+
let(:deep_hash) { { first: { second: { third: 1 }} } }
|
7
|
+
|
8
|
+
def expectation_value(joint_box = ".")
|
9
|
+
{ "first#{joint_box}second#{joint_box}third" => 1 }
|
10
|
+
end
|
11
|
+
|
12
|
+
[:deep_merge, :deep_merge!, :join_keys, :join_keys!].each do |method|
|
13
|
+
it "has #{method} method" do
|
14
|
+
Hash.new.should respond_to(method)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "return a new hash with self and other merged recursively" do
|
19
|
+
hash_empty_dup = hash_empty.dup
|
20
|
+
hash_empty.deep_merge hash_not_empty
|
21
|
+
|
22
|
+
hash_empty.should eql(hash_empty_dup)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "return a hash with self and other merged recursively" do
|
26
|
+
hash_empty_dup = hash_empty.dup
|
27
|
+
hash_empty.deep_merge! hash_not_empty
|
28
|
+
|
29
|
+
hash_empty.should_not eql(hash_empty_dup)
|
30
|
+
hash_empty.should eql(hash_not_empty)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "return a string with join value into hash" do
|
34
|
+
deep_hash_clone = deep_hash.clone
|
35
|
+
deep_hash.join_keys(".").should eql expectation_value
|
36
|
+
deep_hash.dup.should eql deep_hash_clone.dup
|
37
|
+
|
38
|
+
deep_hash.join_keys!(".").should eql expectation_value
|
39
|
+
deep_hash.should_not eql deep_hash_clone
|
40
|
+
end
|
41
|
+
|
42
|
+
context :join_keys do
|
43
|
+
keys = %w[# . -> & = _]
|
44
|
+
keys.each do |key|
|
45
|
+
it "return hash key joined with #{key}" do
|
46
|
+
deep_hash.join_keys(key).should eql expectation_value(key)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -3,10 +3,6 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe AlpacaComplete::LocaleComplete do
|
6
|
-
context 'version' do
|
7
|
-
it { subject::Version.should > "0"}
|
8
|
-
end
|
9
|
-
|
10
6
|
context :get_locate do
|
11
7
|
let(:rails_path) {
|
12
8
|
File.realpath './spec/supports/rails_complete/app/controllers'
|
@@ -54,28 +50,4 @@ describe AlpacaComplete::LocaleComplete do
|
|
54
50
|
end
|
55
51
|
end
|
56
52
|
|
57
|
-
context :get_methods do
|
58
|
-
let(:methods) {
|
59
|
-
require 'i18n'
|
60
|
-
methods = I18n.methods
|
61
|
-
}
|
62
|
-
let(:methods_str) {
|
63
|
-
methods_str = subject.get_methods
|
64
|
-
}
|
65
|
-
|
66
|
-
it 'return methods by string' do
|
67
|
-
methods.each do |m|
|
68
|
-
methods_str.include?( m.to_s ).should eql(true)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'result is string' do
|
73
|
-
methods_str.is_a?( String ).should eql(true)
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'result is match "(\w+\n)+"' do
|
77
|
-
methods_str.match(/([a-zA-Z_!?]+\n)+/).should_not eql(nil)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
53
|
end
|
data/spec/utils_spec.rb
CHANGED
@@ -12,14 +12,12 @@ describe AlpacaComplete::Utils do
|
|
12
12
|
let(:yaml_dir) { 'spec/supports/dict' }
|
13
13
|
|
14
14
|
it 'return nil if yaml isnt exist' do
|
15
|
-
|
16
|
-
yaml_data = load_yaml "#{yaml_dir}/non_existent.yml"
|
15
|
+
yaml_data = AlpacaComplete::Utils.load_yaml "#{yaml_dir}/non_existent.yml"
|
17
16
|
yaml_data.should eql(nil)
|
18
17
|
end
|
19
18
|
|
20
19
|
it 'return hash if yaml is exist' do
|
21
|
-
|
22
|
-
yaml_data = load_yaml "#{yaml_dir}/existent.yml"
|
20
|
+
yaml_data = AlpacaComplete::Utils.load_yaml "#{yaml_dir}/existent.yml"
|
23
21
|
yaml_data.is_a?(Hash).should == true
|
24
22
|
end
|
25
23
|
|
data/spec/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alpaca_complete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
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:
|
12
|
+
date: 2013-01-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -101,7 +101,11 @@ files:
|
|
101
101
|
- lib/AlpacaComplete/detect.rb
|
102
102
|
- lib/AlpacaComplete/locale_complete.rb
|
103
103
|
- lib/AlpacaComplete/utils.rb
|
104
|
+
- lib/Hash.rb
|
105
|
+
- lib/Object.rb
|
106
|
+
- preview1.png
|
104
107
|
- spec/detect_spec.rb
|
108
|
+
- spec/hash_spec.rb
|
105
109
|
- spec/locale_complete_spec.rb
|
106
110
|
- spec/spec_helper.rb
|
107
111
|
- spec/supports/dict/existent.yml
|
@@ -173,7 +177,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
173
177
|
version: '0'
|
174
178
|
segments:
|
175
179
|
- 0
|
176
|
-
hash:
|
180
|
+
hash: 3735223565893724275
|
177
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
182
|
none: false
|
179
183
|
requirements:
|