milkode 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,11 @@ function replace_query_param(url, value)
8
8
  var url_s = url.split("?");
9
9
 
10
10
  if (url_s.length <= 1) {
11
- return url + "?query=" + value;
11
+ if (value.length > 0)
12
+ return url + "?query=" + value;
13
+ else
14
+ return url;
15
+
12
16
  } else {
13
17
  var params = url_s[1].split("&");
14
18
  var found_query = false;
@@ -34,3 +38,17 @@ function topic_path(id)
34
38
  document.getElementById(id).href = url;
35
39
  }
36
40
 
41
+ function repalce_package_name(url, package_name)
42
+ {
43
+ var url_s = url.split("?");
44
+ url = url_s[0].replace(/\/home(\/.*)?/, "/home/" + package_name); // home以下をパッケージ名に置き換え
45
+ return url;
46
+ }
47
+
48
+ function select_package()
49
+ {
50
+ var url = document.URL;
51
+ url = repalce_package_name(url, document.getElementById('package').value);
52
+ url = replace_query_param(url, document.searchform.query.value);
53
+ document.location = url;
54
+ }
@@ -7,10 +7,23 @@
7
7
 
8
8
  .content
9
9
  .sample-code
10
+ %h2 基本
10
11
  %ol
11
12
  %li キーワードを並べてAND検索<br>#{link('def open')}
12
13
  %li 1フレーズとして検索<br>#{link('"def open"')}
14
+
15
+ %h2 オプション
16
+ %ol
13
17
  %li パッケージ名で絞り込み<br>#{link('def open p:milkode')}
14
18
  %li ファイル名で絞り込み<br>#{link('def open f:test')}
15
19
  %li 拡張子で絞り込み<br>#{link('s:rb')}
20
+ %li ファイル名もしくはパッケージ名で絞り込み<br>#{link('fp:milkode')}
21
+ %li ファイル名、パッケージ名、もしくはファイルの内容<br>#{link('k:test')}
22
+
23
+ %h2 ダイレクトパス
24
+ %ol
25
+ %li viewモードで行番号をクリックするとダイレクトパス(現在行を表すテキスト)を表示<br><a href='/home/milkode/lib/milkode/cdstk/cdstk.rb'>/home/milkode/lib/milkode/cdstk/cdstk.rb</a>
26
+ %li ダイレクトパスで検索すると直接ジャンプ<br>#{link('/milkode/lib/milkode/cdstk/cdstk.rb:81')}
27
+ %li 空白を含むダイレクトパスは""で囲む<br>#{link('"/export-memo/2010/Tweet - 7:59"')}
28
+ %li ダイレクトパスは空白で区切って複数渡せる<br>#{link('/milkode/lib/milkode/cli.rb:41 /milkode/lib/milkode/cdstk/cdstk.rb:121')}
16
29
 
@@ -4,15 +4,15 @@
4
4
  %head
5
5
  %meta(charset='utf-8')
6
6
  %title= [@title, @setting.home_title].compact.join(' - ')
7
+ %link(rel="stylesheet" href="/css/bootstrap.min.css" type="text/css" media="all")
8
+ %link(rel="stylesheet" href="/css/bootstrap-responsive.min.css" type="text/css" media="all")
7
9
  %link(rel="stylesheet" href="/css/milkode.css" type="text/css" media="all")
8
10
  %link(rel="stylesheet" href="/css/coderay.css" type="text/css" media="all")
9
11
  %link(rel="stylesheet" href="/css/coderay-patch.css" type="text/css" media="all")
10
12
  %script(type='text/javascript' src='/js/milkode.js')
11
13
 
12
14
  %body
13
- -# %header
14
- -# %h1 <a href=".">Milkode</a>
15
-
16
- != yield
15
+ .container-fluid#mainpage
16
+ != yield
17
17
 
18
18
  -# GoogleAnalyticsを使いたい場合はここにコードを挿入して下さい。
