milkode 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -21,4 +21,5 @@ gem 'thor', '~> 0.15.0'
21
21
  group :development do
22
22
  gem "bundler"
23
23
  gem "jeweler"
24
+ gem "rack-test"
24
25
  end
data/HISTORY.ja.rdoc CHANGED
@@ -1,3 +1,39 @@
1
+ === 0.9.0 2012/07/09
2
+
3
+ * milk web
4
+ * ページデザインを刷新
5
+ * メインページ以外もTwitter bootstrapに対応
6
+ * デザインの調整
7
+ * ファイル一覧 -> ディレクトリ に文章変更
8
+ * 検索時にキーワードにマッチするファイルも合わせて表示するように
9
+ * パッケージセレクタの追加
10
+ * 現在パッケージ名を選択
11
+ * パッケージの切り替え
12
+ * ダイレクトジャンプ
13
+ * viewモードで行番号をクリックするとダイレクトパス(現在行を表すテキスト)を表示
14
+ * ダイレクトパス入力時に指定行に直接ジャンプ出来るように
15
+ * 検索オプション追加
16
+ * fp(fpath_or_packages)
17
+ * k(keyword)
18
+ * 大文字/小文字を区別する(:sensitive)
19
+ * バグ修正
20
+ * 空ファイルを表示出来ない問題を修正
21
+ * 半角スペースを含むファイルが正しく表示出来ない
22
+ * ファイル検索時に次の100件が表示されない
23
+ * ヘルプに文言追加
24
+ * Webアプリのテストを追加(test_cdweb_app)
25
+
26
+ * gmilk
27
+ * 引数解析して'-g'オプション無くても-gモードに移行出来るように
28
+ * ダイレクトパス入力時に指定行に直接ジャンプ出来るように
29
+
30
+ * database
31
+ * fpath_or_packages(fp)オプションに対応
32
+
33
+ === 0.8.1 2012/06/20
34
+
35
+ * gmilk -a -u 時にエラーになる問題を修正 (thanks hazy_moon)
36
+
1
37
  === 0.8.0 2012/06/20
2
38
 
3
39
  * milk web
data/HISTORY.rdoc CHANGED
@@ -1,3 +1,23 @@
1
+ === 0.9.0 2012/07/09
2
+
3
+ * milk web
4
+ * Renew page design
5
+ * Display match files when searching
6
+ * Add package selector
7
+ * Direct jump
8
+ * Add search options
9
+ * Bug fix
10
+
11
+ * gmilk
12
+ * Direct jump
13
+
14
+ * database
15
+ * fpath_or_packages
16
+
17
+ === 0.8.1 2012/06/20
18
+
19
+ * Fix, gmilk -a -u error (thanks hazy_moon)
20
+
1
21
  === 0.8.0 2012/06/20
2
22
 
3
23
  * milk web
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.1
1
+ 0.9.0
data/bin/gmilk CHANGED
@@ -6,5 +6,5 @@
6
6
  require 'rubygems'
7
7
  require 'milkode/grep/cli_grep'
8
8
 
9
- Version = "0.8.0"
9
+ Version = "0.9.0"
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.8.0"
9
+ Version = "0.9.0"
10
10
  Milkode::CLI.start(ARGV)
@@ -16,12 +16,13 @@ require 'milkode/cdweb/lib/command'
16
16
  require 'milkode/cdweb/lib/mkurl'
17
17
  require 'milkode/cdweb/lib/web_setting'
18
18
  require 'milkode/cdweb/lib/package_list'
19
+ require 'milkode/common/util'
19
20
 
20
21
  set :haml, :format => :html5
21
22
 
22
23
  get '/' do
23
24
  @setting = WebSetting.new
24
- @version = "0.8.0"
25
+ @version = "0.9.0"
25
26
  @package_num = Database.instance.yaml_package_num
26
27
  @file_num = Database.instance.totalRecords
27
28
  @package_list = PackageList.new(Database.instance.grndb)
@@ -49,7 +50,15 @@ post '/search*' do
49
50
  path = package_path(path)
50
51
  end
51
52
 
52
- redirect Mkurl.new("#{path}", params).inherit_query_shead
53
+ query = Query.new(params[:query])
54
+ # gotolineモードで1つだけ渡された時は直接ジャンプ
55
+ if query.keywords.size == 1 && Milkode::Util::gotoline_keyword?(query.keywords[0])
56
+ gotoline = Milkode::Util::parse_gotoline(query.keywords)[0]
57
+ path2 = File.join('/home', gotoline[0][0])
58
+ redirect Mkurl.new(path2, params).inherit_query_shead + "#n#{gotoline[1]}"
59
+ else
60
+ redirect Mkurl.new("#{path}", params).inherit_query_shead
61
+ end
53
62
  end
