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 1e445f9e3b9d7becb7d84f2d661f299a2e554e5b 2 parents 7cb152f + 8ba03ed
ongaeshi authored
70 HISTORY.ja.rdoc
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.
+
14 HISTORY.rdoc
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.
1  Rakefile
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'
2  VERSION
View
@@ -1 +1 @@
-0.2.1
+0.2.2
2  bin/milk
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)
61 lib/milkode/cdweb/app.rb
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
41 lib/milkode/cdweb/lib/coderay_wrapper.rb
View
@@ -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
2  lib/milkode/cdweb/lib/command.rb
View
@@ -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
8 lib/milkode/cdweb/lib/database.rb
View
@@ -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
4 lib/milkode/cdweb/lib/search_contents.rb
View
@@ -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>
4 lib/milkode/cdweb/lib/search_files.rb
View
@@ -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
10 lib/milkode/cdweb/public/css/coderay-patch.css
View
@@ -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; }
5 lib/milkode/cdweb/public/css/gren.css → lib/milkode/cdweb/public/css/milkode.css
View
@@ -66,11 +66,6 @@ font.version {
font-size: 35%;
}
-span.highlight-line {
- background-color: #d0ff9c;
- /*background-color: #FFFF55;*/
-}
-
a.headmenu {
font-size: 40%;
font-weight: normal;
BIN  lib/milkode/cdweb/public/images/document-new-4.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  lib/milkode/cdweb/public/images/go-home-5.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 lib/milkode/cdweb/public/js/milkode.js
View
@@ -0,0 +1,36 @@
+//
+// @brief
+// @author ongaeshi
+// @date 2011/08/24
+
+function replace_query_param(url, value)
+{
+ var url_s = url.split("?");
+
+ if (url_s.length <= 1) {
+ return url + "?query=" + value;
+ } else {
+ var params = url_s[1].split("&");
+ var found_query = false;
+
+ for (var i = 0; i < params.length; i++) {
+ if (params[i].search(/^query=/) != -1) {
+ params[i] = params[i].replace(/^query=.*/, "query=" + value);
+ found_query = true;
+ }
+ }
+
+ if (!found_query)
+ params.unshift("query=" + value);
+
+ return url_s[0] + "?" + params.join("&");
+ }
+}
+
+function topic_path(id)
+{
+ var url = document.getElementById(id).href;
+ url = replace_query_param(url, document.searchform.query.value);
+ document.getElementById(id).href = url;
+}
+
3  lib/milkode/cdweb/views/index.haml
View
@@ -3,10 +3,11 @@
%h1 <a href="/"><img src="/images/MilkodeIcon135.png" alt="milkode-icon" border="0" height="135px"/></a> Milkode <font class="version">#{@version}</font>
.content
- %form(method="post" action="home")
+ %form(method="post" action="/search")
%p
%input(name="query" type="text" size="60")
%input(type="submit" value="検索")
+ %input(name='pathname' type='hidden' value='/home')
.footer_home
<a href="/home">#{@package_num}</a>のパッケージ<br>
4 lib/milkode/cdweb/views/layout.haml
View
@@ -4,8 +4,10 @@
%head
%meta(charset='utf-8')
%title= [@title, 'Milkode'].compact.join(' - ')
- %link(rel="stylesheet" href="/css/gren.css" type="text/css" media="all")
+ %link(rel="stylesheet" href="/css/milkode.css" type="text/css" media="all")
%link(rel="stylesheet" href="/css/coderay.css" type="text/css" media="all")
+ %link(rel="stylesheet" href="/css/coderay-patch.css" type="text/css" media="all")
+ %script(type='text/javascript' src='/js/milkode.js')
%body
-# %header
2  lib/milkode/cdweb/views/view.haml
View
@@ -2,7 +2,7 @@
%h1
<a href="/"><img src="/images/MilkodeIcon135.png" alt="milkode-icon-mini" border="0" height="75px"/></a>
Milkode
- = create_headmenu(@path, params)
+ = create_headmenu(@path, params, '..')
.content
= create_form(@path, params[:query], params[:shead])
7 lib/milkode/common/util.rb
View
@@ -3,6 +3,7 @@
require 'rubygems'
require 'milkode/common/archive-zip'
require 'fileutils'
+require 'pathname'
module Milkode
module Util
@@ -41,6 +42,12 @@ def root_entrylist(filename)
list
end
+
+ def relative_path(path, basedir)
+ path = Pathname.new(path)
+ basedir = Pathname.new(basedir)
+ path.relative_path_from(basedir)
+ end
end
end
7 test/test_coderay_wrapper.rb
View
@@ -13,8 +13,11 @@
module Milkode
class TestCodeRayWrapper < Test::Unit::TestCase
def test_basic
- assert_lines JS_SHORT_HTML, CodeRayWrapper.new(JS_SHORT_CODE, "console-dir.js").to_html
- assert_lines JS_HTML , CodeRayWrapper.new(JS_CODE, "console-dir.js").to_html
+ CodeRayWrapper.new(JS_SHORT_CODE, "console-dir.js").to_html
+ CodeRayWrapper.new(JS_CODE, "console-dir.js").to_html
+
+ CodeRayWrapper.new(JS_SHORT_CODE, "console-dir.js").to_html_anchor
+ CodeRayWrapper.new(JS_CODE, "console-dir.js").to_html_anchor
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.