@@ -1,23 +1,19 @@
1
- :javascript
2
- function set_pathname() {
3
- document.searchform.pathname.value = location.pathname;
4
- }
5
- %form(name="searchform" action="/search" method="post")
6
- %p
7
- %input#query(name="query" size="70" type="text"){:value => params[:query]}
8
- %input#search(type="submit" name="search" value="検索" onclick="set_pathname()")
9
- %input#clear(type="submit" name="clear" value="クリア" onclick="set_pathname()")
10
- %br
11
- %label
12
- = create_radio('all', params[:shead])
13
- 全て
14
- %label
15
- = create_radio('package', params[:shead])
16
- パッケージ(デフォルト)
17
- %label
18
- = create_radio('directory', params[:shead])
19
- ディレクトリ
20
- %label
21
- = create_checkbox('onematch', params[:onematch])
22
- = '1ファイル1マッチ'
23
- %input(name="pathname" type="hidden" value="")
1
+ .search_form
2
+ :javascript
3
+ function set_pathname() {
4
+ document.searchform.pathname.value = location.pathname;
5
+ }
6
+ %form(name="searchform" action="/search" method="post")
7
+ %p
8
+ %input#query(name="query" size="70" type="text" style="width: 419px;"){:value => params[:query]}
9
+ %input#search(type="submit" name="search" value="検索" onclick="set_pathname()")
10
+ %input#clear(type="submit" name="clear" value="クリア" onclick="set_pathname()")
11
+ %br
12
+ 範囲:
13
+ = create_select_shead(params[:shead])
14
+ パッケージ:
15
+ = create_select_package(@path)
16
+ = create_checkbox('onematch', params[:onematch], '1ファイル1マッチ')
17
+ = create_checkbox('sensitive', params[:sensitive], '大文字/小文字を区別')
18
+
19
+ %input(name="pathname" type="hidden" value="")
@@ -1,10 +1,10 @@
1
- = haml :header_menu, locals => {:flistpath => '..'}
1
+ = haml :header_menu, :locals => {:flistpath => '..'}
2
2
 
3
3
  .content
4
4
  = haml :search_form
5
5
 
6
6
  .search-summary
7
- <span class="keyword">#{topic_path(@path, params)}</span>(#{@elapsed}秒)
7
+ <span class="keyword">#{topic_path(@path, params)}</span>#{additional_info(@path, params)}(#{@elapsed}秒)
8
8
  ~ @record_content
9
9
 
10
10
 
@@ -89,7 +89,7 @@ module Milkode
89
89
  end
90
90
 
91
91
  def larger_than_oneline(content)
92
- content.count($/) > 1
92
+ content && content.count($/) > 1
93
93
  end
94
94
 
95
95
  def normalize_filename(str)
@@ -104,6 +104,14 @@ module Milkode
104
104
  str == str.downcase
105
105
  end
106
106
 
107
+ def ignore_case?(pattens, is_sensitive)
108
+ !is_sensitive && (pattens.all? {|v| Util::downcase? v})
109
+ end
110
+
111
+ def gotoline_keyword?(keyword)
112
+ keyword =~ /\A\/.*:\d+\Z/
113
+ end
114
+
107
115
  # parse_gotoline(['a', '123', 'b']) #=> [['a', 'b'], 123]]
108
116
  # parse_gotoline(['a', '123', 'b', 55]) #=> [['a', 'b', '123'], 55]]
109
117
  # parse_gotoline(['a:5']) #=> [['a'], 55]]
@@ -153,6 +161,7 @@ module Milkode
153
161
  # 'package/to/a.txt' #=> 'package', 'to/a.txt'
154
162
  # 'package' #=> 'package', nil
155
163
  def divide_shortpath(shortpath)
164
+ shortpath = shortpath[1..-1] if shortpath[0..0] == '/' # 先頭の'/'はカット
156
165
  a = shortpath.split('/')
157
166
 
158
167
  if (a.size >= 2)
@@ -165,7 +174,6 @@ module Milkode
165
174
  def git_url?(src)
166
175
  (src =~ /^(:?git[:@])|(:?ssh:)/) != nil
167
176
  end
168
-
169
177
  end
170
178
  end
171
179
 
@@ -160,6 +160,7 @@ module Milkode
160
160
  paths = options[:paths] || []
161
161
  restpaths = options[:restpaths] || []
162
162
  suffixs = options[:suffixs] || []
