milkode 0.9.8 → 0.9.9

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/Gemfile CHANGED
@@ -19,7 +19,8 @@ gem 'thor', '~> 0.15.0'
19
19
  # Add dependencies to develop your gem here.
20
20
  # Include everything needed to run rake, tests, features, etc.
21
21
  group :development do
22
- gem "bundler"
23
- gem "jeweler"
24
- gem "rack-test"
22
+ gem 'bundler'
23
+ gem 'jeweler'
24
+ gem 'rack-test'
25
+ gem 'sinatra-reloader'
25
26
  end
@@ -1,3 +1,20 @@
1
+ === 0.9.9 2013/02/26
2
+
3
+ * ワイド範囲検索のサポート
4
+ * 指定行内に複数のキーワードが含まれている場所を探す
5
+ * 複数のキーワードが一行でマッチしなかった場合、自動的に範囲を広げて再検索
6
+
7
+ * 検索オプション w: を追加
8
+ * w:7 で7行以内に全てのキーワードが含まれている場所を返す
9
+ * w:1 で今までの検索
10
+ * w:0 の時は検索範囲をファイル全域に
11
+
12
+ * Support sinatra-reloader
13
+ * export MILKODE_SINATRA_RELOADER=1
14
+
15
+ * Delete 'milkode/cdweb/app_error.rb'
16
+ * Recommend 'RACK_ENV=production'
17
+
1
18
  === 0.9.8 2013/02/27
2
19
 
3
20
  * Support MyGithub
@@ -1,3 +1,12 @@
1
+ === 0.9.9 2013/02/26
2
+
3
+ * Suppor wide range search
4
+ * Add 'w:' search option
5
+ * Support sinatra-reloader
6
+ * export MILKODE_SINATRA_RELOADER=1
7
+ * Delete 'milkode/cdweb/app_error.rb'
8
+ * Recommend 'RACK_ENV=production'
9
+
1
10
  === 0.9.8 2013/02/27
2
11
 
3
12
  * Support MyGithub
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.8
1
+ 0.9.9
data/bin/gmilk CHANGED
@@ -6,5 +6,5 @@
6
6
  require 'rubygems'
7
7
  require 'milkode/grep/cli_grep'
8
8
 
9
- Version = "0.9.8"
9
+ Version = "0.9.9"
10
10
  Milkode::CLI_Grep.execute(STDOUT, ARGV)
data/bin/milk CHANGED
@@ -6,5 +6,5 @@
6
6
  require 'rubygems'
7
7
  require 'milkode/cli'
8
8
 
9
- Version = "0.9.8"
9
+ Version = "0.9.9"
10
10
  Milkode::CLI.start(ARGV)
@@ -7,6 +7,10 @@
7
7
 
8
8
  require 'rubygems'
9
9
  require 'sinatra'
10
+ if ENV['MILKODE_SINATRA_RELOADER']
11
+ require 'sinatra/reloader'
12
+ also_reload '../../**/*.rb'
13
+ end
10
14
  require 'sass'
11
15
  require 'haml'
12
16
 
@@ -21,12 +25,20 @@ require 'milkode/common/util'
21
25
  set :haml, :format => :html5
22
26
 
23
27
  get '/' do
24
- @setting = WebSetting.new
25
- @version = "0.9.8"
26
- @package_num = Database.instance.yaml_package_num
27
- @file_num = Database.instance.totalRecords
28
- @package_list = PackageList.new(Database.instance.grndb)
29
- haml :index, :layout => false
28
+ if Database.validate?
29
+ @setting = WebSetting.new
30
+ @version = "0.9.9"
31
+
32
+ @package_num = Database.instance.yaml_package_num
33
+ @file_num = Database.instance.totalRecords
34
+ @package_list = PackageList.new(Database.instance.grndb)
35
+ haml :index, :layout => false
36
+ else
37
+ <<EOF
38
+ <h1>Setup Error!</h1>
39
+ Database Directory: #{Database.dbdir}<br>
40
+ EOF
41
+ end
30
42
  end
31
43
 
32
44
  def package_path(path)
@@ -103,12 +115,6 @@ get %r{/help} do
103
115
  haml :help
104
116
  end
105
117
 
106
- begin
107
- NO_REQUIRE_APP_ERROR
108
- rescue NameError
109
- require 'milkode/cdweb/app_error'
110
- end
111
-
112
118
  # -- helper function --
