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
@@ -0,0 +1,14 @@
1
+ = haml :header_menu
2
+
3
+ .content
4
+ .info-package-content
5
+
6
+ %h1 <a href="/home">全体</a>の統計
7
+
8
+ ~ @summary_content
9
+
10
+ %h2 各パッケージ
11
+
12
+ ~ @record_content
13
+
14
+
@@ -0,0 +1,13 @@
1
+ = haml :header_menu
2
+
3
+ .content
4
+ .info-package-content
5
+ %h1 <a href="/info"><img src="/images/info-big.png"/></a> <a href="/home/#{@path}">#{@path}</a>の統計
6
+
7
+ %h2 基本情報
8
+ ~ @summary_content
9
+
10
+ %h2 言語別
11
+ ~ @plang_content
12
+
13
+
@@ -4,6 +4,7 @@
4
4
  %head
5
5
  %meta(charset='utf-8')
6
6
  %title= [@title, @setting.home_title].compact.join(' - ')
7
+ %link(rel="shortcut icon" href="#{@setting.favicon}")
7
8
  %link(rel="stylesheet" href="/css/bootstrap.min.css" type="text/css" media="all")
8
9
  %link(rel="stylesheet" href="/css/bootstrap-responsive.min.css" type="text/css" media="all")
9
10
  %link(rel="stylesheet" href="/css/milkode.css" type="text/css" media="all")
@@ -4,8 +4,12 @@
4
4
  = haml :search_form
5
5
 
6
6
  .search-summary
7
- <span class="sort-change">#{@sort_change_content}</span> <span class="total-entries">#{@total_records}</span>件(#{@elapsed}秒)
8
- .sort_change
7
+ .sort-change.ss-box
8
+ #{@sort_change_content}
9
+ .total-entries.ss-box
10
+ #{@total_records}</span>件(#{@elapsed}秒)
11
+ .ss-end
12
+
9
13
  ~ @record_content
10
14
 
11
15
 
@@ -4,11 +4,17 @@
4
4
  = haml :search_form
5
5
 
6
6
  .search-summary
