milkode 0.9.9 → 0.9.9.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.travis.yml +2 -1
  2. data/Gemfile +12 -11
  3. data/HISTORY.ja.rdoc +41 -1
  4. data/HISTORY.rdoc +28 -1
  5. data/VERSION +1 -1
  6. data/bin/gmilk +1 -1
  7. data/bin/milk +1 -1
  8. data/lib/milkode/cdstk/cdstk.rb +15 -1
  9. data/lib/milkode/cdstk/package.rb +16 -0
  10. data/lib/milkode/cdweb/app.rb +72 -9
  11. data/lib/milkode/cdweb/cli_cdweb.rb +25 -55
  12. data/lib/milkode/cdweb/lib/database.rb +14 -0
  13. data/lib/milkode/cdweb/lib/info_home.rb +30 -0
  14. data/lib/milkode/cdweb/lib/info_package.rb +83 -0
  15. data/lib/milkode/cdweb/lib/package_list.rb +18 -0
  16. data/lib/milkode/cdweb/public/css/milkode.css +93 -8
  17. data/lib/milkode/cdweb/public/images/info-big.png +0 -0
  18. data/lib/milkode/cdweb/public/images/info.png +0 -0
  19. data/lib/milkode/cdweb/public/images/milkode-directpath-copy.gif +0 -0
  20. data/lib/milkode/cdweb/public/images/milkode-star.png +0 -0
  21. data/lib/milkode/cdweb/public/js/milkode.js +35 -5
  22. data/lib/milkode/cdweb/views/filelist.haml +9 -1
  23. data/lib/milkode/cdweb/views/header_menu.haml +1 -1
  24. data/lib/milkode/cdweb/views/help.haml +70 -23
  25. data/lib/milkode/cdweb/views/info_home.haml +14 -0
  26. data/lib/milkode/cdweb/views/info_package.haml +13 -0
  27. data/lib/milkode/cdweb/views/layout.haml +1 -0
  28. data/lib/milkode/cdweb/views/packages.haml +6 -2
  29. data/lib/milkode/cdweb/views/search.haml +13 -7
  30. data/lib/milkode/cdweb/views/search_form.haml +2 -0
  31. data/lib/milkode/cdweb/views/view.haml +9 -1
  32. data/lib/milkode/cli.rb +3 -2
  33. data/lib/milkode/common/util.rb +6 -2
  34. data/lib/milkode/database/document_table.rb +4 -0
  35. data/lib/milkode/database/package_table.rb +4 -0
  36. data/lib/milkode/grep/cli_grep.rb +48 -36
  37. data/lib/milkode/grep/fast_gotoline.rb +53 -0
  38. data/lib/milkode/{findgrep → grep}/findgrep.rb +42 -56
  39. data/lib/milkode/grep/findgrep_option.rb +63 -0
  40. data/milkode.gemspec +22 -11
  41. data/test/test_cli.rb +3 -1
  42. data/test/test_cli_grep.rb +1 -1
  43. data/test/test_findgrep.rb +2 -2
  44. data/test/test_milkode_yaml.rb +48 -4
  45. data/test/test_query.rb +2 -0
  46. metadata +39 -22
  47. data/lib/milkode/common/archive-zip.rb +0 -10
  48. data/lib/milkode/findgrep/result.rb +0 -43
@@ -120,6 +120,11 @@ module Milkode
120
120
  @documents.size
121
121
  end
122
122
 
123
+ # 指定パッケージに属する全てのレコードを得る
124
+ def package_records(name)
125
+ @documents.package_records(name)
126
+ end
127
+
123
128
  # yamlからパッケージの総数を得る
124
129
  # @todo PackageTableから取得するように変更する
125
130
  def yaml_package_num
@@ -178,6 +183,15 @@ module Milkode
178
183
  @grndb.packages.touch_if(package, :viewtime) if package
179
184
  end
180
185
 
186
+ def fav?(name)
187
+ @grndb.packages.fav?(name)
188
+ end
189
+
190
+ def set_fav(name, favorited)
191
+ time = favorited ? Time.now : Time.at(0)
192
+ @grndb.packages.touch_if(name, :favtime, time)
193
+ end
194
+
181
195
  def update(name)
182
196
  result = Updater::ResultAccumulator.new
