Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
ongaeshi committed Oct 28, 2013
2 parents 2971267 + 62d88d8 commit dac874905ba45822c4125d407439cfe9f0df9049
View
@@ -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
@@ -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
@@ -1 +1 @@
-1.2.0
+1.3.0
View
@@ -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
@@ -6,5 +6,5 @@
require 'rubygems'
require 'milkode/cli'
-Version = "1.2.0"
+Version = "1.3.0"
Milkode::CLI.start(ARGV)
View
@@ -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
@@ -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
@@ -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)
@@ -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
@@ -23,28 +23,31 @@ 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|
if v[0][0][1..-1] == record.shortpath
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
@@ -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("/")
@@ -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)
@@ -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)
@@ -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)
@@ -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; }
@@ -271,6 +271,6 @@ label.ui-corner-all {
/* */
.highlight-filename {
- background-color: #d0ff9c;
+ background-color: #FFEE55;
}
View
@@ -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
Oops, something went wrong.

0 comments on commit dac8749

Please sign in to comment.