163
+ fpath_or_packages = options[:fpath_or_packages] || []
163
164
  offset = options[:offset] || 0
164
165
  limit = options[:limit] || -1
165
166
 
@@ -228,6 +229,17 @@ module Milkode
228
229
  end
229
230
  end
230
231
 
232
+ # ファイル名かパッケージ名
233
+ fpath_or_packages.each do |word|
234
+ sub_expression = record.restpath =~ word
235
+ sub_expression |= record.package =~ word
236
+ if expression.nil?
237
+ expression = sub_expression
238
+ else
239
+ expression &= sub_expression
240
+ end
241
+ end
242
+
231
243
  # 検索式
232
244
  expression
233
245
  end
@@ -94,7 +94,11 @@ EOF
94
94
  return
95
95
  end
96
96
 
97
- if option.packages.empty? && !my_option[:all]
97
+ # 最初の要素の先頭が'/'なら絶対パスモード
98
+ is_abs_path = my_option[:gotoline_data] && my_option[:gotoline_data].first && (my_option[:gotoline_data][0][0][0][0..0] == '/')
99
+
100
+ # 現在位置のパッケージを記録
101
+ if option.packages.empty? && !my_option[:all] && !is_abs_path
98
102
  if (package_dir_in? current_dir)
99
103
  option.filePatterns << current_dir
100
104
  else
@@ -105,8 +109,7 @@ EOF
105
109
 
106
110
  if (arguments.size > 0 || my_option[:find_mode])
107
111
  # ignore?
108
- downcase_all = arguments.all? {|v| Util::downcase? v}
109
- option.ignoreCase = true if downcase_all && !my_option[:case_sensitive]
112
+ option.ignoreCase = true if Util::ignore_case?(arguments, my_option[:case_sensitive])
110
113
 
111
114
  # update
112
115
  if my_option[:update]
@@ -132,11 +135,20 @@ EOF
132
135
  records = findGrep.pickupRecords
133
136
  # stdout.puts "#{records.size} records (#{findGrep.time_s})"
134
137
  stdout.puts "#{records.size} records"
135
- elsif (my_option[:gotoline_data])
138
+ elsif my_option[:gotoline_data]
136
139
  # gotoline mode
137
140
  basePatterns = option.filePatterns
141
+
138
142
  my_option[:gotoline_data].each do |v|
139
- option.filePatterns = basePatterns + v[0]
143
+ if is_abs_path
144
+ package, restpath = Util::divide_shortpath(v[0][0])
145
+ # p [package, restpath]
146
+ option.packages = [package]
147
+ option.filePatterns = [restpath]
148
+ else
149
+ option.filePatterns = basePatterns + v[0]
150
+ end
151
+
140
152
  option.gotoline = v[1]
141
153
  findGrep = FindGrep::FindGrep.new(arguments, option)
142
154
  findGrep.searchAndPrint(stdout)
@@ -198,11 +210,18 @@ EOF
198
210
  gsub("-k", ":k").
199
211
  gsub("-g", ":g")
200
212
  end
213
+
201
214
  end
202
215
 
203
216
  def after
217
+ if @arguments.first
218
+ if Util::gotoline_keyword? @arguments[0]
219
+ @state = :gotoline
220
+ end
221
+ end
222
+
204
223
  result = []
205
-
224
+
206
225
  @arguments.each do |v|
207
226
  case v
208
227
  when ":l"
data/milkode.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{milkode}
8
- s.version = "0.8.1"
8
+ s.version = "0.9.0"
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{2012-06-20}
12
+ s.date = %q{2012-07-09}
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"]
@@ -46,6 +46,7 @@ Gem::Specification.new do |s|
46
46
  "lib/milkode/cdweb/lib/query.rb",
47
47
  "lib/milkode/cdweb/lib/search_contents.rb",
48
48
  "lib/milkode/cdweb/lib/search_files.rb",
49
+ "lib/milkode/cdweb/lib/search_gotoline.rb",
49
50
  "lib/milkode/cdweb/lib/web_setting.rb",
50
51
  "lib/milkode/cdweb/public/css/bootstrap-responsive.min.css",
51
52
  "lib/milkode/cdweb/public/css/bootstrap.min.css",