183
197
  result << update_in(yaml_load.find_name(name))
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # @file
4
+ # @brief
5
+ # @author ongaeshi
6
+ # @date 2013/05/04
7
+
8
+ module Milkode
9
+ class InfoHome
10
+ attr_reader :record_content
11
+ attr_reader :summary_content
12
+
13
+ def initialize
14
+ packages = Database.instance.packages(nil)
15
+
16
+ @summary_content = <<EOF
17
+ <table class="table-striped table-bordered table-condensed">
18
+ <tr><td>パッケージ数</td><td align="right">#{packages.size}</td></tr>
19
+ <tr><td>ファイル数</td><td align="right">#{Database.instance.totalRecords}</td></tr>
20
+ </table>
21
+ EOF
22
+
23
+ @record_content = packages.map do |name|
24
+ "<dt class='result-file'><img src='/images/info.png' /><a href='/info/#{name}'>#{name}</a></dt>"
25
+ end.join("\n")
26
+ end
27
+
28
+ end
29
+ end
30
+
@@ -0,0 +1,83 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # @file
4
+ # @brief
5
+ # @author ongaeshi
6
+ # @date 2013/05/04
7
+
8
+ require 'milkode/cdweb/lib/database'
9
+ require 'milkode/common/plang_detector'
10
+
11
+ module Milkode
12
+ class InfoPackage
13
+ attr_reader :summary_content
14
+ attr_reader :plang_content
15
+
16
+ def initialize(name)
17
+ records = Database.instance.package_records(name)
18
+ # plangs = sorted_plangs(records)
19
+
20
+ @summary_content = <<EOF
21
+ <table class="table-striped table-bordered table-condensed">
22
+ <tr><td>ファイル数</td><td align="right">#{records.size}</td></tr>
23
+ <tr><td>行数</td><td align="right">#{line_count_total(records)}</td></tr>
24
+ </table>
25
+ EOF
26
+
27
+ @plang_content = <<EOF
28
+ <table class="table-striped table-bordered table-condensed">
29
+ #{breakdown_detail(records)}
30
+ </table>
31
+ EOF
32
+ end
33
+
34
+ def line_count_total(records)
35
+ records.reduce(0) do |total, record|
36
+ begin
37
+ unless record.content.nil?
38
+ total + record.content.count($/) + 1
39
+ else
40
+ total
41
+ end
42
+ rescue ArgumentError
43
+ # warning_alert("invalid byte sequence : #{record.path}")
44
+ total
45
+ end
46
+ end
47
+ end
48
+
49
+ def breakdown_detail(records)
50
+ sorted_plangs(records).map {|name, count|
51
+ percent = (count.to_f / records.size * 100).to_i
52
+ "<tr><td>#{name}</td><td align=\"right\">#{count}</td><td align=\"right\">#{percent}%</td></tr>"
53
+ }.join("\n")
54
+ end
55
+
56
+ def sorted_plangs(records)
57
+ total = {}
58
+
59
+ records.each do |record|
60
+ lang = PlangDetector.new(record.restpath)
61
+
62
+ if total[lang.name]
63
+ total[lang.name] += 1
64
+ else
65
+ total[lang.name] = 1
66
+ end
67
+ end
68
+
69
+ total.map {|name, count|
70
+ [name, count]
71
+ }.sort {|a, b|
72
+ if (a[0] == PlangDetector::UNKNOWN)
73
+ -1
74
+ elsif (b[0] == PlangDetector::UNKNOWN)
75
+ 1
76
+ else
77
+ a[1] <=> b[1]
78
+ end
79
+ }.reverse
80
+ end
81
+ end
82
+ end
83
+
@@ -13,6 +13,8 @@ module Milkode
13
13
  ADD_NUM = 5
14
14
  UPDATE_NUM = 5
15
15
  FAV_NUM = 7
16
+
17
+ FAVORITE_LIST_NUM = 7
16
18
 
17
19
  def initialize(grndb)
18
20
  @grndb = grndb
@@ -41,6 +43,22 @@ module Milkode
41
43
  top_list(a[0...FAV_NUM], 'favtime')
42
44
  end
43
45
 
