Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ongaeshi committed Mar 26, 2013
2 parents 8e8dc94 + ec0db66 commit b1d7393
Show file tree
Hide file tree
Showing 20 changed files with 386 additions and 145 deletions.
7 changes: 4 additions & 3 deletions Gemfile
Expand Up @@ -19,7 +19,8 @@ gem 'thor', '~> 0.15.0'
# Add dependencies to develop your gem here. # Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc. # Include everything needed to run rake, tests, features, etc.
group :development do group :development do
gem "bundler" gem 'bundler'
gem "jeweler" gem 'jeweler'
gem "rack-test" gem 'rack-test'
gem 'sinatra-reloader'
end end
17 changes: 17 additions & 0 deletions HISTORY.ja.rdoc
@@ -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 === 0.9.8 2013/02/27


* Support MyGithub * Support MyGithub
Expand Down
9 changes: 9 additions & 0 deletions HISTORY.rdoc
@@ -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 === 0.9.8 2013/02/27


* Support MyGithub * Support MyGithub
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.9.8 0.9.9
2 changes: 1 addition & 1 deletion bin/gmilk 100644 → 100755
Expand Up @@ -6,5 +6,5 @@
require 'rubygems' require 'rubygems'
require 'milkode/grep/cli_grep' require 'milkode/grep/cli_grep'


Version = "0.9.8" Version = "0.9.9"
Milkode::CLI_Grep.execute(STDOUT, ARGV) Milkode::CLI_Grep.execute(STDOUT, ARGV)
2 changes: 1 addition & 1 deletion bin/milk
Expand Up @@ -6,5 +6,5 @@
require 'rubygems' require 'rubygems'
require 'milkode/cli' require 'milkode/cli'


Version = "0.9.8" Version = "0.9.9"
Milkode::CLI.start(ARGV) Milkode::CLI.start(ARGV)
30 changes: 18 additions & 12 deletions lib/milkode/cdweb/app.rb
Expand Up @@ -7,6 +7,10 @@


require 'rubygems' require 'rubygems'
require 'sinatra' require 'sinatra'
if ENV['MILKODE_SINATRA_RELOADER']
require 'sinatra/reloader'
also_reload '../../**/*.rb'
end
require 'sass' require 'sass'
require 'haml' require 'haml'


Expand All @@ -21,12 +25,20 @@
set :haml, :format => :html5 set :haml, :format => :html5


get '/' do get '/' do
@setting = WebSetting.new if Database.validate?
@version = "0.9.8" @setting = WebSetting.new
@package_num = Database.instance.yaml_package_num @version = "0.9.9"
@file_num = Database.instance.totalRecords
@package_list = PackageList.new(Database.instance.grndb) @package_num = Database.instance.yaml_package_num
haml :index, :layout => false @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 end


def package_path(path) def package_path(path)
Expand Down Expand Up @@ -103,12 +115,6 @@ def package_path(path)
haml :help haml :help
end end


begin
NO_REQUIRE_APP_ERROR
rescue NameError
require 'milkode/cdweb/app_error'
end

# -- helper function -- # -- helper function --


helpers do helpers do
Expand Down
15 changes: 0 additions & 15 deletions lib/milkode/cdweb/app_error.rb

This file was deleted.

3 changes: 2 additions & 1 deletion lib/milkode/cdweb/cli_cdweb.rb
Expand Up @@ -112,7 +112,8 @@ def self.execute_with_options(stdout, options)
end end


def self.select_dbdir def self.select_dbdir
if (Dbdir.dbdir?('.') || !Dbdir.dbdir?(Dbdir.default_dir)) # if (Dbdir.dbdir?('.') || !Dbdir.dbdir?(Dbdir.default_dir))
if Dbdir.dbdir?('.')
'.' '.'
else else
Dbdir.default_dir Dbdir.default_dir
Expand Down
8 changes: 7 additions & 1 deletion lib/milkode/cdweb/lib/command.rb
Expand Up @@ -35,7 +35,13 @@ def view(record, params, before)
@record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html
else else
grep = Grep.new(record.content) 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 @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html
end end
else else
Expand Down
4 changes: 4 additions & 0 deletions lib/milkode/cdweb/lib/database.rb
Expand Up @@ -191,6 +191,10 @@ def update_all
end end
result result
end end