113
119
 
114
120
  helpers do
@@ -112,7 +112,8 @@ module Milkode
112
112
  end
113
113
 
114
114
  def self.select_dbdir
115
- if (Dbdir.dbdir?('.') || !Dbdir.dbdir?(Dbdir.default_dir))
115
+ # if (Dbdir.dbdir?('.') || !Dbdir.dbdir?(Dbdir.default_dir))
116
+ if Dbdir.dbdir?('.')
116
117
  '.'
117
118
  else
118
119
  Dbdir.default_dir
@@ -35,7 +35,13 @@ module Milkode
35
35
  @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html
36
36
  else
37
37
  grep = Grep.new(record.content)
38
- match_lines = grep.match_lines_and(q.keywords, is_sensitive)
38
+ match_lines = grep.match_lines_and(q.keywords, is_sensitive, q.wide_match_range)
39
+
40
+ if match_lines.empty? && q.wide_match_range_empty?
41
+ # 検索範囲を広げる
42
+ match_lines = grep.match_lines_and(q.keywords, is_sensitive, 7)
43
+ end
44
+
39
45
  @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html
40
46
  end
41
47
  else
@@ -191,6 +191,10 @@ module Milkode
191
191
  end
192
192
  result
193
193
  end
194
+
195
+ def self.validate?
196
+ YamlFileWrapper.load_if(Database.dbdir) != nil
197
+ end
194
198
 
195
199
  private
196
200
 
@@ -6,6 +6,7 @@
6
6
  # @date 2010/10/18
7
7
 
8
8
  require 'milkode/common/util'
9
+ require 'milkode/common/wide_matcher'
9
10
 
10
11
  module Milkode
11
12
  class Grep
@@ -13,23 +14,22 @@ module Milkode
13
14
  @content = content
14
15
  end
15
16
 
16
- MatchLineResult = Struct.new(:index, :match_datas)
17
+ def match_lines_stopover(patterns, max_match, start_index, is_sensitive, wide_match_range)
18
+ regexps = strs2regs(patterns, is_sensitive)
19
+ result = []
20
+ index = start_index
17
21
 
18
- def match_lines_stopover(patterns, max_match, start_index, is_sensitive)
19
- result = []
20
- patternRegexps = strs2regs(patterns, is_sensitive)
21
- index = start_index
22
-
23
- lines = @content.split($/)
22
+ matcher = WideMatcher.create(wide_match_range)
23
+ lines = @content.split($/)
24
24
 
25
25
  while (index < lines.size) do
26
26
  line = lines[index]
27
27
 
28
- match_datas = []
29
- patternRegexps.each {|v| match_datas << v.match(line)}
28
+ matcher.add_line_matchs(index, match_regexps(line, regexps))
30
29
 
31
- if (match_datas.all?)
32
- result << MatchLineResult.new(index, match_datas)
30
+ if matcher.match?
31
+ result += matcher.match_lines
32
+
33
33
  if result.size >= max_match
34
34
  index += 1
35
35
  break
@@ -40,44 +40,27 @@ module Milkode
40
40
  end
41
41
 
42
42
  index = 0 if (index >= lines.size)
43
- {:result => result, :next_line => index}
43
+ {:result => result.uniq, :next_line => index}
44
44
  end
45
45
 
46
- def match_lines_and(patterns, is_sensitive)
47
- result = []
48
- patternRegexps = strs2regs(patterns, is_sensitive)
49
- index = 0
46
+ def match_lines_and(patterns, is_sensitive, wide_match_range)
47
+ regexps = strs2regs(patterns, is_sensitive)
48
+ result = []
49
+ index = 0
50
+
51
+ matcher = WideMatcher.create(wide_match_range)
50
52
 
51
53
  @content.each_line do |line|
52
- match_datas = []
53
- patternRegexps.each {|v| match_datas << v.match(line)}
54
-
55
- if (match_datas.all?)
56
- result << MatchLineResult.new(index, match_datas)
57
- end
58
-
54
+ matcher.add_line_matchs(index, match_regexps(line, regexps))
55
+ result += matcher.match_lines if matcher.match?
59
56
  index += 1
60
57
  end
61
58
 
62
- result
59
+ result.uniq
63
60
  end
