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.
- data/.travis.yml +2 -1
- data/Gemfile +12 -11
- data/HISTORY.ja.rdoc +41 -1
- data/HISTORY.rdoc +28 -1
- data/VERSION +1 -1
- data/bin/gmilk +1 -1
- data/bin/milk +1 -1
- data/lib/milkode/cdstk/cdstk.rb +15 -1
- data/lib/milkode/cdstk/package.rb +16 -0
- data/lib/milkode/cdweb/app.rb +72 -9
- data/lib/milkode/cdweb/cli_cdweb.rb +25 -55
- data/lib/milkode/cdweb/lib/database.rb +14 -0
- data/lib/milkode/cdweb/lib/info_home.rb +30 -0
- data/lib/milkode/cdweb/lib/info_package.rb +83 -0
- data/lib/milkode/cdweb/lib/package_list.rb +18 -0
- data/lib/milkode/cdweb/public/css/milkode.css +93 -8
- data/lib/milkode/cdweb/public/images/info-big.png +0 -0
- data/lib/milkode/cdweb/public/images/info.png +0 -0
- data/lib/milkode/cdweb/public/images/milkode-directpath-copy.gif +0 -0
- data/lib/milkode/cdweb/public/images/milkode-star.png +0 -0
- data/lib/milkode/cdweb/public/js/milkode.js +35 -5
- data/lib/milkode/cdweb/views/filelist.haml +9 -1
- data/lib/milkode/cdweb/views/header_menu.haml +1 -1
- data/lib/milkode/cdweb/views/help.haml +70 -23
- data/lib/milkode/cdweb/views/info_home.haml +14 -0
- data/lib/milkode/cdweb/views/info_package.haml +13 -0
- data/lib/milkode/cdweb/views/layout.haml +1 -0
- data/lib/milkode/cdweb/views/packages.haml +6 -2
- data/lib/milkode/cdweb/views/search.haml +13 -7
- data/lib/milkode/cdweb/views/search_form.haml +2 -0
- data/lib/milkode/cdweb/views/view.haml +9 -1
- data/lib/milkode/cli.rb +3 -2
- data/lib/milkode/common/util.rb +6 -2
- data/lib/milkode/database/document_table.rb +4 -0
- data/lib/milkode/database/package_table.rb +4 -0
- data/lib/milkode/grep/cli_grep.rb +48 -36
- data/lib/milkode/grep/fast_gotoline.rb +53 -0
- data/lib/milkode/{findgrep → grep}/findgrep.rb +42 -56
- data/lib/milkode/grep/findgrep_option.rb +63 -0
- data/milkode.gemspec +22 -11
- data/test/test_cli.rb +3 -1
- data/test/test_cli_grep.rb +1 -1
- data/test/test_findgrep.rb +2 -2
- data/test/test_milkode_yaml.rb +48 -4
- data/test/test_query.rb +2 -0
- metadata +39 -22
- data/lib/milkode/common/archive-zip.rb +0 -10
- data/lib/milkode/findgrep/result.rb +0 -43
@@ -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
|
-
|
8
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
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
|
|
data/lib/milkode/cli.rb
CHANGED
@@ -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
|
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'
|
data/lib/milkode/common/util.rb
CHANGED
@@ -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
|
@@ -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 =
|
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 (
|
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
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
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
|
-
|
164
|
-
findGrep = FindGrep
|
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
|
16
|
+
module Milkode
|
17
17
|
class FindGrep
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
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
|