Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents 7cb152f + 8ba03ed commit 1e445f9e3b9d7becb7d84f2d661f299a2e554e5b @ongaeshi committed Aug 26, 2011
View
@@ -0,0 +1,70 @@
+=== 0.2.2 2011/08/26
+
+* ファイル内grepを追加
+ * マッチ行へのアンカーリンクが画面上部に表示されるように
+* 駆け上がり検索を検索
+ * トピックパス(ディレクトリのリンク)をクリックした時、検索クエリーを引き継ぐように
+ * 検索ワード入力→トピックパスクリックで検索範囲の変更が可能に
+ * その都度「検索」ボタンを押さなくても、テキスト入力→トピックパスクリック、で入力した新しいキーワードで再検索出来る。
+* トピックパスの先頭に"home"を追加
+ * milkode/lib/file.rb -> home/milkode/lib/file.rb
+* 検索結果ファイル名は相対パスで表示する
+* [ファイル一覧] ボタンを追加
+* 検索ワードを入力せず検索(Enterを押す)と、エラーになる問題を修正 (thanks ryo)
+
+=== 0.2.1 2011/08/12
+
+Milkode レポジトリがバージョンアップしました。
+レポジトリをリビルドして下さい。
+
+ milk rebuild
+
+* AutoPagerizeのサポート (thanks awasira)
+* 'documents' groongaテーブル形式の変更, 'Groonga::Array -> Groonga:: Hash'.
+ * 'milk update' の高速化 (thanks kou)
+ * Issues#6 CentOS 5.5 (32bit) in 'milk update' fails (thanks yoshikaw)
+
+=== 0.2.0 2011/08/10
+
+* Issues#4 Bug fix, wrong display of search results. (thanks rakkoyaku, ryo)
+* Issues#5 Delete GoogleAnalytics code. (thanks vividtone)
+
+=== 0.1.9 2011/08/05
+
+* Bug fix, can't move 'milk web'.
+
+=== 0.1.8, 0.1.7 2011/08/04
+
+* archive-zip patch for Ruby1.9.2.
+
+=== 0.1.6 2011/08/03
+
+* Bug fix, faild 'milk init' for Ubunts. (thanks kumonopanya, and maroekun)
+
+=== 0.1.5 2011/08/02
+
+* Compatibility Ruby 1.9.2p290.
+
+=== 0.1.4 2011/08/01
+
+* To act reasonably even if it fails to require 'readline'.
+
+=== 0.1.3 2011/07/30
+
+* Change Icon.
+* Change web-app design.
+* Change text, lib/milkode/cdweb/views/help.haml.
+
+=== 0.1.2 2011/07/26
+
+* milk web --host, default value "127.0.0.1" (for Windows).
+* to update all packages at 'milk update' (no arg).
+
+=== 0.1.1 2011/07/25
+
+* Add comment.
+
+=== 0.1.0 2011/07/25
+
+* 1st release.
+
View
@@ -1,3 +1,17 @@
+=== 0.2.2 2011/08/26
+
+* Add a file grep.
+ * To be displayed at the top of the anchor link to match the line.
+* Implement search 'topic path'.
+ * Breadcrumbs (link directory) when you click, to take over the search query.
+ * 'Enter search words -> click breadcrumbs', search scope can be changed.
+ * Each time "search" without pressing any button on a new keyword search can be entered in 'the text entry → click breadcrumbs'.
+* Add breadcrumbs at the top "home".
+ * milkode/lib/file.rb -> home/milkode/lib/file.rb
+* Results will be displayed in the file name relative path.
+* Add [List of files] button
+* Search without entering a search word (hit Enter), and fixed the problem that the error (thanks ryo)
+
=== 0.2.1 2011/08/12
Milkode repository is version up.
View
@@ -32,6 +32,7 @@ Jeweler::Tasks.new do |gem|
gem.add_runtime_dependency 'archive-zip', '>=0.3.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'
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
# gem.add_development_dependency 'rspec', '> 1.2.3'
View
@@ -1 +1 @@
-0.2.1
+0.2.2
View
@@ -6,5 +6,5 @@
require 'rubygems'
require 'milkode/cdstk/cli_cdstk'
-Version = "0.2.1"
+Version = "0.2.2"
Milkode::CLI_Cdstk.execute(STDOUT, ARGV)
View
@@ -18,23 +18,23 @@
set :haml, :format => :html5
get '/' do
- @version = "0.2.1"
+ @version = "0.2.2"
@package_num = Database.instance.fileList('').size
@file_num = Database.instance.fileNum
haml :index
end
-post '/home*' do |path|
- path = path.sub(/^\//, "")
-
+post '/search*' do
+ path = unescape(params[:pathname])
+
case params[:shead]
when 'all'
- path = ""
+ path = "/home"
when 'package'
- path = path.split('/')[0]
+ path = path.split('/')[0,3].join('/')
end
- redirect Mkurl.new("home/#{path}", params).inherit_query_shead
+ redirect Mkurl.new("#{path}", params).inherit_query_shead
end
get '/home*' do |path|
@@ -45,10 +45,10 @@
if (record)
view(record, params, before)
else
- unless (params[:query])
- filelist(path, params, before)
- else
+ if (params[:query] and !params[:query].empty?)
search(path, params, before)
+ else
+ filelist(path, params, before)
end
end
end
@@ -79,16 +79,22 @@ def create_form(path, query, shead)
# こっちにすると'検索'ボタンを押した時に新しくウィンドウが開く
# <form action='' target='_blank' method='post'>
<<EOF
- <form action='' method='post'>
+ <script type="text/javascript">
+ function set_pathname() {
+ document.searchform.pathname.value = location.pathname;
+ }
+ </script>
+ <form name="searchform" action='/search' method='post'>
<p>
<input name='query' size='60' type='text' value='#{query}' />
- <input type='submit' value='検索'><br></input>
+ <input type='submit' value='検索' onclick='set_pathname()'><br></input>
#{create_radio('all', shead)}
<label>全体を検索</label>
#{create_radio('package', shead)}
<label> #{package_name(path)} 以下</label>
#{create_radio('directory', shead)}
<label> #{current_name(path)} 以下</label>
+ <input name='pathname' type='hidden' value=''></input>
</p>
</form>
EOF
@@ -99,21 +105,27 @@ def create_radio(value, shead)
"<input name='shead' type='radio' value='#{value}' #{str}/>"
end
- def create_headmenu(path, query)
- # href = "#{request.path_info}?'#{request.query_string}"
- # href = '/home/rack-1.3.0/lib/rack/handler/cgi.rb?shead=directory'
+ def create_headmenu(path, query, flistpath = '')
href = Mkurl.new('/home/' + path, params).inherit_query_shead
+ flist = File.join("/home/#{path}", flistpath)
<<EOF
- <a href="/home" class="headmenu">全てのパッケージ</a>
- <a href="#{href}" class="headmenu" onclick="window.open('#{href}'); return false;">新しい検索</a>
+ #{headicon('go-home-5.png')} <a href="/home" class="headmenu">全てのパッケージ</a>
+ #{headicon('document-new-4.png')} <a href="#{href}" class="headmenu" onclick="window.open('#{href}'); return false;">新しい検索</a>
+ #{headicon('directory.png')} <a href="#{flist}" class="headmenu">ファイル一覧</a>
EOF
end
+ def headicon(name)
+ "<img alt='' style='vertical-align:center; border: 0px; margin: 0px;' src='/images/#{name}'>"
+ end
+
def topic_path(path, params)
- href = '/home'
- path.split('/').map {|v|
+ href = ''
+ path = File.join('home', path)
+
+ path.split('/').map_with_index {|v, index|
href += '/' + v
- "<a href='#{Mkurl.new(href, params).inherit_shead}'>#{v}</a>"
+ "<a id='topic_#{index}' href='#{Mkurl.new(href, params).inherit_query_shead}' onclick='topic_path(\"topic_#{index}\");'>#{v}</a>"
}.join('/')
end
@@ -134,3 +146,12 @@ def filelist_title(path)
end
end
+class Array
+ def map_with_index!
+ each_with_index do |e, idx| self[idx] = yield(e, idx); end
+ end
+
+ def map_with_index(&block)
+ dup.map_with_index!(&block)
+ end
+end
@@ -8,6 +8,7 @@
require 'rubygems'
require 'coderay'
require 'coderay/helpers/file_type'
+require 'nokogiri'
module Milkode
class CodeRayWrapper
@@ -42,11 +43,27 @@ def to_html
:highlight_lines => @highlight_lines,
:line_number_start => @line_number_start
)
-
milkode_ornament(html)
end
+ def to_html_anchor
+ html = CodeRay.scan(@content, file_type).
+ html(
+ :wrap => nil,
+ :line_numbers => :table,
+ :css => :class,
+ :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
+ end
+
def milkode_ornament(html)
+ # @todo nokogiri使う?
a = html.split("\n")
line_number = @line_number_start
@@ -88,6 +105,28 @@ def line_attr(no)
r << "class=\"highlight-line\"" if @highlight_lines.include?(no)
r.join(" ")
end
+
+ ANCHOR_OFFSET = 3
+
+ def create_anchorlink(str)
+ if @highlight_lines
+ lines = str.split("\n")
+
+ codes = @highlight_lines.map {|no|
+ " <tr><td class=\"line_numbers\">#{no}</td> <td class=\"code\"><pre><a href=\"##{[no - ANCHOR_OFFSET, 1].max}\">#{lines[no - 1]}</a></pre></td> </tr>"
+ }.join("\n")
+
+ <<EOF
+<span class="match-num">#{@highlight_lines.size} results</span>
+<table class="CodeRay anchor-table">
+#{codes}
+</table>
+<p>
+EOF
+ else
+ ""
+ end
+ end
end
end
@@ -21,7 +21,7 @@ def view(record, params, before)
if (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
+ @record_content = CodeRayWrapper.new(record.content, record.shortpath, match_lines).to_html_anchor
else
@record_content = CodeRayWrapper.new(record.content, record.shortpath).to_html
end
@@ -57,21 +57,23 @@ def selectAll(offset = 0, limit = -1)
# マッチ数
total_records = table.size
+
+ # @todo ここが速度低下の原因?と思ったけど、ここは全て選択の部分だけか・・・
# 2010/10/29 ongaeshi
# 本当はこのようにgroongaAPIでソートしたいのだが上手くいかなかった
# # ファイル名順にソート
# records = table.sort([{:key => "shortpath", :order => "descending"}],
- # :offset => page * limit,
+ # :offset => offset,
# :limit => limit)
-
+
# ソート
if (limit != -1)
records = table.records.sort_by{|record| record.shortpath.downcase }[offset, limit]
else
records = table.records.sort_by{|record| record.shortpath.downcase }[offset..limit]
end
-
+
return records, total_records
end
@@ -8,6 +8,7 @@
require 'milkode/cdweb/lib/query'
require 'milkode/cdweb/lib/grep'
require 'milkode/cdweb/lib/mkurl'
+require 'milkode/common/util'
module Milkode
class SearchContents
@@ -23,6 +24,7 @@ class SearchContents
# NTH = 3 # 表示範囲
def initialize(path, params, query)
+ @path = path
@params = params
@q = query
@page = params[:page].to_i || 0
@@ -95,7 +97,7 @@ def result_match_record(match_record)
coderay.set_range(first_index..last_index)
<<EOS
- <dt class='result-record'><a href='#{"/home/" + record_link(record) + "##{coderay.line_number_start}"}'>#{record.shortpath}</a></dt>
+ <dt class='result-record'><a href='#{"/home/" + record_link(record) + "##{coderay.line_number_start}"}'>#{Util::relative_path record.shortpath, @path}</a></dt>
<dd>
#{coderay.to_html}
</dd>
@@ -8,6 +8,7 @@
require 'milkode/cdweb/lib/query'
require 'milkode/cdweb/lib/mkurl'
require 'milkode/cdweb/lib/command'
+require 'milkode/common/util'
module Milkode
class SearchFiles
@@ -16,6 +17,7 @@ class SearchFiles
DISP_NUM = 100 # 1ページの表示数
def initialize(path, params, query)
+ @path = path
@params = params
@q = query
@@ -77,7 +79,7 @@ def pagination_span(content)
def result_record(record)
<<EOS
- <dt class='result-file'>#{file_or_dirimg(true)}<a href='#{"/home/" + record_link(record)}'>#{record.shortpath}</a></dt>
+ <dt class='result-file'>#{file_or_dirimg(true)}<a href='#{"/home/" + record_link(record)}'>#{Util::relative_path record.shortpath, @path}</a></dt>
EOS
end
@@ -0,0 +1,10 @@
+/* for CodeRay */
+.CodeRay .highlight-line { background-color: #d0ff9c; }
+
+/* html_anchor */
+.match-num { font-size: 13px; font-weight: bold; }
+.anchor-table { background-color: #ffffff; }
+.anchor-table .line_numbers { background-color: #D0FF9C; }
+.anchor-table td { border: 1px solid silver; font-size:13px; }
+.anchor-table a { color: #000000; text-decoration:none; }
+.anchor-table a:hover { text-decoration:underline; background-color: #F0F0F0; }
Oops, something went wrong.

0 comments on commit 1e445f9

Please sign in to comment.