Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents ca028e2 + 05bb540 commit b586529768f197dc252fd6ee2338ca28c0f2945f @ongaeshi committed Sep 29, 2011
View
@@ -1,3 +1,15 @@
+=== 0.2.3 2011/09/29
+
+* webインターフェースの検索速度向上
+ * ミニファイされたJavaScript等、一行の長いファイルの検索が高速になりました。
+* 日本語ファイル名に対応
+ * #10: windows環境(mswin32)で、日本語ファイル、日英混在文字が化ける (thanks aki1999)
+ * OSXの濁点ファイル名問題を修正 (Ruby1.9.2を使えば、濁点付きの日本語ファイルを正常に処理出来ます)
+* #9: 検索文字列に特定の文字が含まれるとInternal Server Error (thanks vividtone)
+* バグ修正、特定ディレクトリ以下の検索で横のパッケージが'../milkode'のように表示されてしまう問題の修正
+* archive-zip 0.4.0に対応。vendor/archive/support/io.rb は必要なくなったので削除。
+* 既に追加済みのパッケージを再度 milk add したら milk update するように
+
=== 0.2.2 2011/08/26
* ファイル内grepを追加
View
@@ -27,9 +27,9 @@ Jeweler::Tasks.new do |gem|
gem.add_runtime_dependency 'rack','>=1.2.1'
gem.add_runtime_dependency 'sinatra', '>=1.2.6'
gem.add_runtime_dependency 'launchy', '>=0.3.7'
- gem.add_runtime_dependency 'coderay', '>=0.9.8'
+ gem.add_runtime_dependency 'coderay', '=0.9.8'
gem.add_runtime_dependency 'thin', '>=1.2.10'
- gem.add_runtime_dependency 'archive-zip', '>=0.3.0'
+ gem.add_runtime_dependency 'archive-zip', '>=0.4.0'
gem.add_runtime_dependency 'haml', '>=3.1.2'
gem.add_runtime_dependency 'sass', '>=3.1.3'
gem.add_runtime_dependency 'nokogiri', '>=1.5.0'
@@ -58,17 +58,23 @@ Rake::TestTask.new(:test) do |test|
test.verbose = true
end
-# task :test do
-# load "test/runner.rb"
-# end
+task :test_all do
+ puts "--- rvm 1.9.2@milkode ---"
+ system('rvm 1.9.2@milkode')
+ system('rake test')
-require 'rcov/rcovtask'
-Rcov::RcovTask.new do |test|
- test.libs << 'test'
- test.pattern = 'test/**/test_*.rb'
- test.verbose = true
+ puts "--- rvm system ---"
+ system('rvm system')
+ system('rake test')
end
+# require 'rcov/rcovtask'
+# Rcov::RcovTask.new do |test|
+# test.libs << 'test'
+# test.pattern = 'test/**/test_*.rb'
+# test.verbose = true
+# end
+
task :default => :test
require 'rake/rdoctask'
View
@@ -1 +1 @@
-0.2.2
+0.2.3
View
@@ -6,5 +6,5 @@
require 'rubygems'
require 'milkode/cdstk/cli_cdstk'
-Version = "0.2.2"
+Version = "0.2.3"
Milkode::CLI_Cdstk.execute(STDOUT, ARGV)
@@ -34,6 +34,7 @@ def initialize(io = $stdout, db_dir = ".")
@db_dir = db_dir
Database.setup(@db_dir)
@out = io
+ # @out = $stdout # 強制出力
clear_count
end
@@ -91,11 +92,12 @@ def add(contents)
# 存在しないコンテンツがあった場合はその場で終了
contents.each do |v|
shortname = File.basename v
- if (yaml.exist? shortname)
+
+ if (yaml.cant_add_directory? v)
error_alert("already exist '#{shortname}'.")
return
end
-
+
unless (File.exist? v)
error_alert("not found '#{v}'.")
return
@@ -432,13 +434,18 @@ def db_add_dir(dirname)
private :db_add_dir
def db_add_file(stdout, filename, shortpath)
+ # ファイル名を全てUTF-8に変換
+ filename_utf8 = Util::filename_to_utf8(filename)
+ shortpath_utf8 = Util::filename_to_utf8(shortpath)
+ suffix_utf8 = File::extname(filename_utf8)
+
# 格納するデータ
values = {
- :path => filename,
- :shortpath => shortpath,
+ :path => filename_utf8,
+ :shortpath => shortpath_utf8,
:content => nil,
:timestamp => File.mtime(filename),
- :suffix => File::extname(filename),
+ :suffix => suffix_utf8,
}
# 検索するデータベース
@@ -518,7 +525,11 @@ def ignoreFile?(fpath)
private :ignoreFile?
def alert(title, msg)
- @out.puts "#{title.ljust(10)} : #{msg}"
+ if (Util::platform_win?)
+ @out.puts "#{title.ljust(10)} : #{Kconv.kconv(msg, Kconv::SJIS)}"
+ else
+ @out.puts "#{title.ljust(10)} : #{msg}"
+ end
end
def error_alert(msg)
@@ -76,6 +76,13 @@ def exist?(shortname)
@data['contents'].find {|v| File.basename(v['directory']) == shortname }
end
+ def cant_add_directory?(dir)
+ @data['contents'].find {|v|
+ v['directory'] != File.expand_path(dir) &&
+ File.basename(v['directory']) == File.basename(dir)
+ }
+ end
+
def cleanup
contents.delete_if do |v|
if (!File.exist? v['directory'])
@@ -18,7 +18,7 @@
set :haml, :format => :html5
get '/' do
- @version = "0.2.2"
+ @version = "0.2.3"
@package_num = Database.instance.fileList('').size
@file_num = Database.instance.fileNum
haml :index
@@ -9,6 +9,7 @@
require 'coderay'
require 'coderay/helpers/file_type'
require 'nokogiri'
+require 'milkode/common/util'
module Milkode
class CodeRayWrapper
@@ -22,6 +23,18 @@ def initialize(content, filename, match_lines = [])
@line_number_start = 1
end
+ def col_limit(limit_num)
+ content_a = @content.split("\n")
+
+ @content = content_a.map{|v|
+ if (v.length > limit_num)
+ v[0...limit_num] + " ..."
+ else
+ v
+ end
+ }.join("\n")
+ end
+
def set_range(range)
content_a = @content.split("\n")
range = limit_range(range, content_a)
@@ -43,7 +56,13 @@ def to_html
:highlight_lines => @highlight_lines,
:line_number_start => @line_number_start
)
- milkode_ornament(html)
+
+ if (is_ornament?)
+ html_doc = Nokogiri::HTML(html)
+ add_spanid(html_doc)
+ else
+ html
+ end
end
def to_html_anchor
@@ -55,39 +74,36 @@ def to_html_anchor
:highlight_lines => @highlight_lines,
:line_number_start => @line_number_start
)
-
- html_doc = Nokogiri::HTML(html)
- anchor = create_anchorlink(html_doc.at_css("table.CodeRay td.code pre").inner_html)
- body = milkode_ornament(html)
- return anchor + body
+
+ if (is_ornament?)
+ html_doc = Nokogiri::HTML(html)
+ anchor = create_anchorlink(html_doc.at_css("table.CodeRay td.code pre").inner_html)
+ body = add_spanid(html_doc)
+ anchor + body
+ else
+ html
+ end
end
- def milkode_ornament(html)
- # @todo nokogiri使う?
- a = html.split("\n")
+ def add_spanid(html_doc)
+ table = html_doc.at_css("table.CodeRay")
+
+ # preに<span id="行番号"> を付ける
+ pre = table.at_css("td.code pre")
+ pre.inner_html = add_spanid_in(pre.inner_html)
+
+ # 結果を文字列で返す
+ table.to_html
+ end
+ def add_spanid_in(html)
+ lines = html.split("<tt>\n</tt>")
line_number = @line_number_start
- is_code_content = false
-
- a.each_with_index do |l, index|
- if (l =~ / <td class="code"><pre (.*?)>(.*)<tt>/)
- a[index] = " <td class=\"code\"><pre #{$1}><span #{line_attr(line_number)}>#{$2}</span><tt>"
- is_code_content = true
- line_number += 1
- next
- elsif (l =~ %r|</tt></pre></td>|)
- is_code_content = false
- end
- if (is_code_content)
- if (l =~ %r|</tt>(.*)<tt>|)
- a[index] = "</tt><span #{line_attr(line_number)}>#{$1}</span><tt>"
- line_number += 1
- end
- end
- end
-
- a.join("\n") + "\n"
+ lines.map {|l|
+ line_number += 1
+ "<span #{line_attr(line_number - 1)}>#{l}</span>"
+ }.join("<tt>\n</tt>") + "<tt>\n</tt>"
end
def file_type
@@ -127,6 +143,11 @@ def create_anchorlink(str)
""
end
end
+
+ def is_ornament?
+ Util::larger_than_oneline(@content)
+ end
+
end
end
@@ -10,6 +10,7 @@
require 'milkode/cdweb/lib/search_contents'
require 'milkode/cdweb/lib/search_files'
require 'milkode/cdweb/lib/mkurl'
+require 'milkode/common/util'
module Milkode
def view(record, params, before)
@@ -18,7 +19,7 @@ def view(record, params, before)
q = params[:query] && Query.new(params[:query])
- if (q and !q.keywords.empty?)
+ if (Util::larger_than_oneline(record.content) and q and !q.keywords.empty?)
grep = Grep.new(record.content)
match_lines = grep.match_lines_and(q.keywords)
@record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html_anchor
@@ -58,7 +58,7 @@ def strs2regs(strs, ignore = false)
strs.each do |v|
option = 0
option |= Regexp::IGNORECASE if (ignore)
- regs << Regexp.new(v, option)
+ regs << Regexp.new(Regexp.escape(v), option)
end
regs
@@ -19,9 +19,12 @@ class SearchContents
DISP_NUM = 20 # 1ページの表示数
LIMIT_NUM = 50 # 最大検索ファイル数
NTH = 3 # 表示範囲
+ COL_LIMIT = 200 # 1行の桁制限
+
# DISP_NUM = 1000 # 1ページの表示数
# LIMIT_NUM = 1000 # 最大検索ファイル数
# NTH = 3 # 表示範囲
+# COL_LIMIT = 200 # 1行の桁制限
def initialize(path, params, query)
@path = path
@@ -30,7 +33,7 @@ def initialize(path, params, query)
@page = params[:page].to_i || 0
@offset = params[:offset].to_i
fpaths = @q.fpaths
- fpaths << path unless path == ""
+ fpaths << path + "/" unless path == ""
@records, @total_records, @elapsed = Database.instance.search(@q.keywords, @q.packages, fpaths, @q.suffixs, @offset, LIMIT_NUM)
grep_contents
end
@@ -75,9 +78,13 @@ def grep_contents
@next_index = @records.size
@records.each_with_index do |record, index|
- grep = Grep.new(record.content)
- match_line = grep.one_match_and(@q.keywords)
- @match_records << MatchRecord.new(record, match_line) if match_line
+ if (Util::larger_than_oneline(record.content))
+ grep = Grep.new(record.content)
+ match_line = grep.one_match_and(@q.keywords)
+ @match_records << MatchRecord.new(record, match_line) if match_line
+ else
+ @match_records << MatchRecord.new(record, Grep::MatchLineResult.new(0, nil))
+ end
if @match_records.size >= DISP_NUM
@next_index = index + 1
@@ -94,6 +101,7 @@ def result_match_record(match_record)
last_index = match_line.index + NTH
coderay = CodeRayWrapper.new(record.content, record.shortpath, [match_line])
+ coderay.col_limit(COL_LIMIT)
coderay.set_range(first_index..last_index)
<<EOS
@@ -24,7 +24,7 @@ def initialize(path, params, query)
@offset = params[:offset].to_i
fpaths = @q.fpaths
- fpaths << path unless path == ""
+ fpaths << path + "/" unless path == ""
if (fpaths.include?("*"))
@records, @total_records = Database.instance.selectAll(@offset, DISP_NUM)
@@ -5,5 +5,6 @@
# @author ongaeshi
# @date 2011/08/04
-$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../../../vendor')
+# 0.4.0になったため、必要なくなった。
+# $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../../../vendor')
require 'archive/zip'
Oops, something went wrong.

0 comments on commit b586529

Please sign in to comment.