64
61
 
65
- def one_match_and(patterns, is_sensitive)
66
- patternRegexps = strs2regs(patterns, is_sensitive)
67
- index = 0
68
-
69
- @content.each_line do |line|
70
- match_datas = []
71
- patternRegexps.each {|v| match_datas << v.match(line)}
72
-
73
- if (match_datas.all?)
74
- return MatchLineResult.new(index, match_datas)
75
- end
76
-
77
- index += 1
78
- end
79
-
80
- nil
62
+ def one_match_and(patterns, is_sensitive, wide_match_range)
63
+ match_lines_stopover(patterns, 1, 0, is_sensitive, wide_match_range)
81
64
  end
82
65
 
83
66
  private
@@ -93,6 +76,10 @@ module Milkode
93
76
 
94
77
  regs
95
78
  end
79
+
80
+ def match_regexps(line, regexps)
81
+ regexps.reduce([]) {|result, v| result << v.match(line); result}
82
+ end
96
83
  end
97
84
  end
98
85
 
@@ -13,18 +13,20 @@ module Milkode
13
13
  attr_reader :query_string
14
14
 
15
15
  OPTIONS = [
16
- ['package', 'p'],
17
- ['filepath', 'fpath', 'f'],
18
- ['suffix', 's'],
19
- ['fp'], # fpath or package
20
- ['keyword', 'k'],
21
- ['gotoline', 'g'],
16
+ ['package' , 'p'],
17
+ ['filepath' , 'fpath', 'f'],
18
+ ['suffix' , 's'],
19
+ ['fp'] , # fpath or package
20
+ ['keyword' , 'k'],
21
+ ['gotoline' , 'g'],
22
+ ['wide' , 'w'],
22
23
  ]
23
24
 
24
25
  def initialize(str)
25
26
  @query_string = str
26
27
  init_hash
27
28
  parse
29
+ @wide_match_range = calc_param(6)
28
30
  end
29
31
 
30
32
  def escape_html
@@ -32,11 +34,11 @@ module Milkode
32
34
  end
33
35
 
34
36
  def empty?
35
- keywords.size == 0 && packages.size == 0 && fpaths.size == 0 && suffixs.size == 0 && fpath_or_packages.size == 0 && gotolines.size == 0
37
+ keywords.size == 0 && only_keywords
36
38
  end
37
39
 
38
40
  def only_keywords
39
- packages.size == 0 && fpaths.size == 0 && suffixs.size == 0 && fpath_or_packages.size == 0 && gotolines.size == 0
41
+ packages.size == 0 && fpaths.size == 0 && suffixs.size == 0 && fpath_or_packages.size == 0 && gotolines.size == 0 && wide_match_range_empty?
40
42
  end
41
43
 
42
44
  def keywords
@@ -68,6 +70,26 @@ module Milkode
68
70
  calc_param(5)
69
71
  end
70
72
 
73
+ def wide_match_range
74
+ a = @wide_match_range
75
+
76
+ if a.empty?
77
+ 1
78
+ else
79
+ i = a[-1].to_i
80
+
81
+ if (i == 0)
82
+ 0
83
+ else
84
+ i
85
+ end
86
+ end
87
+ end
88
+
89
+ def wide_match_range_empty?
90
+ @wide_match_range.empty?
91
+ end
92
+
71
93
  def conv_keywords_to_fpath
