alpaca_complete 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -10,5 +10,9 @@ group :development do
10
10
  gem "rdoc", "~> 3.12"
11
11
  gem "bundler"
12
12
  gem "jeweler", "~> 1.8.4"
13
+ end
14
+
15
+ group :test do
13
16
  gem 'simplecov'
17
+ gem 'fuubar'
14
18
  end
data/Gemfile.lock CHANGED
@@ -2,6 +2,10 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  diff-lcs (1.1.3)
5
+ fuubar (1.1.0)
6
+ rspec (~> 2.0)
7
+ rspec-instafail (~> 0.2.0)
8
+ ruby-progressbar (~> 1.0.0)
5
9
  git (1.2.5)
6
10
  jeweler (1.8.4)
7
11
  bundler (~> 1.0)
@@ -20,7 +24,9 @@ GEM
20
24
  rspec-core (2.8.0)
21
25
  rspec-expectations (2.8.0)
22
26
  diff-lcs (~> 1.1.2)
27
+ rspec-instafail (0.2.4)
23
28
  rspec-mocks (2.8.0)
29
+ ruby-progressbar (1.0.2)
24
30
  simplecov (0.6.4)
25
31
  multi_json (~> 1.0)
26
32
  simplecov-html (~> 0.5.3)
@@ -31,6 +37,7 @@ PLATFORMS
31
37
 
32
38
  DEPENDENCIES
33
39
  bundler
40
+ fuubar
34
41
  jeweler (~> 1.8.4)
35
42
  rdoc (~> 3.12)