54
63
  end
55
64
 
@@ -96,14 +105,37 @@ helpers do
96
105
  "<a href='#{'/home?query=' + escape_url(query)}'>#{query}</a>"
97
106
  end
98
107
 
99
- def create_radio(value, shead)
100
- str = (value == shead) ? 'checked' : ''
101
- "<input name='shead' type='radio' value='#{value}' #{str}/>"
108
+ def create_select_shead(value)
109
+ value ||= "package"
110
+
111
+ data = [
112
+ ['all' , '全て' ],
113
+ ['package' , 'パッケージ' ],
114
+ ['directory', 'ディレクトリ'],
115
+ ]
116
+
117
+ <<EOF
118
+ <select name="shead" id="shead">
119
+ #{data.map{|v| "<option value='#{v[0]}' #{v[0] == value ? 'selected' : ''}>#{v[1]}</option>"}}
120
+ </select>
121
+ EOF
102
122
  end
103
123
 
104
- def create_checkbox(name, value)
124
+ def create_select_package(path)
125
+ value = package_name(path)
126
+ value = '---' if value == "root"
127
+ data = ['---'] + Database.instance.packages(nil)
128
+
129
+ <<EOF
130
+ <select name="package" id="package" onchange="select_package()">
131
+ #{data.map{|v| "<option value='#{v}' #{v == value ? 'selected' : ''}>#{v}</option>"}}
132
+ </select>
133
+ EOF
134
+ end
135
+
136
+ def create_checkbox(name, value, label)
105
137
  str = (value) ? 'checked' : ''
106
- "<input type='checkbox' name='#{name}' value='on' #{str}/>"
138
+ "<label class='checkbox inline'><input type='checkbox' name='#{name}' value='on' #{str}/>#{label}</label>"
107
139
  end
108
140
 
109
141
  def create_headmenu(path, query, flistpath = '')
@@ -112,7 +144,7 @@ helpers do
112
144
  <<EOF
113
145
  #{headicon('go-home-5.png')} <a href="/home" class="headmenu">全てのパッケージ</a>
114
146
  #{headicon('document-new-4.png')} <a href="#{href}" class="headmenu" onclick="window.open('#{href}'); return false;">新しい検索</a>
115
- #{headicon('directory.png')} <a href="#{flist}" class="headmenu">ファイル一覧</a>
147
+ #{headicon('directory.png')} <a href="#{flist}" class="headmenu">ディレクトリ</a>
116
148
  #{headicon('help.png')} <a href="/help" class="headmenu">ヘルプ</a>
117
149
  EOF
118
150
  end
@@ -131,6 +163,35 @@ EOF
131
163
  }.join('/')
132
164
  end
133
165
 