72
94
  s = query_string.split.map {|v|
73
95
  if keywords.include? v
@@ -118,6 +140,10 @@ module Milkode
118
140
  Query.new(s)
119
141
  end
120
142
 
143
+ def conv_wide_match_range(match_range)
144
+ Query.new(query_string + " w:#{match_range}")
145
+ end
146
+
121
147
  private
122
148
 
123
149
  def calc_param(index)
@@ -24,45 +24,59 @@ module Milkode
24
24
  MATH_FILE_DISP = 3 # マッチファイルの最大表示数
25
25
  MATH_FILE_LIMIT = MATH_FILE_DISP + 1 # マッチファイルの検索リミット数
26
26
 
27
+ DEFAULT_WIDE_MATCH_RANGE = 7 # 未指定時のワイド検索範囲
28
+
27
29
  def initialize(path, params, query)
28
- @path = path
29
- @params = params
30
- @q = query
31
- @page = params[:page].to_i || 0
32
- @offset = params[:offset].to_i
33
- @line = params[:line].to_i
34
- @is_onematch = params[:onematch] == 'on'
35
- @is_sensitive = params[:sensitive] == 'on'
30
+ @path = path
31
+ @params = params
32
+ @q = query
33
+ @page = params[:page].to_i || 0
34
+ @offset = params[:offset].to_i
35
+ @line = params[:line].to_i
36
+ @is_onematch = params[:onematch] == 'on'
37
+ @is_sensitive = params[:sensitive] == 'on'
38
+
36
39
  @searcher_fuzzy_gotoline = nil
37
40
 
38
41
  # 検索1 : クエリーそのまま
39
42
  @records, @total_records = Database.instance.search(@q.keywords, @q.multi_match_keywords, @q.packages, path, @q.fpaths, @q.suffixs, @q.fpath_or_packages, @offset, LIMIT_NUM)
40
- grep_contents(@q.keywords)
43
+ grep_contents(@q.keywords, @q.wide_match_range)
41
44
 
42
45
  # 検索2 : マッチしなかった時におすすめクエリーがある場合
43
- if @match_records.empty?
44
- if recommended_fuzzy_gotoline?
45
- # 専用の Searcher を作成
46
- @searcher_fuzzy_gotoline = SearchFuzzyGotoLine.new(@path, @params, @q)
47
-
48
- # 結果をコピーする
49
- @total_records = @searcher_fuzzy_gotoline.total_records
50
- @match_records = @searcher_fuzzy_gotoline.match_records
51
- @next_index = @searcher_fuzzy_gotoline.next_index
52
- @end_index = @searcher_fuzzy_gotoline.end_index
53
- @next_line = nil
54
-
55
- elsif recommended_fpath_or_packages?
56
- # おすすめクエリーに変換
57
- q2 = @q.conv_head_keyword_to_fpath_or_packages
58
-
59
- # 検索
60
- @records, @total_records = Database.instance.search(q2.keywords, q2.multi_match_keywords, q2.packages, path, q2.fpaths, q2.suffixs, q2.fpath_or_packages, @offset, LIMIT_NUM)
61
-
62
- # 再grep
63
- grep_contents(q2.keywords)
46
+
47
+ # gotolineモード (test_cdstk.rb:55)
48
+ if @match_records.empty? && recommended_fuzzy_gotoline?
49
+ # 専用の Searcher を作成
50
+ @searcher_fuzzy_gotoline = SearchFuzzyGotoLine.new(@path, @params, @q)
51
+
52
+ # 結果をコピーする
53
+ @total_records = @searcher_fuzzy_gotoline.total_records
54
+ @match_records = @searcher_fuzzy_gotoline.match_records
55
+ @next_index = @searcher_fuzzy_gotoline.next_index
56
+ @end_index = @searcher_fuzzy_gotoline.end_index
57
+ @next_line = nil
58
+ end
59
+
60
+ # ワイド検索範囲
61
+ if @match_records.empty? && recommended_wide_match_range?
62
+ grep_contents(@q.keywords, DEFAULT_WIDE_MATCH_RANGE)
63
+
64
+ if @match_records.empty?
65
+ grep_contents(@q.keywords, 0)
64
66
  end
65
67
  end
68
+
69
+ # 先頭をファイル名とみなす
70
+ if @match_records.empty? && recommended_fpath_or_packages?
71
+ # おすすめクエリーに変換
72
+ q2 = @q.conv_head_keyword_to_fpath_or_packages
73
+
74
+ # 検索
75
+ @records, @total_records = Database.instance.search(q2.keywords, q2.multi_match_keywords, q2.packages, path, q2.fpaths, q2.suffixs, q2.fpath_or_packages, @offset, LIMIT_NUM)
76
+
77
+ # 再grep
78
+ grep_contents(q2.keywords, q2.wide_match_range)
79
+ end
66
80
 
67
81
  # 検索3 : マッチするファイル
68
82
  @match_files = []
@@ -135,33 +149,58 @@ EOF
135
149
  @q.keywords.size == 1 && @q.only_keywords && Util::fuzzy_gotoline_keyword?(@q.keywords[0])
136
150
  end
137
151
 
152
+ def recommended_wide_match_range?
153
+ @q.keywords.size >= 2 && @q.wide_match_range_empty?
154
+ end
155
+
138
156
  def recommended_fpath_or_packages?
139
157
  @q.keywords.size >= 2 && @q.only_keywords
140
158
  end
141
159
 
142
160
  def recommended_query_contents
161
+ result = []
162
+
143
163
  if recommended_fuzzy_gotoline?
144
164
  conv_query = @q.conv_fuzzy_gotoline
145
165
  tmpp = @params.clone
146
166
  tmpp[:query] = conv_query.query_string
147
167
  url = Mkurl.new(@path, tmpp).inherit_query_shead
148
- <<EOS
149
- <dt class='result-file'>#{img_icon('document-new-4.png')}<a href='#{url}'>#{conv_query.query_string}</a></dt>
150
- <hr>
151
- EOS
152
- elsif recommended_fpath_or_packages?
168
+ result << "<dt class='result-file'>#{img_icon('document-new-4.png')}<a href='#{url}'>#{conv_query.query_string}</a></dt>"
169
+ end
170
+
171
+ if recommended_wide_match_range?
172
+ conv_query = @q.conv_wide_match_range(0)
173
+ tmpp = @params.clone
174
+ tmpp[:query] = conv_query.query_string
175
+ w0_url = Mkurl.new(@path, tmpp).inherit_query_shead
176
+
177
+ conv_query = @q.conv_wide_match_range(1)
178
+ tmpp = @params.clone
179
+ tmpp[:query] = conv_query.query_string
180
+ w1_url = Mkurl.new(@path, tmpp).inherit_query_shead
181
+
182
+ conv_query = @q.conv_wide_match_range(DEFAULT_WIDE_MATCH_RANGE)
183
+ tmpp = @params.clone
184
+ tmpp[:query] = conv_query.query_string
185
+ url = Mkurl.new(@path, tmpp).inherit_query_shead
186
+
187
+ result << "<dt class='result-file'>#{img_icon('document-new-4.png')}<a href='#{url}'>#{conv_query.query_string}</a> (<a href='#{w0_url}'>w:0</a>, <a href='#{w1_url}'>w:1</a>)</dt>"
188
+ end
189
+
190
+ if recommended_fpath_or_packages?
153
191
  conv_query = @q.conv_head_keyword_to_fpath_or_packages
154
192
  tmpp = @params.clone
155
193
  tmpp[:query] = conv_query.query_string
156
194
  url = Mkurl.new(@path, tmpp).inherit_query_shead
157
- <<EOS
158
- <dt class='result-file'>#{img_icon('document-new-4.png')}<a href='#{url}'>#{conv_query.query_string}</a></dt>
159
- <hr>
160
- EOS
195
+ result << "<dt class='result-file'>#{img_icon('document-new-4.png')}<a href='#{url}'>#{conv_query.query_string}</a></dt>"
196
+ end
197
+
198
+ unless result.empty?
199
+ result.join("\n") + "<hr>\n"
161
200
  else
162
201
  ""
163
202
  end
164
- end
203
+ end
165
204
 
166
205
  def match_files_contents
167
206
  unless @match_files.empty?
@@ -208,26 +247,15 @@ EOF
208
247
 
209
248
  MatchRecord = Struct.new(:record, :match_line)
210
249
 
211
- def grep_contents(keywords)
250
+ def grep_contents(keywords, wide_match_range)
212
251
  @match_records = []
213
252
  @end_index = @next_index = @records.size
214
253
  @next_line = nil
215
254
 
216
255
  @records.each_with_index do |record, index|
217
256
  if (Util::larger_than_oneline(record.content))
218
-
219
- if @is_onematch
220
- grep = Grep.new(record.content)
221
- match_line = grep.one_match_and(keywords, @is_sensitive)
222
- @match_records << MatchRecord.new(record, match_line) if match_line
223
-
224
- if @match_records.size >= DISP_NUM
225
- @end_index = index
226
- @next_index = index + 1
227
- break
228
- end
229
- else
230
- break if grep_match_lines_stopover(record, index, keywords)
257
+ if grep_match_lines_stopover(record, index, keywords, wide_match_range)
258
+ break
231
259
  end
232
260
  else
233
261
  @match_records << MatchRecord.new(record, Grep::MatchLineResult.new(0, nil))
@@ -241,9 +269,14 @@ EOF
241
269
  end
242
270
  end
243
271
 
244
- def grep_match_lines_stopover(record, index, keywords)
245
- grep = Grep.new(record.content)
246
- r = grep.match_lines_stopover(keywords, DISP_NUM - @match_records.size, (index == 0) ? @line : 0, @is_sensitive)
272
+ def grep_match_lines_stopover(record, index, keywords, wide_match_range)
273
+ grep = Grep.new(record.content)
274
+
275
+ if @is_onematch
276
+ r = grep.one_match_and(keywords, @is_sensitive, wide_match_range)
277
+ else
278
+ r = grep.match_lines_stopover(keywords, DISP_NUM - @match_records.size, (index == 0) ? @line : 0, @is_sensitive, wide_match_range)
279
+ end
247
280
 
248
281
  r[:result].each do |match_line|
249
282
  @match_records << MatchRecord.new(record, match_line) if match_line
@@ -170,7 +170,7 @@ EOF
170
170
  :DbDir => options[:db],
171
171
  }