46
+ def favorite_list(params)
47
+ names = @grndb.packages.favs.map{|r| r.name}[0..FAVORITE_LIST_NUM-1]
48
+
49
+ list = names.map_with_index {|v, index|
50
+ "<strong><a id='favorite_list_#{index}' href='#{Mkurl.new('/home/' + v, params).inherit_query_shead}' onclick='topic_path(\"favorite_list_#{index}\");'>#{v}</a></strong>"
51
+ }.join("&nbsp;&nbsp;\n")
52
+
53
+ <<EOF
54
+ #{list}&nbsp;&nbsp;
55
+ <a href="/home?sort=favtime">...</a>
56
+ EOF
57
+ end
58
+
59
+ # ------------------------------------------------------
60
+ private
61
+
44
62
  def grndb_list(column_name, num)
45
63
  a = @grndb.packages.sort(column_name).map {|r| r.name}
46
64
  top_list(a[0...num], column_name)
@@ -7,6 +7,8 @@ div.header {
7
7
  div.footer {
8
8
  }
9
9
 
10
+ /* search-summary */
11
+
10
12
  div.search-summary {
11
13
  /* border-color: #e92926; */
12
14
  /* background-color:#FFF0F0; */
@@ -23,6 +25,21 @@ div.search-summary {
23
25
  padding-left:5px;
24
26
  }
25
27
 
28
+ .search-summary .keyword {
29
+ font-weight: bold;
30
+ }
31
+
32
+ .search-summary .ss-box {
33
+ float: left;
34
+ margin-right: 5px;
35
+ }
36
+
37
+ .search-summary .ss-end {
38
+ clear: both;
39
+ }
40
+
41
+ /* result */
42
+
26
43
  dt.result-record {
27
44
  font-size: 105%;
28
45
  }
@@ -62,11 +79,7 @@ pre.lines {
62
79
  padding-bottom: 5px;
63
80
  }
64
81
 
65
- span.keyword {
66
- font-weight: bold;
67
- }
68
-
69
- span.sort-change {
82
+ .sort-change {
70
83
  font-weight: bold;
71
84
  margin-right: 10px;
72
85
  }
@@ -88,13 +101,22 @@ input#query {
88
101
  input#search {
89
102
  margin-left: 10px;
90
103
  width: 80px;
104
+ height: 36px;
91
105
  font-size: 20px;
92
106
  }
93
107
 
108
+ input#newtab {
109
+ margin-left: 0px;
110
+ width: 60px;
111
+ height: 32px;
112
+ font-size: 12px;
113
+ }
114
+
94
115
  input#clear {
95
116
  margin-left: 0px;
96
- width: 80px;
97
- font-size: 18px;
117
+ width: 60px;
118
+ height: 32px;
119
+ font-size: 12px;
98
120
  }
99
121
 
100
122
  ul.unstyled_margin {
@@ -170,8 +192,56 @@ label.ui-corner-all {
170
192
 
171
193
  /* mainpage - help */
172
194
 
173
- #mainpage .sample-code {
195
+ #mainpage .help-content {
196
+ margin-top: 20px;
197
+ }
198
+
199
+ #mainpage .help-content h1 {
200
+ margin-top: 30px;
201
+ margin-bottom: 15px;
202
+ }
203
+
204
+ #mainpage .help-content h2 {
205
+ margin-top: 30px;
206
+ margin-bottom: 15px;
207
+ }
208
+
209
+ #mainpage .help-content ul li {
210
+ list-style: none;
211
+ margin-top: 10px;
212
+ margin-bottom: 10px;
213
+ }
214
+
215
+ #mainpage .help-content p {
216
+ font-size: 108%;
217
+ margin-left: 10px;
218
+ }
219
+
220
+ #mainpage .help-content img {
221
+ margin-left: 10px;
222
+ }
223
+
224
+ #mainpage .help-content pre {
225
+ margin-left: 10px;
226
+ }
227
+
228
+ #mainpage .help-content .comment {
229
+ color: #008E1D;
230
+ }
231
+
232
+ /* mainpage - info_package */
233
+
234
+ #mainpage .info-package-content {
235
+ margin-top: 25px;
236
+ }
237
+
238
+ #mainpage .info-package-content h1 {
239
+ margin-bottom: 15px;
240
+ }
241
+
242
+ #mainpage .info-package-content h2 {
174
243
  margin-top: 20px;
244
+ margin-bottom: 10px;
175
245
  }
176
246
 
177
247
  /* lineno-modal */