@@ -95,6 +96,7 @@ Gem::Specification.new do |s|
95
96
  "test/data/.gitignore",
96
97
  "test/data/a_project/cdstk.rb",
97
98
  "test/data/a_project/cdstk_yaml.rb",
99
+ "test/data/a_project/empty.txt",
98
100
  "test/data/abc.zip",
99
101
  "test/data/b_project/runner.rb",
100
102
  "test/data/b_project/test_dir.rb",
@@ -116,6 +118,7 @@ Gem::Specification.new do |s|
116
118
  "test/runner.rb",
117
119
  "test/test_cdstk.rb",
118
120
  "test/test_cdstk_command.rb",
121
+ "test/test_cdweb_app.rb",
119
122
  "test/test_cli.rb",
120
123
  "test/test_cli_grep.rb",
121
124
  "test/test_coderay_wrapper.rb",
@@ -165,6 +168,7 @@ Gem::Specification.new do |s|
165
168
  s.add_runtime_dependency(%q<thor>, ["~> 0.15.0"])
166
169
  s.add_development_dependency(%q<bundler>, [">= 0"])
167
170
  s.add_development_dependency(%q<jeweler>, [">= 0"])
171
+ s.add_development_dependency(%q<rack-test>, [">= 0"])
168
172
  else
169
173
  s.add_dependency(%q<termcolor>, [">= 1.2.0"])
170
174
  s.add_dependency(%q<rroonga>, [">= 1.1.0"])
@@ -179,6 +183,7 @@ Gem::Specification.new do |s|
179
183
  s.add_dependency(%q<thor>, ["~> 0.15.0"])
180
184
  s.add_dependency(%q<bundler>, [">= 0"])
181
185
  s.add_dependency(%q<jeweler>, [">= 0"])
186
+ s.add_dependency(%q<rack-test>, [">= 0"])
182
187
  end
183
188
  else
184
189
  s.add_dependency(%q<termcolor>, [">= 1.2.0"])
@@ -194,6 +199,7 @@ Gem::Specification.new do |s|
194
199
  s.add_dependency(%q<thor>, ["~> 0.15.0"])
195
200
  s.add_dependency(%q<bundler>, [">= 0"])
196
201
  s.add_dependency(%q<jeweler>, [">= 0"])
202
+ s.add_dependency(%q<rack-test>, [">= 0"])
197
203
  end
198
204
  end
199
205
 
File without changes
@@ -0,0 +1,73 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # @file
4
+ # @brief
5
+ # @author ongaeshi
6
+ # @date 2012/06/23
7
+
8
+ require 'milkode/cdweb/app'
9
+ require 'milkode/cdweb/lib/database'
10
+ require 'test_helper'
11
+ require 'test/unit'
12
+ require 'rack/test'
13
+ require 'milkode_test_work'
14
+
15
+ class TestCdwebApp < Test::Unit::TestCase
16
+ include Rack::Test::Methods
17
+
18
+ def setup
19
+ @work = MilkodeTestWork.new({:default_db => true})
20
+ @work.add_package "db1", @work.expand_path("../data/a_project")
21
+
22
+ Database.setup(Dbdir.default_dir)
23
+ Database.instance.open_force
24
+ end
25
+
26
+ def teardown
27
+ @work.teardown
28
+ end
29
+
30
+ def app
31
+ Sinatra::Application
32
+ end
33
+
34
+ def test_main
35
+ t_default
36
+ t_home
37
+ t_help
38
+ t_not_found
39
+ t_view_empty_file
40
+ end
41
+
42
+ private
43
+
44
+ def t_default
45
+ get '/'
46
+ assert_equal 200, last_response.status
47
+ end
48
+
49
+ def t_home
50
+ get '/home'
51
+ assert_equal 200, last_response.status
52
+
53
+ get '/home', :query => 'test'
54
+ assert_equal 200, last_response.status
55
+ end
56
+
57
+ def t_help
58
+ get '/help'
59
+ assert_equal 200, last_response.status
60
+ end
61
+
62
+ def t_not_found
63
+ get '/not_found'
64
+ assert_equal 404, last_response.status
65
+ end
66
+
67
+ def t_view_empty_file
68
+ get '/home/a_project/empty.txt'
69
+ assert_equal 200, last_response.status # 空ファイルも表示出来るようにする
70
+ end
71
+ end
72
+
73
+
data/test/test_query.rb CHANGED
@@ -47,6 +47,31 @@ module Milkode
47
47
  assert_equal q.keywords, ['def update']