172
172
  opts[:customize] = options[:customize]
173
- cdstk(opts[:DbDir]).assert_compatible
173
+ # cdstk(opts[:DbDir]).assert_compatible
174
174
  Milkode::CLI_Cdweb.execute_with_options($stdout, opts)
175
175
  end
176
176
 
@@ -0,0 +1,84 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # @file
4
+ # @brief
5
+ # @author ongaeshi
6
+ # @date 2013/03/15
7
+
8
+ module Milkode
9
+ MatchLineResult = Struct.new(:index, :match_datas)
10
+
11
+ class WideMatcher
12
+ attr_reader :num_max
13
+
14
+ def self.create(num_max)
15
+ if num_max == 0
16
+ WideMatcherZero.new
17
+ else
18
+ WideMatcher.new(num_max)
19
+ end
20
+ end
21
+
22
+ def initialize(num_max)
23
+ @num_max = num_max
24
+ @container = []
25
+ end
26
+
27
+ def linenum
28
+ @container.size
29
+ end
30
+
31
+ def add_line_matchs(index, matches)
32
+ @last_index = index
33
+ @container.shift if linenum >= @num_max
34
+ @container << matches
35
+ # p @container
36
+ end
37
+
38
+ def match?
39
+ @container.reduce(Array.new(@container.first.size)) {|result, matches|
40
+ matches.each_with_index do |m, i|
41
+ result[i] |= m
42
+ end
43
+ result
44
+ }.all?
45
+ end
46
+
47
+ def match_lines
48
+ index = @last_index - @container.size + 1
49
+ @container.reduce([]) do |result, matches|
50
+ m = matches.compact
51
+ result << MatchLineResult.new(index, m) unless m.empty?
52
+ index += 1
53
+ result
54
+ end
55
+ end
56
+ end
57
+
58
+ class WideMatcherZero
59
+ attr_reader :num_max
60
+
61
+ def initialize
62
+ @num_max = 0
63
+ end
64
+
65
+ def linenum
66
+ 1
67
+ end
68
+
69
+ def add_line_matchs(index, matches)
70
+ @index = index
71
+ @matches = matches
72
+ end
73
+
74
+ def match?
75
+ @matches.any?
76
+ end
77
+
78
+ def match_lines
79
+ [MatchLineResult.new(@index, @matches.compact)]
80
+ end
81
+ end
82
+ end
83
+
84
+
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{milkode}
8
- s.version = "0.9.8"
8
+ s.version = "0.9.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ongaeshi"]
12
- s.date = %q{2013-02-27}
12
+ s.date = %q{2013-03-26}
13
13
  s.description = %q{Line based local source code search engine & grep-command & web-app.}
