Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents 8e8dc94 + ec0db66 commit b1d7393c82598b2e803e9c4d91de556fbb6e976a @ongaeshi committed Mar 26, 2013
View
@@ -19,7 +19,8 @@ gem 'thor', '~> 0.15.0'
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
- gem "bundler"
- gem "jeweler"
- gem "rack-test"
+ gem 'bundler'
+ gem 'jeweler'
+ gem 'rack-test'
+ gem 'sinatra-reloader'
end
View
@@ -1,3 +1,20 @@
+=== 0.9.9 2013/02/26
+
+* ワイド範囲検索のサポート
+ * 指定行内に複数のキーワードが含まれている場所を探す
+ * 複数のキーワードが一行でマッチしなかった場合、自動的に範囲を広げて再検索
+
+* 検索オプション w: を追加
+ * w:7 で7行以内に全てのキーワードが含まれている場所を返す
+ * w:1 で今までの検索
+ * w:0 の時は検索範囲をファイル全域に
+
+* Support sinatra-reloader
+ * export MILKODE_SINATRA_RELOADER=1
+
+* Delete 'milkode/cdweb/app_error.rb'
+ * Recommend 'RACK_ENV=production'
+
=== 0.9.8 2013/02/27
* Support MyGithub
View
@@ -1,3 +1,12 @@
+=== 0.9.9 2013/02/26
+
+* Suppor wide range search
+ * Add 'w:' search option
+* Support sinatra-reloader
+ * export MILKODE_SINATRA_RELOADER=1
+* Delete 'milkode/cdweb/app_error.rb'
+ * Recommend 'RACK_ENV=production'
+
=== 0.9.8 2013/02/27
* Support MyGithub
View
@@ -1 +1 @@
-0.9.8
+0.9.9
View
2 bin/gmilk 100644 → 100755
@@ -6,5 +6,5 @@
require 'rubygems'
require 'milkode/grep/cli_grep'
-Version = "0.9.8"
+Version = "0.9.9"
Milkode::CLI_Grep.execute(STDOUT, ARGV)
View
@@ -6,5 +6,5 @@
require 'rubygems'
require 'milkode/cli'
-Version = "0.9.8"
+Version = "0.9.9"
Milkode::CLI.start(ARGV)
@@ -7,6 +7,10 @@
require 'rubygems'
require 'sinatra'
+if ENV['MILKODE_SINATRA_RELOADER']
+ require 'sinatra/reloader'
+ also_reload '../../**/*.rb'
+end
require 'sass'
require 'haml'
@@ -21,12 +25,20 @@
set :haml, :format => :html5
get '/' do
- @setting = WebSetting.new
- @version = "0.9.8"
- @package_num = Database.instance.yaml_package_num
- @file_num = Database.instance.totalRecords
- @package_list = PackageList.new(Database.instance.grndb)
- haml :index, :layout => false
+ if Database.validate?
+ @setting = WebSetting.new
+ @version = "0.9.9"
+
+ @package_num = Database.instance.yaml_package_num
+ @file_num = Database.instance.totalRecords
+ @package_list = PackageList.new(Database.instance.grndb)
+ haml :index, :layout => false
+ else
+ <<EOF
+<h1>Setup Error!</h1>
+Database Directory: #{Database.dbdir}<br>
+EOF
+ end
end
def package_path(path)
@@ -103,12 +115,6 @@ def package_path(path)
haml :help
end
-begin
- NO_REQUIRE_APP_ERROR
-rescue NameError
- require 'milkode/cdweb/app_error'
-end
-
# -- helper function --
helpers do
@@ -1,15 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# @file
-# @brief
-# @author ongaeshi
-# @date 2013/02/17
-
-get '*' do
- @setting = WebSetting.new
- @path = ''
- haml :error
-end
-
-
-
@@ -112,7 +112,8 @@ def self.execute_with_options(stdout, options)
end
def self.select_dbdir
- if (Dbdir.dbdir?('.') || !Dbdir.dbdir?(Dbdir.default_dir))
+ # if (Dbdir.dbdir?('.') || !Dbdir.dbdir?(Dbdir.default_dir))
+ if Dbdir.dbdir?('.')
'.'
else
Dbdir.default_dir
@@ -35,7 +35,13 @@ def view(record, params, before)
@record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html
else
grep = Grep.new(record.content)
- match_lines = grep.match_lines_and(q.keywords, is_sensitive)
+ match_lines = grep.match_lines_and(q.keywords, is_sensitive, q.wide_match_range)
+
+ if match_lines.empty? && q.wide_match_range_empty?
+ # 検索範囲を広げる
+ match_lines = grep.match_lines_and(q.keywords, is_sensitive, 7)
+ end
+
@record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html
end
else
@@ -191,6 +191,10 @@ def update_all
end
result
end
+
+ def self.validate?
+ YamlFileWrapper.load_if(Database.dbdir) != nil
+ end
private
@@ -6,30 +6,30 @@
# @date 2010/10/18
require 'milkode/common/util'
+require 'milkode/common/wide_matcher'
module Milkode
class Grep
def initialize(content)
@content = content
end
- MatchLineResult = Struct.new(:index, :match_datas)
+ def match_lines_stopover(patterns, max_match, start_index, is_sensitive, wide_match_range)
+ regexps = strs2regs(patterns, is_sensitive)
+ result = []
+ index = start_index
- def match_lines_stopover(patterns, max_match, start_index, is_sensitive)
- result = []
- patternRegexps = strs2regs(patterns, is_sensitive)
- index = start_index
-
- lines = @content.split($/)
+ matcher = WideMatcher.create(wide_match_range)
+ lines = @content.split($/)
while (index < lines.size) do
line = lines[index]
- match_datas = []
- patternRegexps.each {|v| match_datas << v.match(line)}
+ matcher.add_line_matchs(index, match_regexps(line, regexps))
- if (match_datas.all?)
- result << MatchLineResult.new(index, match_datas)
+ if matcher.match?
+ result += matcher.match_lines
+
if result.size >= max_match
index += 1
break
@@ -40,44 +40,27 @@ def match_lines_stopover(patterns, max_match, start_index, is_sensitive)
end
index = 0 if (index >= lines.size)
- {:result => result, :next_line => index}
+ {:result => result.uniq, :next_line => index}
end
- def match_lines_and(patterns, is_sensitive)
- result = []
- patternRegexps = strs2regs(patterns, is_sensitive)
- index = 0
+ def match_lines_and(patterns, is_sensitive, wide_match_range)
+ regexps = strs2regs(patterns, is_sensitive)
+ result = []
+ index = 0
+
+ matcher = WideMatcher.create(wide_match_range)
@content.each_line do |line|
- match_datas = []
- patternRegexps.each {|v| match_datas << v.match(line)}
-
- if (match_datas.all?)
- result << MatchLineResult.new(index, match_datas)
- end
-
+ matcher.add_line_matchs(index, match_regexps(line, regexps))
+ result += matcher.match_lines if matcher.match?
index += 1
end
- result
+ result.uniq
end
- def one_match_and(patterns, is_sensitive)
- patternRegexps = strs2regs(patterns, is_sensitive)
- index = 0
-
- @content.each_line do |line|
- match_datas = []
- patternRegexps.each {|v| match_datas << v.match(line)}
-
- if (match_datas.all?)
- return MatchLineResult.new(index, match_datas)
- end
-
- index += 1
- end
-
- nil
+ def one_match_and(patterns, is_sensitive, wide_match_range)
+ match_lines_stopover(patterns, 1, 0, is_sensitive, wide_match_range)
end
private
@@ -93,6 +76,10 @@ def strs2regs(strs, is_sensitive)
regs
end
+
+ def match_regexps(line, regexps)
+ regexps.reduce([]) {|result, v| result << v.match(line); result}
+ end
end
end
@@ -13,30 +13,32 @@ class Query
attr_reader :query_string
OPTIONS = [
- ['package', 'p'],
- ['filepath', 'fpath', 'f'],
- ['suffix', 's'],
- ['fp'], # fpath or package
- ['keyword', 'k'],
- ['gotoline', 'g'],
+ ['package' , 'p'],
+ ['filepath' , 'fpath', 'f'],
+ ['suffix' , 's'],
+ ['fp'] , # fpath or package
+ ['keyword' , 'k'],
+ ['gotoline' , 'g'],
+ ['wide' , 'w'],
]
def initialize(str)
@query_string = str
init_hash
parse
+ @wide_match_range = calc_param(6)
end
def escape_html
Rack::Utils::escape_html(@query_string)
end
def empty?
- keywords.size == 0 && packages.size == 0 && fpaths.size == 0 && suffixs.size == 0 && fpath_or_packages.size == 0 && gotolines.size == 0
+ keywords.size == 0 && only_keywords
end
def only_keywords
- packages.size == 0 && fpaths.size == 0 && suffixs.size == 0 && fpath_or_packages.size == 0 && gotolines.size == 0
+ packages.size == 0 && fpaths.size == 0 && suffixs.size == 0 && fpath_or_packages.size == 0 && gotolines.size == 0 && wide_match_range_empty?
end
def keywords
@@ -68,6 +70,26 @@ def gotolines
calc_param(5)
end
+ def wide_match_range
+ a = @wide_match_range
+
+ if a.empty?
+ 1
+ else
+ i = a[-1].to_i
+
+ if (i == 0)
+ 0
+ else
+ i
+ end
+ end
+ end
+
+ def wide_match_range_empty?
+ @wide_match_range.empty?
+ end
+
def conv_keywords_to_fpath
s = query_string.split.map {|v|
if keywords.include? v
@@ -118,6 +140,10 @@ def conv_fuzzy_gotoline
Query.new(s)
end
+ def conv_wide_match_range(match_range)
+ Query.new(query_string + " w:#{match_range}")
+ end
+
private
def calc_param(index)
Oops, something went wrong.

0 comments on commit b1d7393

Please sign in to comment.