@@ -179,3 +249,18 @@ label.ui-corner-all {
179
249
  #lineno-copyall {
180
250
  font-size: 13px;
181
251
  }
252
+
253
+ /* star */
254
+
255
+ .star {
256
+ text-indent: -5000px;
257
+ display: block;
258
+ background: transparent url(/images/milkode-star.png) 20px;
259
+ height: 20px;
260
+ width: 20px;
261
+ }
262
+
263
+ .star.favorited {
264
+ background-position: 0px;
265
+ }
266
+
@@ -15,7 +15,7 @@ function replace_query_param(url, value) {
15
15
  return url + "?query=" + value;
16
16
  else
17
17
  return url;
18
-
18
+
19
19
  } else {
20
20
  var params = url_s[1].split("&");
21
21
  var found_query = false;
@@ -69,6 +69,12 @@ function select_package_home() {
69
69
  document.location = url + "/home/" + name;
70
70
  }
71
71
 
72
+ function favorite_list(id) {
73
+ var url = document.getElementById(id).href;
74
+ url = replace_query_param(url, document.searchform.query.value);
75
+ document.getElementById(id).href = url;
76
+ }
77
+
72
78
  function update_package(package_name) {
73
79
  // click button
74
80
  $("#updateModal .modal-body").html("<h4>更新中... <img src='/images/waiting.gif'/></h4>");
@@ -90,7 +96,7 @@ function update_package(package_name) {
90
96
  }
91
97
 
92
98
  function clippy_text(text, bgcolor) {
93
- return ' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' +
99
+ return ' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' +
94
100
  ' width="110"' +
95
101
  ' height="14"' +
96
102
  ' id="clippy" >' +
@@ -136,6 +142,10 @@ function lineno_setup(path, lineno) {
136
142
  $("#lineno-copyall").html("Lineno + Text" + clippy_text(directpath + " " + escapeHTML(n_lineno_dom.text()), '#F5F5F5'));
137
143
  }
138
144
 
145
+ function open_newtab() {
146
+ window.open(replace_query_param(document.URL, document.searchform.query.value));
147
+ }
148
+
139
149
  $(document).ready(function() {
140
150
  $("select#package").multiselect({
141
151
  multiple: false,
@@ -170,7 +180,27 @@ $(document).ready(function() {
170
180
  $('#shead').change(function(){
171
181
  $('#search').click();
172
182
  });
173
- });
174
-
175
-
176
183
 
184
+ $('.star').click(function() {
185
+ // 星の表示を切り替え
186
+ $(this).toggleClass('favorited');
187
+ var isFavorited = $(this).hasClass('favorited');
188
+
189
+ // パッケージ名を取得
190
+ var pname = $(this).attr('milkode-package-name');
191
+
192
+ // ajax通信
193
+ $.post(
194
+ '/command',
195
+ {
196
+ kind: 'favorite',
197
+ name: pname,
198
+ favorited: isFavorited
199
+ },
200
+ function(data) {
201
+ // @todo お気に入り一覧を更新
202
+ $(".favorite_list").html(data);
203
+ }
204
+ );
205
+ });
206
+ });
@@ -4,7 +4,15 @@
4
4
  = haml :search_form
5
5
 
6
6
  .search-summary
7
- <span class="keyword">#{topic_path(@path, params)}</span> <span class="total-entries">#{@total_records}</span>件(#{@elapsed}秒) #{search_summary_hook(@path)}
7
+ .favstar.ss-box
8
+ #{favstar(@path)}
9
+ .keyword.ss-box
10
+ #{topic_path(@path, params)}
11
+ .total-entries.ss-box
12
+ #{@total_records}件(#{@elapsed}秒)
13
+ .search-summary-hook.ss-box
14
+ #{search_summary_hook(@path)}
15
+ .ss-end
8
16
  ~ @record_content
9
17
 
10
18
 
@@ -1,5 +1,5 @@
1
1
  .header
2
2
  %h1
3
3
  <a href="/"><img src=#{@setting.header_icon} alt="milkode-icon-mini" border="0" height="75px"/></a>
4
- #{@setting.header_title}
4
+ #{@setting.header_title} &nbsp;
5
5
  = create_headmenu(@path, params, defined?(flistpath) ? flistpath : '')
@@ -1,29 +1,76 @@
1
- - @title = 'help'
2
-
3
- .header
4
- %h1
5
- <a href="/"><img src=#{@setting.header_icon} alt="milkode-icon-mini" border="0" height="75px"/></a>
6
- #{@title} - #{@setting.header_title}
1
+ = haml :header_menu
7
2
 
8
3
  .content
9
- .sample-code
10
- %h2 基本
4
+ .help-content
5
+ %h1 ヘルプ
6
+
11
7
  %ol
12
- %li キーワードを並べてAND検索<br>#{link('def open')}
13
- %li 1フレーズとして検索<br>#{link('"def open"')}
8
+ %li <a href="#search">検索</a>
9
+ %li <a href="#refine">絞り込みオプション</a>
10
+ %li <a href="#directpath">ダイレクトパス</a>
11
+
12
+ %h2#search 検索
13
+ %ul
14
+ %li キーワードを並べてAND検索
15
+
16
+ %pre
17
+ :preserve
18
+ def open
19
+
20
+ %li 1フレーズとして検索
21
+ %pre
22
+ :preserve
23
+ "def open"
14
24
 
15
- %h2 オプション
16
- %ol
17
- %li パッケージ名で絞り込み<br>#{link('def open p:milkode')}
18
- %li ファイル名で絞り込み<br>#{link('def open f:test')}
19
- %li 拡張子で絞り込み<br>#{link('s:rb')}
20
- %li ファイル名もしくはパッケージ名で絞り込み<br>#{link('fp:milkode')}
21
- %li ファイル名、パッケージ名、もしくはファイルの内容<br>#{link('k:test')}
25
+ %h2#refine 絞り込みオプション
26
+ %p
27
+ 検索キーワードと組み合わせて使う
22
28
 
23
- %h2 ダイレクトパス
24
- %ol
25
- %li viewモードで行番号をクリックするとダイレクトパス(現在行を表すテキスト)を表示
26
- %li ダイレクトパスで検索すると直接ジャンプ<br>#{link('/milkode/lib/milkode/cdstk/cdstk.rb:81')}
27
- %li 空白を含むダイレクトパスは""で囲む<br>#{link('"/path/a to text/dir:3"')}
28
- %li ダイレクトパスは空白で区切って複数渡せる<br>#{link('/milkode/lib/milkode/cli.rb:41 /milkode/lib/milkode/cdstk/cdstk.rb:121')}
29
+ %ul
30
+ %li パッケージ名で絞り込み
31
+ %pre
32
+ :preserve
33
+ p:milkode
34
+
35
+ %li ファイル名で絞り込み
36
+ %pre
37
+ :preserve
38
+ f:test
29
39
 
40
+ %li 拡張子で絞り込み
41
+ %pre
42
+ :preserve
43
+ s:rb
44
+
45
+ %li ファイル名もしくはパッケージ名で絞り込み
46
+ %pre
47
+ :preserve
48
+ fp:milkode
49
+
50
+ %li ファイル名、パッケージ名、もしくはファイルの内容
51
+ %pre
52
+ :preserve
53
+ k:test
54
+
55
+ %li 検索範囲を複数行に広げる
56
+ %pre
57
+ :preserve
58
+ w:7 read write <span class="comment"># 7行以内に'read'と'write'が含まれる箇所</span>
59
+ w:0 read write <span class="comment"># 'w:0'ならファイル内全て</span>
60
+
61
+ %h2#directpath ダイレクトパス
62
+ %p
63
+ Milkodeにおける<strong>"絶対パス"</strong>に相当するもの
64
+
65
+ %ul
66
+ %li ダイレクトパスで検索すると直接ジャンプ
67
+ %pre
68
+ :preserve
69
+ /proj/a/file.rb:81 <span class="comment"># /パッケージ名/ファイル名:行番号</span>
70
+ "/proj/a file.rb:3" <span class="comment"># 空白を含むダイレクトパスは""で囲む</span>
71
+ /proj1/file.rb:1 /proj2/file.c:2 <span class="comment"># 空白で区切れば複数個渡せる</span>
72
+
73
+ %li ファイルモードで行番号をクリックすると取得可能
74
+ <img src="/images/milkode-directpath-copy.gif" />
75
+
76
+ %li <a href="https://github.com/ongaeshi/emacs-milkode">emacs-milkode</a>との連携にも使う