36
43
  rspec (~> 2.8.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -1,7 +1,7 @@
1
1
  "=============================================================================
2
2
  " FILE: locale_complete.Vim
3
3
  " AUTHOR: Hiroyuki Ishii <alprhcp666@gmail.com>
4
- " Last Modified: 2012-09-26
4
+ " Last Modified: 2012-10-25
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
@@ -27,80 +27,158 @@
27
27
  let s:save_cpo = &cpo
28
28
  set cpo&vim
29
29
 
30
+ " config
31
+ ""{{{
30
32
  let s:source = {
31
33
  \ 'name' : 'locale_complete_locale',
32
34
  \ 'kind' : 'ftplugin',
33
- \ 'filetypes' : { 'ruby' : 1, 'eruby' : 1 },
35
+ \ 'filetypes' : {
36
+ \ 'ruby' : 1,
37
+ \ 'eruby' : 1,
38
+ \ 'haml' : 1,
39
+ \ 'yaml' : 1,
40
+ \ 'javascript' : 1,
41
+ \ 'coffee' : 1,
42
+ \ },
34
43
  \}
35
44
 
36
- if !exists('g:source_alpaca_rails_length')
37
- let g:source_alpaca_rails_length = 2
45
+ if !exists('g:source_locale_complete_length')
46
+ let g:source_locale_complete_length = 1
38
47
  endif
39
48
 
40
- if !exists('g:source_alpaca_rails_rank')
41
- let g:source_alpaca_rails_rank = 200
49
+ if !exists('g:source_locale_complete_rank')
50
+ let g:source_locale_complete_rank = 200
42
51
  endif
43
52
 
44
- " TODO change
45
- if !exists('g:source_alpaca_rails_bin')
53
+ if !exists('g:source_locale_complete_enable_dup')
54
+ let g:source_locale_complete_enable_dup = 1
46
55
  endif
47
56
 
57
+ if !executable('alpaca_complete')
58
+ finish
59
+ endif
60
+ "}}}
61
+
48
62
  function! s:source.initialize()
49
- call neocomplcache#set_completion_length('alpaca_rails', g:source_alpaca_rails_length)
63
+ call neocomplcache#set_completion_length('locale_complete', g:source_locale_complete_length)
50
64
  call neocomplcache#set_dictionary_helper(g:neocomplcache_source_rank,
51
- \ 'alpaca_rails', g:source_alpaca_rails_rank)
65
+ \ 'locale_complete', g:source_locale_complete_rank)
66
+
67
+ " Initialize.
68
+ let s:complete_list = {}
69
+
70
+ " Create cache directory.
71
+ if !isdirectory(neocomplcache#get_temporary_directory() . '/alpaca_complete')
72
+ call mkdir(neocomplcache#get_temporary_directory() . '/alpaca_complete')
73
+ endif
74
+
75
+ " Initialize check.
76
+ " au User Rails call s:check_recache()
77
+ autocmd BufReadPost * call s:check_recache()
52
78
  endfunction
53
79
 
54
80
  function! s:source.finalize()
55
- " TODO chaching
56
81
  endfunction
57
82
 
58
- function! s:source.get_keyword_pos(cur_text)
83
+ function! s:source.get_keyword_pos(cur_text)"{{{
84
+ " XXX vim-ref の availableみたいな機構ないのかな。
85
+ if !exists('b:rails_root')
86
+ return -1
87
+ endif
59
88
  if a:cur_text =~ '.*I18n\.t.*'
60
89
  let cur_pos = match(a:cur_text, '[a-zA-Z]\+[a-zA-Z._:]*$')
61
90
 
62
91
  return cur_pos < 0 ? -1 : cur_pos
63
92
  end
64
93
  return -1
65
- endfunction
94
+ endfunction"}}}
66
95
 
67
- function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str)
68
- " TODO caching
96
+ function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str)"{{{
69
97
  let line = a:cur_keyword_str
70
98
 
71
99
  let input_first = match(line, '[a-zA-Z._:]*$')
72
100
  let input_obj = line[input_first :]
73
101
 
74
- if input_obj ==# '' || input_obj ==# "\s"
102
+ if input_obj ==# '' || input_obj ==# "\s" || !exists('b:rails_root')
75
103
  return []
76
104
  endif
77
105
 
78
- " RoRの補完プラグインを使う
106
+ if !has_key(s:complete_list, s:get_cache_name())
107
+ let keyword_lists = neocomplcache#cache#index_load_from_cache(
108
+ \ 'alpaca_complete', s:get_cache_name())
109
+ if !empty(keyword_lists)
110
+ " Caching from cache.
111
+ let s:complete_list[s:get_cache_name()] = keyword_lists
112
+ return neocomplcache#dictionary_filter(keyword_lists, input_obj)
113
+ else
114
+ return []
115
+ endif
116
+ else
117
+ let s:complete_list[s:get_cache_name()] = keyword_lists
118
+ return neocomplcache#dictionary_filter(s:complete_list[s:get_cache_name()], input_obj)
119
+ endif
120
+ endfunction"}}}
121
+
122
+ function! s:check_recache()
123
+ if !exists('b:rails_root')| return -1 |endif
124
+
125
+ if !has_key(s:complete_list, s:get_cache_name())
126
+ call s:caching()
127
+ endif
128
+ endfunction
129
+
130
+ function! s:get_cache_name()
131
+ return "locale_" . b:rails_root . "_locale"
132
+ endfunction
133
+
134
+ function! neocomplcache#sources#locale_complete#get_cur_text()"{{{
135
+ return [line('.')]
136
+ endfunction"}}}
137
+
138
+ function! neocomplcache#sources#locale_complete#define()"{{{
139
+ return s:source
140
+ endfunction"}}}
141
+
142
+ " caching
143
+ ""{{{
144
+ function! s:caching()
145
+ " RoRの補完プラグインalpaca_completeを使う
79
146
  let mf0 = neocomplcache#system( 'alpaca_complete -l -f ' . expand("%:p") )
80
147
  let mf_list = split(mf0, '\n')
81
148
 
82
149
  let result = []
150
+ let key_str = ':key =>'
151
+ let value_str = ':value =>'
152
+ let key_len = strlen(key_str)
153
+ let value_len = strlen(key_str)
83
154
  for locale_name in mf_list
84
- let locale_setting = substitute(locale_name, '^\([a-zA-Z_]*\)\..*', '\1', 'g')
85
- let complete_pos = strlen(locale_setting) + 1
155
+ let key_end = match( locale_name, value_str) - 2 " ' :'という文字列分引く
156
+ let value_start = key_end + value_len + 2 + 2
157
+
158
+ let locale = {}
159
+ let locale.key = locale_name[key_len : key_end]
160
+ "=> ja.error.messages
161
+ let locale.type = substitute(locale.key, '^\([a-za-z_]*\)\..*', '\1', 'g')
162
+ "=> ja en
163
+ let locale.value= locale_name[value_start :]
164
+ "=> ログイン情報を入力してください
165
+
86
166
  let result = add(result, {
87
- \ "word" : locale_name[complete_pos :],
88
- \ "abbr" : locale_name[complete_pos :],
89
- \ "kind" : "[alpL]",
90
- \ "menu" : locale_setting
167
+ \ "word" : locale.key[strlen(locale.type) + 1 :],
168
+ \ "kind" : "[alpl_" . locale.type . "]",
169
+ \ "menu" : locale.value,
170
+ \ "dup" : g:source_locale_complete_enable_dup
91
171
  \})
92
172
  endfor
93
173
 
94
- return neocomplcache#keyword_filter(result, input_obj)
95
- endfunction
96
-
97
- function! neocomplcache#sources#locale_complete#define()
98
- return s:source
99
- endfunction
174
+ if empty( result )
175
+ return -1
176
+ endif
100
177
 
101
- function! neocomplcache#sources#locale_complete#get_cur_text()
102
- return [line('.')]
178
+ " caching
179
+ call neocomplcache#cache#save_cache('alpaca_complete', s:get_cache_name(), result)
103
180
  endfunction
181
+ "}}}
104
182
 
105
183
  let &cpo = s:save_cpo
106
184
  unlet s:save_cpo
@@ -47,9 +47,9 @@ endif
47
47
 
48
48
  function! s:source.initialize()
49
49
  " TODO chaching
50
- call neocomplcache#set_completion_length('yaml_complete', g:source_alpaca_rails_length)
51
- call neocomplcache#set_dictionary_helper(g:neocomplcache_source_rank,
52
- \ 'yaml_complete', g:source_yaml_complete_rank)
50
+ " call neocomplcache#set_completion_length('yaml_complete', g:source_alpaca_rails_length)
51
+ " call neocomplcache#set_dictionary_helper(g:neocomplcache_source_rank,
52
+ " \ 'yaml_complete', g:source_yaml_complete_rank)
53
53
  endfunction
54
54
 
55
55
  function! s:source.finalize()
@@ -59,14 +59,30 @@ endfunction
59
59
  function! s:source.get_keyword_pos(cur_text)
60
60
  if a:cur_text =~ '\s*[a-zA-Z._:]'
61
61
  let cur_pos = match(a:cur_text, '[a-zA-Z:_]\+[a-zA-Z._:]*$')
62
-
63
62
  return cur_pos < 0 ? -1 : cur_pos
64
63
  end
64
+
65
65
  return -1
66
66
  endfunction
67
67
 
68
+ function! s:get_rails_type()
69
+ let filepath = expand("%:p")
70
+ if filepath =~ 'models/[a-zA-Z_]\+.rb$'
71
+ return "models"
72
+ elseif filepath =~ 'views\/[a-zA-Z_]\+.rb$'
73
+ return "views"
74
+ elseif filepath =~ 'controllers\/[a-zA-Z_]\+.rb$'
75
+ return "controllers"
76
+ elseif filepath =~ 'db\/migrate\/[a-zA-Z0-9_]\+.rb$'
77
+ return "migrate"
78
+ elseif filepath =~ 'spec\/[a-zA-Z0-9_/]\+_spec.rb$'
79
+ return "rspec"
80
+ endif
81
+
82
+ return 0
83
+ endfunction
84
+
68
85
  function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str)
69
- let path = neocomplcache#system( 'alpaca_complete -d ' . expand("%:p") )
70
86
  let line = a:cur_keyword_str
71
87
 
72
88
  let input_first = match(line, '[a-zA-Z._:]*$')
@@ -76,26 +92,27 @@ function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str)
76
92
  return []
77
93
  endif
78
94
 
79
- " RoRの補完プラグインを使う
80
- let mf0 = s:get_dict_yaml(
81
- let mf_list = split(mf0, '\n')
82
- let result = []
83
- for locale_name in mf_list
84
- " s:get_locate() => ja + "."
85
- let complete_pos = strlen(s:get_locate()) + 1
86
- let result = add(result, {
87
- \ "word" : locale_name[complete_pos :],
88
- \ "abbr" : locale_name[complete_pos :],
89
- \ "kind" : "[locale]"
90
- \})
91
- endfor
92
-
93
- return neocomplcache#keyword_filter(result, input_obj)
94
- endfunction
95
-
96
- function! s:get_locate()
97
- " TODO 自動取得
98
- return 'ja'
95
+ let cmd = s:get_rails_type()
96
+
97
+ return []
98
+ " " RoRの補完プラグインを使う
99
+ " TODO alpaca_completeでyamlデータ読み込み
100
+ " webapi#json_parseでdictにする
101
+ " let = neocomplcache#system( 'alpaca_complete -d ' . expand("%:p") )
102
+ " let mf0 = s:get_dict_yaml(
103
+ " let mf_list = split(mf0, '\n')
104
+ " let result = []
105
+ " for locale_name in mf_list
106
+ " " s:get_locate() => ja + "."
107
+ " let complete_pos = strlen(s:get_locate()) + 1
108
+ " let result = add(result, {
109
+ " \ "word" : locale_name[complete_pos :],
110
+ " \ "abbr" : locale_name[complete_pos :],
111
+ " \ "kind" : "[locale]"
112
+ " \})
113
+ " endfor
114
+
115
+ " return neocomplcache#keyword_filter(result, input_obj)
99
116
  endfunction
100
117
 
101
118
  function! neocomplcache#sources#yaml_complete#define()
data/bin/alpaca_complete CHANGED
@@ -5,8 +5,8 @@ require 'AlpacaComplete'
5
5
  opt = AlpacaComplete::Utils.option_parser ARGV
6
6
  if opt[:locale] == true
7
7
  locales = AlpacaComplete::LocaleComplete.complete opt[:path], opt[:word]
8
- locales.each do |locale|
9
- puts locale
8
+ locales.each do |k, v|
9
+ puts ":key =>#{k} :value =>#{v}"
10
10
  end
11
11
  elsif opt[:dict] == true
12
12
  locales = AlpacaComplete::DictComplete.complete opt[:path], opt[:word]
@@ -0,0 +1,13 @@
1
+ migration:
2
+ methods:
3
+ -
4
+ word: create_table
5
+ arguments:
6
+ -
7
+ word: :id
8
+ arguments:
9
+ -
10
+ true,
11
+ false
12
+ valiables:
13
+ constant:
@@ -13,9 +13,10 @@ class Object
13
13
  end
14
14
 
15
15
  module AlpacaComplete
16
- Dir['./lib/**/*.rb'].each {|f| require f }
16
+ Version = "0.1.1"
17
17
 
18
18
  autoload :LocaleComplete, 'AlpacaComplete/locale_complete'
19
+ autoload :Dictionary, 'AlpacaComplete/dictionary'
19
20
  autoload :Utils, 'AlpacaComplete/utils'
20
21
  autoload :Detect, 'AlpacaComplete/detect'
21
22
  end
@@ -0,0 +1,18 @@
1
+ module AlpacaComplete::Dictionary
2
+ NEWEST_VERSION = "3.2"
3
+ DICTIONARY_PATH = 'dictionary'
4
+ extend AlpacaComplete::Utils
5
+
6
+
7
+ def self.switch_dict(type, version=NEWEST_VERSION)
8
+ case type
9
+ when "migration"
10
+ "migration_3_2_1"
11
+ end
12
+ end
13
+
14
+ def self.load_dictionary(type, version=NEWEST_VERSION)
15
+ file_name = switch_dict(type, version)
16
+ load_yaml("#{DICTIONARY_PATH}/#{file_name}.yml")
17
+ end
18
+ end
@@ -53,7 +53,7 @@ module AlpacaComplete::LocaleComplete
53
53
  opt = { "path" => path}
54
54
  comp = Regexp.new("^#{word}")
55
55
 
56
- get_locale_list( opt ).select {|v|
56
+ get_locale_hash( opt ).select {|v|
57
57
  v.match comp
58
58
  }
59
59
  end
@@ -84,8 +84,13 @@ module AlpacaComplete::LocaleComplete
84
84
  locales = Hash.new
85
85
 
86
86
  Dir.glob( "#{locale_path}/**/*.yml" ).each do |file|
87
- locale_hash = YAML::load_file( file )
88
- locales.deep_merge!(locale_hash)
87
+ begin
88
+ locale_hash = YAML::load_file( file )
89
+ locales.deep_merge!(locale_hash)
90
+ rescue
91
+ # TODO yamlにエラーがあった場合の処理
92
+
93
+ end
89
94
  end
90
95
 
91
96
  locales
@@ -62,7 +62,7 @@ module AlpacaComplete::Utils
62
62
  end
63
63
  end
64
64
 
65
- def self.load_yaml( path )
65
+ def load_yaml( path )
66
66
  return nil until File.exist?(path)
67
67
 
68
68
  YAML::load_file( path )
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe AlpacaComplete::Dictionary do
4
+ context :switch_dict do
5
+ type = AlpacaComplete::Dictionary.switch_dict("migration", "3.2")
6
+ type.should == "migration_3_2_1"
7
+ end
8
+
9
+ context :load_dictionary do
10
+ dict = AlpacaComplete::Dictionary.load_dictionary("migration", "3.2")
11
+ puts '----------------------------------------'
12
+ puts dict
13
+ end
14
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'yaml'
2
2
  require './lib/AlpacaComplete'
3
3
  require 'rspec'
4
+ require 'fuubar'
4
5
  require 'rubygems'
5
6
  require 'rspec/autorun'
6
7
 
data/spec/utils_spec.rb CHANGED
@@ -12,12 +12,14 @@ 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
- yaml_data = AlpacaComplete::Utils.load_yaml "#{yaml_dir}/non_existent.yml"
15
+ extend AlpacaComplete::Utils
16
+ yaml_data = load_yaml "#{yaml_dir}/non_existent.yml"
16
17
  yaml_data.should eql(nil)
17
18
  end
18
19
 
19
20
  it 'return hash if yaml is exist' do
20
- yaml_data = AlpacaComplete::Utils.load_yaml "#{yaml_dir}/existent.yml"
21
+ extend AlpacaComplete::Utils
22
+ yaml_data = load_yaml "#{yaml_dir}/existent.yml"
21
23
  yaml_data.is_a?(Hash).should == true
22
24
  end
23
25
 
data/spec/version_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AlpacaComplete::VERSION do
4
- it { should >= "0.0.1" }
3
+ describe AlpacaComplete::Version do
4
+ it { should == "0.1.1" }
5
5
  end
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.1
4
+ version: 0.1.2
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: 2012-10-11 00:00:00.000000000 Z
12
+ date: 2012-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -75,22 +75,6 @@ dependencies:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: 1.8.4
78
- - !ruby/object:Gem::Dependency
79
- name: simplecov
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
78
  description: rails complete for editor
95
79
  email: alprhcp666@gmail.com
96
80
  executables:
@@ -112,14 +96,16 @@ files:
112
96
  - VERSION
113
97
  - alpaca_complete.gemspec
114
98
  - autoload/neocomplcache/sources/locale_complete.vim
115
- - autoload/neocomplcache/sources/yaml_complete
99
+ - autoload/neocomplcache/sources/yaml_complete.vim
116
100
  - bin/alpaca_complete
101
+ - dictionary/migration_3_2_1.yml
117
102
  - lib/AlpacaComplete.rb
118
103
  - lib/AlpacaComplete/detect.rb
104
+ - lib/AlpacaComplete/dictionary.rb
119
105
  - lib/AlpacaComplete/locale_complete.rb
120
106
  - lib/AlpacaComplete/utils.rb
121
- - lib/AlpacaComplete/version.rb
122
107
  - spec/detect_spec.rb
108
+ - spec/dictionary_spec.rb
123
109
  - spec/locale_complete_spec.rb
124
110
  - spec/spec_helper.rb
125
111
  - spec/supports/dict/existent.yml
@@ -191,7 +177,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
177
  version: '0'
192
178
  segments:
193
179
  - 0
194
- hash: 2164592348720935884
180
+ hash: -2551976939518646737
195
181
  required_rubygems_version: !ruby/object:Gem::Requirement
196
182
  none: false
197
183
  requirements:
@@ -1,5 +0,0 @@
1
- # coding: utf-8
2
-
3
- module AlpacaComplete
4
- VERSION = "0.0.1"
5
- end