7
- <span class="keyword">#{topic_path(@path, params)}</span>
8
- <span class="hit-num">#{@total_records}</span>ファイル中</span>
9
- <span class="search-range">#{@range.first} - #{@range.last}ファイルを検索</span>
10
- <span class="match-num">#{@match_num}</span>件マッチ</span>
11
- (#{@elapsed}秒)
12
- #{search_summary_hook(@path)}
13
-
7
+ .favstar.ss-box
8
+ #{favstar(@path)}
9
+ .keyword.ss-box
10
+ #{topic_path(@path, params)}
11
+ .hit-num.ss-box
12
+ #{@total_records}</span>ファイル中
13
+ .search-range.ss-box
14
+ #{@range.first} - #{@range.last}ファイルを検索
15
+ .match-num.ss-box
16
+ #{@match_num}</span>件マッチ(#{@elapsed}秒)
17
+ .search-summary-hook.ss-box
18
+ #{search_summary_hook(@path)}
19
+ .ss-end
14
20
  ~ @record_content
@@ -7,6 +7,7 @@
7
7
  %p
8
8
  %input#query(name="query" size="70" type="text" style="width: 419px;"){:value => params[:query]}
9
9
  %input#search(type="submit" name="search" value="検索" onclick="set_pathname()")
10
+ %input#newtab(type="submit" name="newtab" value="新規タブ" onclick="open_newtab(); return false;")
10
11
  %input#clear(type="submit" name="clear" value="クリア" onclick="set_pathname()")
11
12
  %br
12
13
  範囲:
@@ -15,5 +16,6 @@
15
16
  = create_select_package(@path)
16
17
  = create_checkbox('onematch', params[:onematch], '1ファイル1マッチ')
17
18
  = create_checkbox('sensitive', params[:sensitive], '大文字/小文字を区別')
19
+ = create_favorite_list(@package_list)
18
20
 
19
21
  %input(name="pathname" type="hidden" value="")
@@ -4,7 +4,15 @@
4
4
  = haml :search_form
5
5
 
6
6
  .search-summary
7
- <span class="keyword">#{topic_path(@path, params)}</span>#{additional_info(@path, params)}(#{@elapsed}秒) #{search_summary_hook(@path)}
7
+ .favstar.ss-box
8
+ #{favstar(@path)}
9
+ .keyword.ss-box
10
+ #{topic_path(@path, params)}
11
+ .additional-info.ss-box
12
+ #{additional_info(@path, params)}(#{@elapsed}秒)
13
+ .search-summary-hook.ss-box
14
+ #{search_summary_hook(@path)}
15
+ .ss-end
8
16
  ~ @record_content
9
17
 
10
18
 
@@ -144,7 +144,8 @@ EOF
144
144
  end
145
145
 
146
146
  desc "fav [package1 package2 ...]", "Add favorite"
147
- option :delete, :type => :boolean, :aliases => '-d', :desc => "Delete favorite."
147
+ option :delete , :type => :boolean, :aliases => '-d', :desc => "Delete favorite."
148
+ option :sync_yaml , :type => :boolean, :aliases => '-s', :desc => "Sync yaml with database."
148
149
  def fav(*paths)
149
150
  cdstk.fav(paths, options)
150
151
  end
@@ -208,7 +209,7 @@ EOF
208
209
 
209
210
  # デフォルトメソッドを上書きして -h を処理
210
211
  # defined in /lib/thor/invocation.rb
211
- def invoke_task(task, *args)
212
+ def invoke_command(task, *args)
212
213
  if options[:help] && task.name != 'grep'
213
214
  CLI.task_help(shell, task.name)
214
215
  elsif options[:version] && task.name == 'help'
@@ -1,11 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  require 'rubygems'
4
- require 'milkode/common/archive-zip'
5
4
  require 'fileutils'
6
5
  require 'pathname'
7
6
  require 'kconv'
8
- require 'groonga'
9
7
 
10
8
  module Milkode
11
9
  module Util
@@ -16,6 +14,8 @@ module Milkode
16
14
  # zipファイルを展開し、展開フォルダ名を返す
17
15
  # ファイルが見つからなかった時はnilを返す
18
16
  def zip_extract(filename, dst_dir)
17
+ require 'archive/zip'
18
+
19
19
  raise ZipfileNotFound unless File.exist?(filename)
20
20
 
21
21
  root_list = root_entrylist(filename)
@@ -55,6 +55,10 @@ module Milkode
55
55
  end
56
56
  end
57
57
 
58
+ def ruby20?
59
+ RUBY_VERSION >= '2.0.0'
60
+ end
61
+
58
62
  def ruby19?
59
63
  RUBY_VERSION >= '1.9.0'
60
64
  end
@@ -356,6 +356,10 @@ module Milkode
356
356
  @table.to_a
357
357
  end
358
358
 
359
+ def package_records(name)
360
+ search(:strict_packages => [name])
361
+ end
362
+
359
363
  private
360
364
 
361
365
  def load_content(filename)
@@ -97,6 +97,10 @@ module Milkode
97
97
  sorted
98
98
  end
99
99
  end
100
+
101
+ def fav?(name)
102
+ @table[name].favtime != Time.at(0)
103
+ end
100
104
  end
101
105
  end
102
106
 
@@ -1,12 +1,12 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require 'optparse'
4
- require 'milkode/findgrep/findgrep'
5
- require 'milkode/common/dbdir'
6
- require 'milkode/cdstk/cdstk'
7
- require 'milkode/cdstk/yaml_file_wrapper'
8
- require 'milkode/cdstk/package'
9
3
  require 'kconv'
4
+ require 'milkode/cdstk/package'
5
+ require 'milkode/cdstk/yaml_file_wrapper'
6
+ require 'milkode/common/dbdir'
7
+ require 'milkode/common/util'
8
+ require 'milkode/grep/findgrep_option'
9
+ require 'optparse'
10
10
 
11
11
  module Milkode
12
12
  class CLI_Grep
@@ -16,7 +16,7 @@ module Milkode
16
16
  arguments = arguments.map{|arg| Kconv.kconv(arg, Kconv::UTF8)}
17
17
  end
18
18
 
19
- option = FindGrep::FindGrep::DEFAULT_OPTION.dup
19
+ option = FindGrepOption::create_default
20
20
 
21
21
  # default option
22
22
  option.dbFile = Dbdir.groonga_path(Dbdir.default_dir)
@@ -111,10 +111,10 @@ EOF
111
111
 
112
112
  # 現在位置のパッケージを記録
113
113
  if option.packages.empty? && !my_option[:all] && !is_abs_path
114
- if (current_package)
115
- option.strict_packages << current_package.name
116
- elsif (package_dir_in? current_dir)
114
+ if package_dir_in?(current_dir)
117
115
  option.filePatterns << current_dir
116
+ elsif current_package
117
+ option.strict_packages << current_package.name
118
118
  else
119
119
  stdout.puts "fatal: Not package dir '#{current_dir}'."
120
120
  return
@@ -124,6 +124,7 @@ EOF
124
124
  if (arguments.size > 0 || my_option[:find_mode])
125
125
  # update
126
126
  if my_option[:update]
127
+ require 'milkode/cdstk/cdstk'
127
128
  cdstk = Cdstk.new(stdout, Dbdir.select_dbdir)
128
129
 
129
130
  if (my_option[:all])
@@ -139,35 +140,46 @@ EOF
139
140
  stdout.puts
140
141
  end
141
142
 
142
- if (my_option[:count])
143
- # count mode
144
- option.isSilent = true
145
- findGrep = FindGrep::FindGrep.new(arguments, option)
146
- records = findGrep.pickupRecords
147
- # stdout.puts "#{records.size} records (#{findGrep.time_s})"
148
- stdout.puts "#{records.size} records"
149
- elsif my_option[:gotoline_data]
150
- # gotoline mode
151
- basePatterns = option.filePatterns
152
-
153
- my_option[:gotoline_data].each do |v|
154
- if is_abs_path
155
- package, restpath = Util::divide_shortpath(v[0][0])
156
- # p [package, restpath]
157
- option.packages = [package]
158
- option.filePatterns = [restpath]
159
- else
160
- option.filePatterns = basePatterns + v[0]
143
+ if is_abs_path
144
+ require 'milkode/grep/fast_gotoline'
145
+
146
+ obj = FastGotoline.new(my_option[:gotoline_data], yaml_load)
147
+ obj.search_and_print(stdout)
148
+
149
+ else
150
+ require 'milkode/grep/findgrep'
151
+
152
+ if (my_option[:count])
153
+ # count mode
154
+ option.isSilent = true
155
+ findGrep = FindGrep.new(arguments, option)
156
+ records = findGrep.pickupRecords
157
+ # stdout.puts "#{records.size} records (#{findGrep.time_s})"
158
+ stdout.puts "#{records.size} records"
159
+ elsif my_option[:gotoline_data]
160
+ # gotoline mode
161
+ basePatterns = option.filePatterns
162
+
163
+ my_option[:gotoline_data].each do |v|
164
+ if is_abs_path
165
+ # @memo ここにはこないはず
166
+ package, restpath = Util::divide_shortpath(v[0][0])
167
+ # p [package, restpath]
168
+ option.packages = [package]
169
+ option.filePatterns = [restpath]
170
+ else
171
+ option.filePatterns = basePatterns + v[0]
172
+ end
173
+
174
+ option.gotoline = v[1]
175
+ findGrep = FindGrep.new(arguments, option)
176
+ findGrep.searchAndPrint(stdout)
161
177
  end
162
-
163
- option.gotoline = v[1]
164
- findGrep = FindGrep::FindGrep.new(arguments, option)
178
+ else
179
+ # search mode
180
+ findGrep = FindGrep.new(arguments, option)
165
181
  findGrep.searchAndPrint(stdout)
166
182
  end
167
- else
168
- # search mode
169
- findGrep = FindGrep::FindGrep.new(arguments, option)
170
- findGrep.searchAndPrint(stdout)
171
183
  end
172
184
  else
173
185
  stdout.print opt.help
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # @file
4
+ # @brief
5
+ # @author ongaeshi
6
+ # @date 2013/05/03
7
+
8
+ require 'milkode/common/util'
9
+
10
+ module Milkode
11
+ class FastGotoline
12
+ def initialize(gotolines, yaml)
13
+ @gotolines = gotolines
14
+ @yaml = yaml
15
+ end
16
+
17
+ def search_and_print(stdout)
18
+ @gotolines.each do |gotoline|
19
+ package_name, restpath = Util::divide_shortpath(gotoline[0][0])
20
+ package = @yaml.find_name(package_name)
21
+
22
+ if package
23
+ path = File.join(package.directory, restpath)
24
+ relative_path = Util::relative_path(path, Dir.pwd).to_s
25
+ lineno = gotoline[1]
26
+ content = get_text_lineno(path, lineno)
27
+
28
+ if content
29
+ stdout.puts "#{relative_path}:#{lineno} #{content}"
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ def get_text_lineno(path, no)
36
+ index = no - 1
37
+
38
+ begin
39
+ open(path, "r") do |file|
40
+ file.each_with_index do |line, i|
41
+ return line.chomp if i == index
42
+ end
43
+ end
44
+ rescue Errno::ENOENT
45
+ # ファイルが見つからない時もnilを返す
46
+ end
47
+
48
+ nil
49
+ end
50
+
51
+ end
52
+ end
53
+
@@ -1,8 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
+
2
3
  require 'find'
3
- require 'milkode/findgrep/result'
4
4
  require 'rubygems'
5
- require 'termcolor'
5
+ # require 'termcolor'
6
6
  require 'kconv'
7
7
  require 'milkode/common/platform'
8
8
  require 'milkode/common/grenfiletest'
@@ -13,59 +13,44 @@ require 'cgi'
13
13
  require 'pathname'
14
14
  require 'milkode/database/groonga_database'
15
15
 
16
- module FindGrep
16
+ module Milkode
17
17
  class FindGrep
18
- Option = Struct.new(:patternsNot,
19
- :patternsOr,
20
- :directory,
21
- :depth,
22
- :ignoreCase,
23
- :caseSensitive,
24
- :colorHighlight,
25
- :isSilent,
26
- :debugMode,
27
- :packages,
28
- :strict_packages,
29
- :filePatterns,
30
- :suffixs,
31
- :ignoreFiles,
32
- :ignoreDirs,
33
- :kcode,
34
- :noSnip,
35
- :dbFile,
36
- :groongaOnly,
37
- :isMatchFile,
38
- :dispHtml,
39
- :matchCountLimit,
40
- :keywords,
41
- :gotoline)
42
-
43
- DEFAULT_OPTION = Option.new([],
44
- [],
45
- ".",
46
- -1,
47
- false,
48
- false,
49
- false,
50
- false,
51
- false,
52
- [],
53
- [],
54
- [],
55
- [],
56
- [],
57
- [],
58
- # Platform.get_shell_kcode,
59
- Kconv::UTF8,
60
- false,
61
- nil,
62
- false,
63
- false,
64
- false,
65
- -1,
66
- [],
67
- -1)
68
-
18
+ class Result
19
+ attr_accessor :count
20
+ attr_accessor :search_count
21
+ attr_accessor :match_file_count
22
+ attr_accessor :match_count
23
+ attr_accessor :size
24
+ attr_accessor :search_size
25
+
26
+ attr_accessor :search_files
27
+ attr_accessor :match_files
28
+ attr_accessor :unreadable_files
29
+ attr_accessor :prune_dirs
30
+ attr_accessor :ignore_files
31
+
32
+ def initialize(start_dir)
33
+ @start_dir = File.expand_path(start_dir)
34
+ @count, @search_count, @match_file_count, @match_count, @size, @search_size = 0, 0, 0, 0, 0, 0
35
+ @start_time = Time.now
36
+ @search_files, @match_files, @unreadable_files, @prune_dirs, @ignore_files = [], [], [], [], []
37
+ end
38
+
39
+ def time_stop
40
+ @end_time = Time.now
41
+ end
42
+
43
+ def time
44
+ @end_time - @start_time
45
+ end
46
+
47
+ def print(stdout)
48
+ stdout.puts "dir : #{@start_dir} (#{Gren::Util::time_s(time)})"
49
+ stdout.puts "files : #{@search_count} in #{@count} (#{Gren::Util::size_s(@search_size)} in #{Gren::Util::size_s(@size)})"
50
+ stdout.puts "match : #{@match_file_count} files, #{match_count} hit"
51
+ end
52
+ end
53
+
69
54
  class MatchCountOverError < RuntimeError ; end
70
55
 
71
56
  attr_reader :documents
@@ -80,7 +65,8 @@ module FindGrep
80
65
  @ignoreFiles = strs2regs_simple(option.ignoreFiles)
81
66
  @ignoreDirs = strs2regs_simple(option.ignoreDirs)
82
67
  @result = Result.new(option.directory)
83
- open_database if (@option.dbFile)
68
+ open_database if @option.dbFile
69
+ require 'termcolor' if @option.colorHighlight
84
70
  end
85
71
 
86
72
  def open_database()
@@ -90,7 +76,7 @@ module FindGrep
90
76
  # データベース開く
91
77
  if dbfile.exist?
92
78
  if !@grndb || @grndb.closed?
93
- @grndb = GroongaDatabase.new
79
+ @grndb = Milkode::GroongaDatabase.new
94
80
  @grndb.open_file(dbfile.to_s)
95
81
  @documents = @grndb.documents
96
82
  puts "open : #{dbfile.to_s} open." unless @option.isSilent