48
48
  end
49
49
 
50
+ def test_conv_keywords_to_fpath
51
+ q = create_query("array test s:rb")
52
+ assert_equal q.conv_keywords_to_fpath.query_string, 'f:array f:test s:rb'
53
+
54
+ q = create_query("hoge")
55
+ assert_equal q.conv_keywords_to_fpath.query_string, 'f:hoge'
56
+
57
+ q = create_query("hoge f:hoge")
58
+ assert_equal q.conv_keywords_to_fpath.query_string, 'f:hoge f:hoge'
59
+ end
60
+
61
+ def test_fp
62
+ q = create_query("key1 fp:pack fp:age")
63
+ assert_equal q.keywords, ['key1']
64
+ assert_equal q.packages, []
65
+ assert_equal q.fpaths, []
66
+ assert_equal q.suffixs, []
67
+ assert_equal q.fpath_or_packages, ['pack', 'age']
68
+ end
69
+
70
+ def test_conv_keywords_to_fpath_or_packages
71
+ q = create_query("array test s:rb")
72
+ assert_equal q.conv_keywords_to_fpath_or_packages.query_string, 'fp:array fp:test s:rb'
73
+ end
74
+
50
75
  def create_query(query)
51
76
  Query.new(query)
52
77
  end
data/test/test_util.rb CHANGED
@@ -71,6 +71,13 @@ class TestUtil < Test::Unit::TestCase
71
71
  assert !Milkode::Util::downcase?("dummyNode")
72
72
  end
73
73
 
74
+ def test_ignore_case?
75
+ assert_equal true, Milkode::Util::ignore_case?(['a', 'b'], false)
76
+ assert_equal false, Milkode::Util::ignore_case?(['a', 'b'], true)
77
+ assert_equal false, Milkode::Util::ignore_case?(['a', 'B'], false)
78
+ assert_equal false, Milkode::Util::ignore_case?(['A', 'b'], true)
79
+ end
80
+
74
81
  def test_parse_gotoline
75
82
  assert_equal [[['a', 'b'], 123]], Milkode::Util::parse_gotoline(['a', '123', 'b'])
76
83
  assert_equal [[['a', '123', 'b'], 55]], Milkode::Util::parse_gotoline(['a', '123', 'b', '55'])
@@ -78,6 +85,7 @@ class TestUtil < Test::Unit::TestCase
78
85
  assert_equal [[['a'], 55]], Milkode::Util::parse_gotoline(['a:55'])
79
86
  assert_equal [[['lib/aaa.c'], 8], [['test/bbb.rb'], 9]], Milkode::Util::parse_gotoline(['lib/aaa.c:8', 'test/bbb.rb:9'])
80
87
  assert_equal [[['c:/tmp/ccc.txt'], 99]], Milkode::Util::parse_gotoline(['c:/tmp/ccc.txt:99'])
88
+ assert_equal [[['/milkode/hoge.rb'], 99]], Milkode::Util::parse_gotoline(['/milkode/hoge.rb:99'])
81
89
  end
82
90
 
83
91
  def test_gotoline_multi?
@@ -93,6 +101,16 @@ class TestUtil < Test::Unit::TestCase
93
101
  assert_equal true, Milkode::Util::git_url?('git@github.com:ongaeshi/milkode.git')
94
102
  assert_equal true, Milkode::Util::git_url?('ssh:foo@bar/baz.git')
95
103
  end
104
+
105
+ def test_divide_shortpath
106
+ package, restpath = Milkode::Util::divide_shortpath('package/to/a.txt')
107
+ assert_equal 'package', package
108
+ assert_equal 'to/a.txt', restpath
109
+
110
+ package, restpath = Milkode::Util::divide_shortpath('/package/to/a.txt')
111
+ assert_equal 'package', package
112
+ assert_equal 'to/a.txt', restpath
113
+ end
96
114
 
97
115
 
98
116
  def teardown