14
14
  s.email = %q{ongaeshi0621@gmail.com}
15
15
  s.executables = ["gmilk", "milk"]
@@ -35,7 +35,6 @@ Gem::Specification.new do |s|
35
35
  "lib/milkode/cdstk/package.rb",
36
36
  "lib/milkode/cdstk/yaml_file_wrapper.rb",
37
37
  "lib/milkode/cdweb/app.rb",
38
- "lib/milkode/cdweb/app_error.rb",
39
38
  "lib/milkode/cdweb/cli_cdweb.rb",
40
39
  "lib/milkode/cdweb/config.ru",
41
40
  "lib/milkode/cdweb/lib/coderay_html2.rb",
@@ -117,6 +116,7 @@ Gem::Specification.new do |s|
117
116
  "lib/milkode/common/platform.rb",
118
117
  "lib/milkode/common/string_snip.rb",
119
118
  "lib/milkode/common/util.rb",
119
+ "lib/milkode/common/wide_matcher.rb",
120
120
  "lib/milkode/database/document_record.rb",
121
121
  "lib/milkode/database/document_table.rb",
122
122
  "lib/milkode/database/groonga_database.rb",
@@ -184,6 +184,7 @@ Gem::Specification.new do |s|
184
184
  "test/test_string_snip.rb",