def self.validate?
YamlFileWrapper.load_if(Database.dbdir) != nil
end


private private


Expand Down
67 changes: 27 additions & 40 deletions lib/milkode/cdweb/lib/grep.rb
Expand Up @@ -6,30 +6,30 @@
# @date 2010/10/18 # @date 2010/10/18


require 'milkode/common/util' require 'milkode/common/util'
require 'milkode/common/wide_matcher'


module Milkode module Milkode
class Grep class Grep
def initialize(content) def initialize(content)
@content = content @content = content
end 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) matcher = WideMatcher.create(wide_match_range)
result = [] lines = @content.split($/)
patternRegexps = strs2regs(patterns, is_sensitive)
index = start_index

lines = @content.split($/)


while (index < lines.size) do while (index < lines.size) do
line = lines[index] line = lines[index]


match_datas = [] matcher.add_line_matchs(index, match_regexps(line, regexps))
patternRegexps.each {|v| match_datas << v.match(line)}


if (match_datas.all?) if matcher.match?
result << MatchLineResult.new(index, match_datas) result += matcher.match_lines

if result.size >= max_match if result.size >= max_match
index += 1 index += 1
break break
Expand All @@ -40,44 +40,27 @@ def match_lines_stopover(patterns, max_match, start_index, is_sensitive)
end end


index = 0 if (index >= lines.size) index = 0 if (index >= lines.size)
{:result => result, :next_line => index} {:result => result.uniq, :next_line => index}
end end


def match_lines_and(patterns, is_sensitive) def match_lines_and(patterns, is_sensitive, wide_match_range)
result = [] regexps = strs2regs(patterns, is_sensitive)
patternRegexps = strs2regs(patterns, is_sensitive) result = []
index = 0 index = 0

matcher = WideMatcher.create(wide_match_range)


@content.each_line do |line| @content.each_line do |line|
match_datas = [] matcher.add_line_matchs(index, match_regexps(line, regexps))
patternRegexps.each {|v| match_datas << v.match(line)} result += matcher.match_lines if matcher.match?

if (match_datas.all?)
result << MatchLineResult.new(index, match_datas)
end

index += 1 index += 1
end end


result result.uniq
end end


def one_match_and(patterns, is_sensitive) def one_match_and(patterns, is_sensitive, wide_match_range)
patternRegexps = strs2regs(patterns, is_sensitive) match_lines_stopover(patterns, 1, 0, is_sensitive, wide_match_range)
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
end end


private private
Expand All @@ -93,6 +76,10 @@ def strs2regs(strs, is_sensitive)


regs regs
end end

def match_regexps(line, regexps)
regexps.reduce([]) {|result, v| result << v.match(line); result}
end
end end
end end


42 changes: 34 additions & 8 deletions lib/milkode/cdweb/lib/query.rb
Expand Up @@ -13,30 +13,32 @@ class Query
attr_reader :query_string attr_reader :query_string


OPTIONS = [ OPTIONS = [
['package', 'p'], ['package' , 'p'],
['filepath', 'fpath', 'f'], ['filepath' , 'fpath', 'f'],
['suffix', 's'], ['suffix' , 's'],
['fp'], # fpath or package ['fp'] , # fpath or package
['keyword', 'k'], ['keyword' , 'k'],
['gotoline', 'g'], ['gotoline' , 'g'],
['wide' , 'w'],
] ]


def initialize(str) def initialize(str)
@query_string = str @query_string = str
init_hash init_hash
parse parse
@wide_match_range = calc_param(6)
end end


def escape_html def escape_html
Rack::Utils::escape_html(@query_string) Rack::Utils::escape_html(@query_string)
end end


def empty? 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 end


def only_keywords 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 end


def keywords def keywords
Expand Down Expand Up @@ -68,6 +70,26 @@ def gotolines
calc_param(5) calc_param(5)
end 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 def conv_keywords_to_fpath
s = query_string.split.map {|v| s = query_string.split.map {|v|
if keywords.include? v if keywords.include? v
Expand Down Expand Up @@ -118,6 +140,10 @@ def conv_fuzzy_gotoline
Query.new(s) Query.new(s)
end end


def conv_wide_match_range(match_range)
Query.new(query_string + " w:#{match_range}")
end

private private


def calc_param(index) def calc_param(index)
Expand Down

0 comments on commit b1d7393

Please sign in to comment.