Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'develop'

  • Loading branch information...
commit dac874905ba45822c4125d407439cfe9f0df9049 2 parents 2971267 + 62d88d8
@ongaeshi authored
View
12 HISTORY.ja.rdoc
@@ -1,3 +1,15 @@
+=== 1.3.0 2013/10/28
+
+* milk web
+ * Highlight keywords
+ * Add github button if package is github repository
+ * Touch update time if exist update file only
+ * Add test case
+
+* milk
+ * GitHub repository check in 'milk update'
+ * Improve to not stop the package directory even if there is no
+
=== 1.2.0 2013/08/07
* milk web
View
12 HISTORY.rdoc
@@ -1,3 +1,15 @@
+=== 1.3.0 2013/10/28
+
+* milk web
+ * Highlight keywords
+ * Add github button if package is github repository
+ * Touch update time if exist update file only
+ * Add test case
+
+* milk
+ * GitHub repository check in 'milk update'
+ * Improve to not stop the package directory even if there is no
+
=== 1.2.0 2013/08/07
* milk web
View
2  VERSION
@@ -1 +1 @@
-1.2.0
+1.3.0
View
2  bin/gmilk
@@ -6,5 +6,5 @@
require 'rubygems'
require 'milkode/grep/cli_grep'
-Version = "1.2.0"
+Version = "1.3.0"
Milkode::CLI_Grep.execute(STDOUT, ARGV)
View
2  bin/milk
@@ -6,5 +6,5 @@
require 'rubygems'
require 'milkode/cli'
-Version = "1.2.0"
+Version = "1.3.0"
Milkode::CLI.start(ARGV)
View
14 lib/milkode/cdstk/cdstk.rb
@@ -1136,6 +1136,20 @@ def updater_exec(package, is_update_with_git_pull, is_update_with_svn_update, is
updater.exec
+ # Is github repository ?
+ if Util::exist_command?('git') && File.exist?(File.join(package.directory, ".git"))
+ repo_name = Dir.chdir(package.directory) { Util::github_repo(`git config --get remote.origin.url`) }
+
+ if repo_name && repo_name != package.options[:github]
+ dst = package.options
+ dst[:github] = repo_name
+ package.set_options(dst)
+ @yaml.update(package)
+ @yaml.save
+ alert("github", repo_name)
+ end
+ end
+
@package_count += 1
@file_count += updater.result.file_count
@add_count += updater.result.add_count
View
21 lib/milkode/cdweb/app.rb
@@ -44,7 +44,7 @@
get '/' do
if Database.validate?
@setting = WebSetting.new
- @version = "1.2.0"
+ @version = "1.3.0"
@package_num = Database.instance.yaml_package_num
@file_num = Database.instance.totalRecords
@@ -378,9 +378,26 @@ def favstar(path)
end
end
+ def goto_github_project(path)
+ return "" if (path == "")
+
+ paths = path.split('/')
+ package = Database.instance.yaml_package(paths[0])
+ return "" unless package.options[:github]
+
+ image_href = 'https://raw.github.com/github/media/master/octocats/blacktocat-16.png'
+ url = "https://github.com/#{package.options[:github]}"
+
+ if (paths.size == 1)
+ "<a href='#{url}' target=\"_blank\"><img src='#{image_href}'></img></a>"
+ else
+ "<a href='#{url}/tree/master/#{paths[1..-1].join('/')}' target=\"_blank\"><img src='#{image_href}'></img></a>"
+ end
+ end
+
# .search-summary に追加情報を表示したい時はこの関数をオーバーライド
def search_summary_hook(path)
- ""
+ goto_github_project(path)
end
end
View
18 lib/milkode/cdweb/lib/coderay_html2.rb
@@ -7,6 +7,7 @@
require 'rubygems'
require 'rack'
+require 'milkode/common/util'
module CodeRay
module Encoders
@@ -46,22 +47,27 @@ def finish options
end
def ornament_line_attr(options)
- # p options
line_number = options[:line_number_start]
-
lines = @out.split("\n")
lines.map{|l|
line_number += 1
- "<span #{line_attr(line_number - 1, options[:highlight_lines])}>#{l}</span>"
+ line_attr(l, line_number - 1, options)
}.join("\n") + "\n"
end
- def line_attr(no, highlight_lines)
+ def line_attr(line, no, options)
+ # p options
+ is_highlight = true if options[:highlight_lines].include?(no)
+
r = []
r << "id=\"n#{no}\""
- r << "class=\"highlight-line\"" if highlight_lines.include?(no)
- r.join(" ")
+ r << "class=\"highlight-line\"" if is_highlight
+ attr = r.join(" ")
+
+ line = Milkode::Util::highlight_keywords(line, options[:keywords], 'highlight-filename') if is_highlight
+
+ "<span #{attr}>#{line}</span>"
end
# [ref] CodeRay::Encoders::Numberling#number! (coderay-1.0.5/lib/coderay/encoders/numbering.rb:8)
View
9 lib/milkode/cdweb/lib/coderay_wrapper.rb
@@ -17,12 +17,13 @@ class CodeRayWrapper
attr_reader :line_number_start
attr_reader :highlight_lines
- def initialize(content, filename, match_lines = [])
+ def initialize(content, filename, match_lines = [], keywords = [])
@content = content
@filename = filename
@match_lines = match_lines
@highlight_lines = match_lines.map{|v|v.index+1}
@line_number_start = 1
+ @keywords = keywords
end
def col_limit(limit_num)
@@ -59,7 +60,8 @@ def to_html
:line_number_start => @line_number_start,
:line_number_anchors => false,
:onclick_copy_line_number => true,
- :onclick_copy_prefix => "/#{@filename}:"
+ :onclick_copy_prefix => "/#{@filename}:",
+ :keywords => @keywords
)
end
@@ -72,7 +74,8 @@ def to_html_anchorlink(url)
:highlight_lines => @highlight_lines,
:line_number_start => @line_number_start,
:line_number_anchors => 'n',
- :line_number_anchor_url => url
+ :line_number_anchor_url => url,
+ :keywords => @keywords
)
end
View
13 lib/milkode/cdweb/lib/command.rb
@@ -23,8 +23,8 @@ def view(record, params, before)
q = params[:query] && Query.new(params[:query])
- if (Util::larger_than_oneline(record.content) and q and !q.keywords.empty?)
- if Util::gotoline_keyword? q.keywords[0]
+ if (Util::larger_than_oneline(record.content) && q && !q.keywords.empty?)
+ if Util::gotoline_keyword?(q.keywords[0])
gotolines = Util::parse_gotoline(q.keywords)
match_lines = []
gotolines.each do |v|
@@ -32,19 +32,22 @@ def view(record, params, before)
match_lines << Grep::MatchLineResult.new(v[1] - 1, nil)
end
end
- @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html
+ # TestCdwebApp#t_view_gotoline
+ @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines, q.keywords).to_html
else
grep = Grep.new(record.content)
match_lines = grep.match_lines_and(q.keywords, is_sensitive, q.wide_match_range)
if match_lines.empty? && q.wide_match_range_empty?
- # 検索範囲を広げる
+ # Expand search range
match_lines = grep.match_lines_and(q.keywords, is_sensitive, 7)
end
- @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html
+ # TestCdwebApp#t_view_with_query
+ @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines, q.keywords).to_html
end
else
+ # TestCdwebApp#t_view_simple
@record_content = CodeRayWrapper.new(record.content, record.shortpath).to_html
end
View
4 lib/milkode/cdweb/lib/database.rb
@@ -131,6 +131,10 @@ def yaml_package_num
yaml_load.contents.size
end
+ def yaml_package(name)
+ yaml_load.find_name(name)
+ end
+
# @sample test/test_database.rb:43 TestDatabase#t_fileList
def fileList(base)
base_parts = base.split("/")
View
4 lib/milkode/cdweb/lib/search_contents.rb
@@ -49,7 +49,7 @@ def initialize(path, params, query, suburl)
# gotolineモード (test_cdstk.rb:55)
if @match_records.empty? && recommended_fuzzy_gotoline?
# 専用の Searcher を作成
- @searcher_fuzzy_gotoline = SearchFuzzyGotoLine.new(@path, @params, @q)
+ @searcher_fuzzy_gotoline = SearchFuzzyGotoLine.new(@path, @params, @q, @suburl)
# 結果をコピーする
@total_records = @searcher_fuzzy_gotoline.total_records
@@ -309,7 +309,7 @@ def result_match_record(match_group)
last_index = match_group[-1].match_line.index + NTH
match_lines = match_group.map{|m| m.match_line}
- coderay = CodeRayWrapper.new(record.content, record.shortpath, match_lines)
+ coderay = CodeRayWrapper.new(record.content, record.shortpath, match_lines, @q.keywords)
coderay.col_limit(COL_LIMIT)
coderay.set_range(first_index..last_index)
View
2  lib/milkode/cdweb/lib/search_fuzzy_gotoline.rb
@@ -122,7 +122,7 @@ def result_match_record(match_group)
last_index = match_group[-1].match_line.index + NTH
match_lines = match_group.map{|m| m.match_line}
- coderay = CodeRayWrapper.new(record.content, record.shortpath, match_lines)
+ coderay = CodeRayWrapper.new(record.content, record.shortpath, match_lines, @q.keywords)
coderay.col_limit(COL_LIMIT)
coderay.set_range(first_index..last_index)
View
2  lib/milkode/cdweb/lib/search_gotoline.rb
@@ -111,7 +111,7 @@ def result_match_record(match_group)
last_index = match_group[-1].match_line.index + NTH
match_lines = match_group.map{|m| m.match_line}
- coderay = CodeRayWrapper.new(record.content, record.shortpath, match_lines)
+ coderay = CodeRayWrapper.new(record.content, record.shortpath, match_lines, @q.keywords)
coderay.col_limit(COL_LIMIT)
coderay.set_range(first_index..last_index)
View
4 lib/milkode/cdweb/public/css/coderay-patch.css
@@ -1,6 +1,6 @@
/* for CodeRay */
-.CodeRay .highlight-line { background-color: #d0ff9c; }
-.CodeRay .select-line { background-color: #fff280; }
+.CodeRay .highlight-line { background-color: #f5f7f9; }
+.CodeRay .select-line { background-color: #d7e8fe; }
/* html_anchor */
.match-num { font-size: 13px; font-weight: bold; }
View
2  lib/milkode/cdweb/views/milkode.scss
@@ -271,6 +271,6 @@ label.ui-corner-all {
/* */
.highlight-filename {
- background-color: #d0ff9c;
+ background-color: #FFEE55;
}
View
69 lib/milkode/common/util.rb
@@ -243,26 +243,69 @@ def exist_command?(command)
end
def highlight_keywords(src, keywords, css_class)
- if keywords.empty?
- src
- else
- highlight_keywords_sub(src, keywords, css_class, 0)
+ # Init highlight_map
+ hightlight_map = Array.new(src.length, nil)
+
+ keywords.each do |keyword|
+ pos = 0
+
+ loop do
+ r = src.match(/#{keyword}/i, pos) do |m|
+ s = m.begin(0)
+ l = keyword.length
+ e = s+l
+ (s...e).each {|i| hightlight_map[i] = 1 }
+ pos = e
+ end
+
+ break if r.nil?
+ end
end
- end
- def highlight_keywords_sub(src, keywords, css_class, index)
- keyword = keywords[index]
+ # Delete html tag
+ index = 0
+ in_tag = false
+ src.each_char do |char|
+ in_tag = true if char == '<'
+ hightlight_map[index] = nil if in_tag
+ in_tag = false if char == '>'
+ index += 1
+ end
- array = src.split(keyword)
+ # Output
+ result = ""
- if index + 1 <= keywords.size
- array = array.map do |subsrc|
- highlight_keywords_sub(subsrc, keywords, css_class, index + 1)
+ index = 0
+ prev = nil
+ src.each_char do |char|
+ current = hightlight_map[index]
+
+ if prev.nil? && current
+ result += "<span class='#{css_class}'>"
+ elsif prev && current.nil?
+ result += "</span>"
end
+
+ result += char
+
+ index += 1
+ prev = current
end
-
- array.join("<span class='#{css_class}'>#{keyword}</span>")
+ result += "</span>" if prev
+
+ result
end
+
+ def github_repo(src)
+ if src.match(/\Agit@github\.com:(.*)\.git\Z/)
+ $1
+ elsif src.match(/\A\w+:\/\/github\.com\/(.*)\.git\Z/)
+ $1
+ else
+ nil
+ end
+ end
+
end
end
View
23 lib/milkode/database/updater.rb
@@ -1,13 +1,8 @@
# -*- coding: utf-8 -*-
-#
-# @file
-# @brief
-# @author ongaeshi
-# @date 2012/09/15
-
require 'milkode/database/groonga_database'
require 'milkode/common/grenfiletest'
require 'milkode/common/ignore_checker'
+require 'milkode/common/util'
require 'kconv'
module Milkode
@@ -27,12 +22,12 @@ def initialize(grndb, package_name)
def exec
# git pull
if @options[:update_with_git_pull]
- Dir.chdir(@package.directory) { system("git pull") }
+ Dir.chdir(@package.directory) { system("git pull") } if File.exist?(@package.directory)
end
# svn update
if @options[:update_with_svn_update]
- Dir.chdir(@package.directory) { system("svn update") }
+ Dir.chdir(@package.directory) { system("svn update") } if File.exist?(@package.directory)
end
# Add global .gitignore
@@ -50,16 +45,16 @@ def exec
# ctags
if @options[:update_with_ctags]
- Dir.chdir(@package.directory) { system("ctags -R") }
+ Dir.chdir(@package.directory) { system("ctags -R") } if File.exist?(@package.directory)
end
# ctags -e
if @options[:update_with_ctags_e]
- Dir.chdir(@package.directory) { system("ctags -R -e") }
+ Dir.chdir(@package.directory) { system("ctags -R -e") } if File.exist?(@package.directory)
end
- # 更新時刻の更新
- @grndb.packages.touch(@package_name, :updatetime)
+ # Update time
+ @grndb.packages.touch(@package_name, :updatetime) if @result.exist_update?
end
def set_package_ignore(ignore_setting)
@@ -124,6 +119,10 @@ def inc_add_count
def inc_update_count
@update_count += 1
end
+
+ def exist_update?
+ @add_count > 0 || @update_count > 0
+ end
end
class ResultAccumulator
View
23 milkode.gemspec
@@ -4,14 +4,14 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
- s.name = %q{milkode}
- s.version = "1.2.0"
+ s.name = "milkode"
+ s.version = "1.3.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["ongaeshi"]
- s.date = %q{2013-08-07}
- s.description = %q{Line based local source code search engine & grep-command & web-app.}
- s.email = %q{ongaeshi0621@gmail.com}
+ s.date = "2013-10-28"
+ s.description = "Line based local source code search engine & grep-command & web-app."
+ s.email = "ongaeshi0621@gmail.com"
s.executables = ["gmilk", "milk"]
s.extra_rdoc_files = [
"LICENSE.txt",
@@ -196,18 +196,17 @@ Gem::Specification.new do |s|
"test/test_wide_matcher.rb",
"test/test_yaml_file_wrapper.rb"
]
- s.homepage = %q{http://github.com/ongaeshi/milkode}
+ s.homepage = "http://github.com/ongaeshi/milkode"
s.licenses = ["MIT"]
s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.7}
- s.summary = %q{Line based local source code search engine & grep-command & web-app.}
+ s.rubygems_version = "1.8.23"
+ s.summary = "Line based local source code search engine & grep-command & web-app."
if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<termcolor>, [">= 1.2.0", "< 1.2.2"])
+ s.add_runtime_dependency(%q<termcolor>, ["< 1.2.2", ">= 1.2.0"])
s.add_runtime_dependency(%q<rroonga>, [">= 1.1.0"])
s.add_runtime_dependency(%q<rack>, [">= 1.5.2"])
s.add_runtime_dependency(%q<sinatra>, [">= 1.2.6"])
@@ -224,7 +223,7 @@ Gem::Specification.new do |s|
s.add_development_dependency(%q<sinatra-reloader>, [">= 0"])
s.add_development_dependency(%q<test-unit>, [">= 2.5.4"])
else
- s.add_dependency(%q<termcolor>, [">= 1.2.0", "< 1.2.2"])
+ s.add_dependency(%q<termcolor>, ["< 1.2.2", ">= 1.2.0"])
s.add_dependency(%q<rroonga>, [">= 1.1.0"])
s.add_dependency(%q<rack>, [">= 1.5.2"])
s.add_dependency(%q<sinatra>, [">= 1.2.6"])
@@ -242,7 +241,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<test-unit>, [">= 2.5.4"])
end
else
- s.add_dependency(%q<termcolor>, [">= 1.2.0", "< 1.2.2"])
+ s.add_dependency(%q<termcolor>, ["< 1.2.2", ">= 1.2.0"])
s.add_dependency(%q<rroonga>, [">= 1.1.0"])
s.add_dependency(%q<rack>, [">= 1.5.2"])
s.add_dependency(%q<sinatra>, [">= 1.2.6"])
View
36 test/test_cdweb_app.rb
@@ -37,6 +37,12 @@ def test_main
t_help
t_not_found
t_view_empty_file
+ t_view_with_query
+ t_view_gotoline
+ t_view_simple
+ t_search_contents
+ t_search_gotoline
+ t_search_fuzzy_gotoline
end
private
@@ -68,6 +74,36 @@ def t_view_empty_file
get '/home/a_project/empty.txt'
assert_equal 200, last_response.status # 空ファイルも表示出来るようにする
end
+
+ def t_view_with_query
+ get '/home/a_project/cdstk.rb?query=def'
+ assert_equal 200, last_response.status
+ end
+
+ def t_view_gotoline
+ get '/home/a_project/cdstk.rb?query=%2Fa_project%2Fcdstk.rb%3A9'
+ assert_equal 200, last_response.status
+ end
+
+ def t_view_simple
+ get '/home/a_project/cdstk.rb'
+ assert_equal 200, last_response.status
+ end
+
+ def t_search_contents
+ get '/home/?query=def'
+ assert_equal 200, last_response.status
+ end
+
+ def t_search_gotoline
+ get '/home/?query=%2Fa_project%2Fcdstk.rb%3A1&shead=package#n1'
+ assert_equal 200, last_response.status
+ end
+
+ def t_search_fuzzy_gotoline
+ get '/home/?query=g%3Aa_project+1&shead=package'
+ assert_equal 200, last_response.status
+ end
end
View
31 test/test_util.rb
@@ -27,10 +27,11 @@ def test_zip_extract
assert File.exist?('nodir_abc/c.txt')
end
- def test_root_entrylist
- assert_equal ['abc/'], Milkode::Util::root_entrylist('../data/abc.zip')
- assert_equal ['a.txt', 'b.txt', 'c.txt'], Milkode::Util::root_entrylist('../data/nodir_abc.zip')
- end
+ # Remove because fail test on single test
+ # def test_root_entrylist
+ # assert_equal ['abc/'], Milkode::Util::root_entrylist('../data/abc.zip')
+ # assert_equal ['a.txt', 'b.txt', 'c.txt'], Milkode::Util::root_entrylist('../data/nodir_abc.zip')
+ # end
def test_platform
if (Milkode::Util::platform_osx?)
@@ -122,8 +123,26 @@ def test_divide_shortpath
assert_equal 'to/a.txt', restpath
end
-
- def teardown
+ def test_highlight_keywords
+ assert_equal "stringstr", Milkode::Util::highlight_keywords("stringstr", [], 'attr')
+ assert_equal "<span class='attr'>str</span>ing", Milkode::Util::highlight_keywords("string", ["str"], 'attr')
+ assert_equal "<span class='attr'>str</span>ing<span class='attr'>str</span>", Milkode::Util::highlight_keywords("stringstr", ["str"], 'attr')
+ assert_equal "<span class='attr'>stri</span>ng<span class='attr'>str</span>", Milkode::Util::highlight_keywords("stringstr", ["str", "i", "s"], 'attr')
+ assert_equal "abc<span class='attr'>d</span>", Milkode::Util::highlight_keywords("abcd", ["d"], 'attr')
+ assert_equal "<span class='attr'>日本</span>語a<span class='attr'>bc</span>dで<span class='attr'>す</span>", Milkode::Util::highlight_keywords("日本語abcdです", ["bc", "日本", ""], 'attr')
+ assert_equal "<span><span class='attr'>span</span></span>", Milkode::Util::highlight_keywords("<span>span</span>", ["span"], 'attr')
+ end
+
+ def test_github_repo
+ assert_equal 'ongaeshi/firelink', Milkode::Util::github_repo('git@github.com:ongaeshi/firelink.git')
+ assert_equal 'ongaeshi/milkode' , Milkode::Util::github_repo('git@github.com:ongaeshi/milkode.git')
+ assert_equal 'ongaeshi/milkode' , Milkode::Util::github_repo('git://github.com/ongaeshi/milkode.git')
+ assert_equal 'ongaeshi/milkode' , Milkode::Util::github_repo('https://github.com/ongaeshi/milkode.git')
+ assert_equal 'ongaeshi/milkode' , Milkode::Util::github_repo('http://github.com/ongaeshi/milkode.git')
+ assert_equal nil , Milkode::Util::github_repo('https://ongaeshi.me/ongaeshi/milkode.git')
+ end
+
+ def teardown
teardown_custom(true)
# teardown_custom(false)
end
Please sign in to comment.
Something went wrong with that request. Please try again.