166
+ HASH = {
167
+ '.h' => ['.c', '.cpp', '.m', '.mm'],
168
+ '.c' => ['.h'],
169
+ '.hpp' => ['.cpp'],
170
+ '.cpp' => ['.hpp', '.h'],
171
+ '.m' => ['.h'],
172
+ '.mm' => ['.h'],
173
+ }
174
+
175
+ def additional_info(path, parms)
176
+ suffix = File.extname path
177
+ cadet = HASH[suffix]
178
+
179
+ if (cadet)
180
+ result = cadet.find do |v|
181
+ Database.instance.record(path.gsub(/#{suffix}\Z/, v))
182
+ end
183
+
184
+ if (result)
185
+ path2 = path.gsub(/#{suffix}\Z/, result)
186
+ " (<a href='#{Mkurl.new(File.join('/home', path2), params).inherit_query_shead}'>#{result}</a>) "
187
+ else
188
+ ''
189
+ end
190
+ else
191
+ ''
192
+ end
193
+ end
194
+
134
195
  def package_name(path)
135
196
  (path == "") ? 'root' : path.split('/')[0]
136
197
  end
@@ -72,22 +72,7 @@ module Encoders
72
72
  raise ArgumentError, "Invalid value %p for :line_number_start; Integer expected." % start
73
73
  end
74
74
 
75
- anchor_prefix = options[:line_number_anchors]
76
- anchor_prefix = 'line' if anchor_prefix == true
77
- anchor_prefix = anchor_prefix.to_s[/\w+/] if anchor_prefix
78
-
79
- anchor_url = options[:line_number_anchor_url] || ""
80
-
81
- anchoring =
82
- if anchor_prefix
83
- proc do |line|
84
- line = line.to_s
85
- anchor = anchor_prefix + line
86
- "<a href=\"#{anchor_url}##{anchor}\" name=\"#{anchor}\">#{line}</a>"
87
- end
88
- else
89
- proc { |line| line.to_s } # :to_s.to_proc in Ruby 1.8.7+
90
- end
75
+ anchoring = create_anchor(options)
91
76
 
92
77
  bold_every = options[:bold_every]
93
78
  highlight_lines = options[:highlight_lines]
@@ -166,6 +151,29 @@ module Encoders
166
151
 
167
152
  output
168
153
  end
154
+
155
+ def self.create_anchor(options)
156
+ anchor_prefix = options[:line_number_anchors]
157
+ anchor_prefix = 'line' if anchor_prefix == true
158
+ anchor_prefix = anchor_prefix.to_s[/\w+/] if anchor_prefix
159
+
160
+ if anchor_prefix
161
+ anchor_url = options[:line_number_anchor_url] || ""
162
+
163
+ proc do |line|
164
+ line = line.to_s
165
+ anchor = anchor_prefix + line
166
+ "<a href=\"#{anchor_url}##{anchor}\" name=\"#{anchor}\">#{line}</a>"
167
+ end
168
+ elsif options[:onclick_copy_line_number]
169
+ prefix = options[:onclick_copy_prefix] || ""
170
+ proc do |line|
171
+ "<a href=\"#!\" onclick=\"alert('#{prefix + line.to_s}');\" title=\"Display line number\">#{line.to_s}</a>"
172
+ end
173
+ else
174
+ proc { |line| line.to_s } # :to_s.to_proc in Ruby 1.8.7+
175
+ end
176
+ end
169
177
  end
170
178
  end
171
179
  end
@@ -55,7 +55,9 @@ module Milkode
55
55
  :css => :class,
56
56
  :highlight_lines => @highlight_lines,
57
57
  :line_number_start => @line_number_start,
58
- :line_number_anchors => false
58
+ :line_number_anchors => false,
59
+ :onclick_copy_line_number => true,
60
+ :onclick_copy_prefix => "/#{@filename}:"
59
61
  )
60
62
  end
61
63
 
@@ -9,6 +9,7 @@ require 'milkode/cdweb/lib/database'
9
9
  require 'milkode/cdweb/lib/coderay_wrapper'
10
10
  require 'milkode/cdweb/lib/search_contents'
11
11
  require 'milkode/cdweb/lib/search_files'
12
+ require 'milkode/cdweb/lib/search_gotoline'
12
13
  require 'milkode/cdweb/lib/mkurl'
13
14
  require 'milkode/common/util'
14
15
 
@@ -17,13 +18,25 @@ module Milkode
17
18
  @setting = WebSetting.new
18
19
  @title = record.shortpath
19
20
  @path = record.shortpath
21
+ is_sensitive = params[:sensitive] == 'on'
20
22
 
21
23
  q = params[:query] && Query.new(params[:query])
22
24
 
23
25
  if (Util::larger_than_oneline(record.content) and q and !q.keywords.empty?)
24
- grep = Grep.new(record.content)
25
- match_lines = grep.match_lines_and(q.keywords)
26
- @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html
26
+ if Util::gotoline_keyword? q.keywords[0]
27
+ gotolines = Util::parse_gotoline(q.keywords)
28
+ match_lines = []
29
+ gotolines.each do |v|
30
+ if v[0][0][1..-1] == record.shortpath
31
+ match_lines << Grep::MatchLineResult.new(v[1] - 1, nil)
32
+ end
33
+ end
34
+ @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html
35
+ else
36
+ grep = Grep.new(record.content)
37
+ match_lines = grep.match_lines_and(q.keywords, is_sensitive)
38
+ @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html
39
+ end
27
40
  else
28
41
  @record_content = CodeRayWrapper.new(record.content, record.shortpath).to_html
29
42
  end
@@ -40,7 +53,11 @@ module Milkode
40
53
  @title = "'#{query.query_string}' in #{path_title(path)}"
41
54
 
42
55
  if (query.keywords.size > 0)
43
- searcher = SearchContents.new(path, params, query)
56
+ if Util::gotoline_keyword? query.keywords[0]
57
+ searcher = SearchGotoLine.new(path, params, query)
58
+ else
59
+ searcher = SearchContents.new(path, params, query)
60
+ end
44
61
  else
45
62
  searcher = SearchFiles.new(path, params, query)
46
63
  end
@@ -12,6 +12,7 @@ require 'groonga'
12
12
  require 'milkode/common/dbdir'
13
13
  require 'milkode/cdstk/yaml_file_wrapper'
14
14
  require 'milkode/database/groonga_database'
15
+ require 'milkode/common/util'
15
16
  include Milkode
16
17
 
17
18
  module Milkode
@@ -42,18 +43,22 @@ module Milkode
42
43
 
43
44
  def open
44
45
  if !@grndb || @grndb.closed?
45
- @grndb = GroongaDatabase.new
46
- @grndb.open(Database.dbdir)
47
- @grndb.yaml_sync(yaml_load.contents)
48
- @documents = @grndb.documents
46
+ open_force
49
47
  end
50
48
  end
51
49
 
50
+ def open_force
51
+ @grndb = GroongaDatabase.new
52
+ @grndb.open(Database.dbdir)
53
+ @grndb.yaml_sync(yaml_load.contents)
54
+ @documents = @grndb.documents
55
+ end
56
+
52
57
  def record(shortpath)
53
58
  DocumentRecord.create @documents.find_shortpath(shortpath)
54
59
  end
55
60
 
56
- def search(patterns, packages, current_path, fpaths, suffixs, offset = 0, limit = -1)
61
+ def search(patterns, keywords, packages, current_path, fpaths, suffixs, fpath_or_packages, offset = 0, limit = -1)
57
62
  paths = []
58
63
 
59
64
  # パッケージ名未指定の時は現在位置を検索条件に追加
@@ -73,11 +78,12 @@ module Milkode
73
78
  # 検索
74
79
  result = @documents.search(
75
80
  :patterns => patterns,
76
- # :keywords => ,
81
+ :keywords => keywords,
77
82
  :paths => paths,
78
83
  :packages => packages,
79
84
  :restpaths => fpaths,
80
85
  :suffixs => suffixs,
86
+ :fpath_or_packages => fpath_or_packages,
81
87
  :offset => offset,
82
88
  :limit => limit
83
89
  )
@@ -5,6 +5,8 @@
5
5
  # @author ongaeshi
6
6
  # @date 2010/10/18
7
7
 
8
+ require 'milkode/common/util'
9
+
8
10
  module Milkode
9
11
  class Grep
10
12
  def initialize(content)
@@ -13,9 +15,9 @@ module Milkode
13
15
 
14
16
  MatchLineResult = Struct.new(:index, :match_datas)
15
17
 
16
- def match_lines_stopover(patterns, max_match, start_index)
18
+ def match_lines_stopover(patterns, max_match, start_index, is_sensitive)
17
19
  result = []
18
- patternRegexps = strs2regs(patterns, true)
20
+ patternRegexps = strs2regs(patterns, Util::ignore_case?(patterns, is_sensitive))
19
21
  index = start_index
20
22
 
21
23
  lines = @content.split($/)
@@ -41,9 +43,9 @@ module Milkode
41
43
  {:result => result, :next_line => index}
42
44
  end
43
45
 
44
- def match_lines_and(patterns)
46
+ def match_lines_and(patterns, is_sensitive)
45
47
  result = []
46
- patternRegexps = strs2regs(patterns, true)
48
+ patternRegexps = strs2regs(patterns, Util::ignore_case?(patterns, is_sensitive))
47
49
  index = 0
48
50
 
49
51
  @content.each_line do |line|
@@ -60,8 +62,8 @@ module Milkode
60
62
  result
61
63
  end
62
64
 
63
- def one_match_and(patterns)
64
- patternRegexps = strs2regs(patterns, true)
65
+ def one_match_and(patterns, is_sensitive)
66
+ patternRegexps = strs2regs(patterns, Util::ignore_case?(patterns, is_sensitive))
65
67
  index = 0
66
68
 
67
69
  @content.each_line do |line|
@@ -7,7 +7,6 @@
7
7
 
8
8
  require 'rubygems'
9
9
  require 'rack'
10
- include Rack::Utils
11
10
 
12
11
  module Milkode
13
12
  class Mkurl
@@ -39,7 +38,12 @@ module Milkode
39
38
  private
40
39
 
41
40
  def escape_path(src)
42
- escape(src).gsub("%2F", '/')
41
+ # /rack-1.3.0/lib/rack/utils.rb:29
42
+ Rack::Utils::escape_path(src).gsub("%2F", '/')
43
+ end
44
+
45
+ def escape(src)
46
+ Rack::Utils::escape(src)
43
47
  end
44
48
 
45
49
  def create_url(qp)
@@ -55,6 +59,7 @@ module Milkode
55
59
  qparam << "query=#{escape(@params[:query])}" if (query_inherit and @params[:query])
56
60
  qparam << "shead=#{escape(@params[:shead])}" if (shead_inherit and @params[:shead])
57
61
  qparam << "onematch=#{escape(@params[:onematch])}" if (shead_inherit and @params[:onematch])
62
+ qparam << "sensitive=#{escape(@params[:sensitive])}" if (shead_inherit and @params[:sensitive])
58
63
  qparam << "offset=#{escape(@params[:offset])}" if (offset_inherit and @params[:offset])
59
64
  qparam << "line=#{escape(@params[:line])}" if (offset_inherit and @params[:line])
60
65
  qparam << "sort=#{sort_kind}" if sort_kind