185
185
  "test/test_updater.rb",
186
186
  "test/test_util.rb",
187
+ "test/test_wide_matcher.rb",
187
188
  "test/test_yaml_file_wrapper.rb"
188
189
  ]
189
190
  s.homepage = %q{http://github.com/ongaeshi/milkode}
@@ -211,6 +212,7 @@ Gem::Specification.new do |s|
211
212
  s.add_development_dependency(%q<bundler>, [">= 0"])
212
213
  s.add_development_dependency(%q<jeweler>, [">= 0"])
213
214
  s.add_development_dependency(%q<rack-test>, [">= 0"])
215
+ s.add_development_dependency(%q<sinatra-reloader>, [">= 0"])
214
216
  else
215
217
  s.add_dependency(%q<termcolor>, [">= 1.2.0", "< 1.2.2"])
216
218
  s.add_dependency(%q<rroonga>, [">= 1.1.0"])
@@ -226,6 +228,7 @@ Gem::Specification.new do |s|
226
228
  s.add_dependency(%q<bundler>, [">= 0"])
227
229
  s.add_dependency(%q<jeweler>, [">= 0"])
228
230
  s.add_dependency(%q<rack-test>, [">= 0"])
231
+ s.add_dependency(%q<sinatra-reloader>, [">= 0"])
229
232
  end
230
233
  else
231
234
  s.add_dependency(%q<termcolor>, [">= 1.2.0", "< 1.2.2"])
@@ -242,6 +245,7 @@ Gem::Specification.new do |s|
242
245
  s.add_dependency(%q<bundler>, [">= 0"])
243
246
  s.add_dependency(%q<jeweler>, [">= 0"])
244
247
  s.add_dependency(%q<rack-test>, [">= 0"])
248
+ s.add_dependency(%q<sinatra-reloader>, [">= 0"])
245
249
  end
246
250
  end
247
251
 
@@ -61,7 +61,7 @@ class TestCdwebApp < Test::Unit::TestCase
61
61
 
62
62
  def t_not_found
63
63
  get '/not_found'
64
- assert_equal 200, last_response.status
64
+ assert_equal 404, last_response.status
65
65
  end
66
66
 
67
67
  def t_view_empty_file
@@ -78,6 +78,20 @@ module Milkode
78
78
  assert_equal q.keywords , ['a.rb']
79
79
  end
80
80
 
81
+ def test_wide_match_range
82
+ assert_equal 1 , create_query("").wide_match_range
83
+ assert_equal true , create_query("").wide_match_range_empty?
84
+ assert_equal 1 , create_query("w:").wide_match_range
85
+ assert_equal true , create_query("w:").wide_match_range_empty?
86
+ assert_equal 1 , create_query("w:1").wide_match_range
87
+ assert_equal false , create_query("w:1").wide_match_range_empty?
88
+ assert_equal 6 , create_query("w:5 w:6").wide_match_range
89
+ assert_equal 0 , create_query("w:0").wide_match_range
90
+ assert_equal 0 , create_query("w:aaa").wide_match_range
91
+ end
92
+
93
+ private
94
+
81
95
  def create_query(query)
82
96
  Query.new(query)
83
97
  end
@@ -0,0 +1,64 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # @file
4
+ # @brief
5
+ # @author ongaeshi
6
+ # @date 2011/02/20
7
+
8
+ require 'test_helper'
9
+ require 'milkode/common/wide_matcher'
10
+
11
+ class TestWideMatcher < Test::Unit::TestCase
12
+ include Milkode
13
+
14
+ SRC = <<EOF
15
+ aaa
16
+ bbb
17
+ ccc
18
+ ddd
19
+ aaa
20
+ EOF
21
+
22
+ def test_initialize
23
+ obj = WideMatcher.create(5)
24
+ assert_equal 5, obj.num_max
25
+ assert_equal 0, obj.linenum
26
+ end
27
+
28
+ def test_add_line_matches
29
+ lines = SRC.split("\n")
30
+ regexps = strs2regs(['a', 'c'])
31
+
32
+ obj = WideMatcher.create(3)
33
+
34
+ obj.add_line_matchs( 0, match_regexps(lines[0], regexps) )
35
+ assert_equal false, obj.match?
36
+
37
+ obj.add_line_matchs( 1, match_regexps(lines[1], regexps) )
38
+ assert_equal false, obj.match?
39
+
40
+ obj.add_line_matchs( 2, match_regexps(lines[2], regexps) )
41
+ assert_equal true, obj.match?
42
+ assert_equal [0, 2], obj.match_lines.map{|v| v.index}
43
+
44
+ obj.add_line_matchs( 3, match_regexps(lines[3], regexps) )
45
+ assert_equal false, obj.match?
46
+
47
+ obj.add_line_matchs( 4, match_regexps(lines[4], regexps) )
48
+ assert_equal true, obj.match?
49
+ assert_equal [2, 4], obj.match_lines.map{|v| v.index}
50
+ end
51
+
52
+ private
53
+
54
+ def strs2regs(strs)
55
+ strs.map do |v|
56
+ Regexp.new(Regexp.escape(v))
57
+ end
58
+ end
59
+
60
+ def match_regexps(line, regexps)
61
+ regexps.map {|v| v.match(line)}
62
+ end
63
+
64
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milkode
3
3
  version: !ruby/object:Gem::Version
4
- hash: 43
4
+ hash: 41
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 8
10
- version: 0.9.8
9
+ - 9
10
+ version: 0.9.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - ongaeshi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-02-27 00:00:00 +09:00
18
+ date: 2013-03-26 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -252,6 +252,20 @@ dependencies:
252
252
  - 0
253
253
  version: "0"
254
254
  requirement: *id014
255
+ - !ruby/object:Gem::Dependency
256
+ type: :development
257
+ prerelease: false
258
+ name: sinatra-reloader
259
+ version_requirements: &id015 !ruby/object:Gem::Requirement
260
+ none: false
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ hash: 3
265
+ segments:
266
+ - 0
267
+ version: "0"
268
+ requirement: *id015
255
269
  description: Line based local source code search engine & grep-command & web-app.
256
270
  email: ongaeshi0621@gmail.com
257
271
  executables:
@@ -280,7 +294,6 @@ files:
280
294
  - lib/milkode/cdstk/package.rb
281
295
  - lib/milkode/cdstk/yaml_file_wrapper.rb
282
296
  - lib/milkode/cdweb/app.rb
283
- - lib/milkode/cdweb/app_error.rb
284
297
  - lib/milkode/cdweb/cli_cdweb.rb
285
298
  - lib/milkode/cdweb/config.ru
286
299
  - lib/milkode/cdweb/lib/coderay_html2.rb
@@ -362,6 +375,7 @@ files:
362
375
  - lib/milkode/common/platform.rb
363
376
  - lib/milkode/common/string_snip.rb
364
377
  - lib/milkode/common/util.rb
378
+ - lib/milkode/common/wide_matcher.rb
365
379
  - lib/milkode/database/document_record.rb
366
380
  - lib/milkode/database/document_table.rb
367
381
  - lib/milkode/database/groonga_database.rb
@@ -429,6 +443,7 @@ files:
429
443
  - test/test_string_snip.rb
430
444
  - test/test_updater.rb
431
445
  - test/test_util.rb
446
+ - test/test_wide_matcher.rb
432
447
  - test/test_yaml_file_wrapper.rb
433
448
  has_rdoc: true
434
449
  homepage: http://github.com/ongaeshi/milkode
@@ -1,15 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # @file
4
- # @brief
5
- # @author ongaeshi
6
- # @date 2013/02/17
7
-
8
- get '*' do
9
- @setting = WebSetting.new
10
- @path = ''
11
- haml :error
12
- end
13
-
14
-
15
-