Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'develop'

  • Loading branch information...
commit c35eaa831d8622d0ae35d992d3879d68b5d43410 2 parents 4c22f01 + 6df1a89
@ongaeshi authored
Showing with 926 additions and 299 deletions.
  1. +2 −1  .travis.yml
  2. +12 −11 Gemfile
  3. +41 −1 HISTORY.ja.rdoc
  4. +28 −1 HISTORY.rdoc
  5. +1 −1  VERSION
  6. +1 −1  bin/gmilk
  7. +1 −1  bin/milk
  8. +15 −1 lib/milkode/cdstk/cdstk.rb
  9. +16 −0 lib/milkode/cdstk/package.rb
  10. +72 −9 lib/milkode/cdweb/app.rb
  11. +25 −55 lib/milkode/cdweb/cli_cdweb.rb
  12. +14 −0 lib/milkode/cdweb/lib/database.rb
  13. +30 −0 lib/milkode/cdweb/lib/info_home.rb
  14. +83 −0 lib/milkode/cdweb/lib/info_package.rb
  15. +18 −0 lib/milkode/cdweb/lib/package_list.rb
  16. +93 −8 lib/milkode/cdweb/public/css/milkode.css
  17. BIN  lib/milkode/cdweb/public/images/info-big.png
  18. BIN  lib/milkode/cdweb/public/images/info.png
  19. BIN  lib/milkode/cdweb/public/images/milkode-directpath-copy.gif
  20. BIN  lib/milkode/cdweb/public/images/milkode-star.png
  21. +35 −5 lib/milkode/cdweb/public/js/milkode.js
  22. +9 −1 lib/milkode/cdweb/views/filelist.haml
  23. +1 −1  lib/milkode/cdweb/views/header_menu.haml
  24. +70 −23 lib/milkode/cdweb/views/help.haml
  25. +14 −0 lib/milkode/cdweb/views/info_home.haml
  26. +13 −0 lib/milkode/cdweb/views/info_package.haml
  27. +6 −2 lib/milkode/cdweb/views/packages.haml
  28. +13 −7 lib/milkode/cdweb/views/search.haml
  29. +2 −0  lib/milkode/cdweb/views/search_form.haml
  30. +9 −1 lib/milkode/cdweb/views/view.haml
  31. +3 −2 lib/milkode/cli.rb
  32. +0 −10 lib/milkode/common/archive-zip.rb
  33. +6 −2 lib/milkode/common/util.rb
  34. +4 −0 lib/milkode/database/document_table.rb
  35. +4 −0 lib/milkode/database/package_table.rb
  36. +0 −43 lib/milkode/findgrep/result.rb
  37. +48 −36 lib/milkode/grep/cli_grep.rb
  38. +53 −0 lib/milkode/grep/fast_gotoline.rb
  39. +42 −56 lib/milkode/{findgrep → grep}/findgrep.rb
  40. +63 −0 lib/milkode/grep/findgrep_option.rb
  41. +23 −12 milkode.gemspec
  42. +3 −1 test/test_cli.rb
  43. +1 −1  test/test_cli_grep.rb
  44. +2 −2 test/test_findgrep.rb
  45. +48 −4 test/test_milkode_yaml.rb
  46. +2 −0  test/test_query.rb
View
3  .travis.yml
@@ -7,8 +7,9 @@ notifications:
- ongaeshi0621@gmail.com
rvm:
- - 1.8.7
+ # - 1.8.7
- 1.9.3
+ - 2.0.0
before_install:
- curl https://raw.github.com/groonga/groonga/master/data/travis/setup.sh | sh
View
23 Gemfile
@@ -4,17 +4,17 @@ source "http://rubygems.org"
# Example:
# gem "activesupport", ">= 2.3.5"
# gemspec
-gem 'termcolor','>= 1.2.0', '< 1.2.2'
-gem 'rroonga','>= 1.1.0'
-gem 'rack','>=1.3.4', '~> 1.4.0'
-gem 'sinatra', '>=1.2.6'
-gem 'launchy', '>=0.3.7'
-gem 'coderay', '>=1.0.5'
-gem 'thin', '>=1.2.10'
-gem 'archive-zip', '>=0.4.0'
-gem 'haml', '>=3.1.2'
-gem 'sass', '>=3.1.3'
-gem 'thor', '~> 0.15.0'
+gem 'termcolor' , '>= 1.2.0' , '< 1.2.2'
+gem 'rroonga' , '>= 1.1.0'
+gem 'rack' , '>= 1.5.2'
+gem 'sinatra' , '>= 1.2.6'
+gem 'launchy' , '>= 0.3.7'
+gem 'coderay' , '>= 1.0.5'
+gem 'thin' , '>= 1.2.10'
+gem 'archive-zip' , '>= 0.4.0'
+gem 'haml' , '>= 3.1.2'
+gem 'sass' , '>= 3.1.3'
+gem 'thor' , '>= 0.18.1'
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
@@ -23,4 +23,5 @@ group :development do
gem 'jeweler'
gem 'rack-test'
gem 'sinatra-reloader'
+ gem 'test-unit' , '>= 2.5.4'
end
View
42 HISTORY.ja.rdoc
@@ -1,3 +1,44 @@
+=== 1.0.0.rc.1 2013/05/05
+
+* milk web
+ * お気に入りリスト
+ * お気に入りを付けたパッケージにすぐアクセス出来る
+ * ☆マークをクリックでwebアプリからも設定が可能に
+
+ * 統計情報ボタンの設置
+ * ファイル数、行数、言語別割合の表示をWebインターフェースで
+
+ * 「新規タブ」ボタンを設置
+ * タブを開きながら検索
+
+ * help.haml
+ * 全体的にリニューアル
+ * 'w:' オプションについて追記
+
+* gmilk
+ * 依存関係を整理して、起動時間の高速化
+ * ダイレクトパス検索('gmilk /path/to/file:5')に関してはさらに高速化
+ * gmilk -d が正しく動いていない問題を修正
+
+* milk
+ * milk fav --sync-yaml を追加
+ * webアプリ経由のお気に入り設定をyamlに取り込む
+
+* etc
+ * Ruby2.0.0 に対応
+ * test/test_milkode_yaml.rb が動かない問題を修正: Yaml#dumpの取得形式が変わった
+ * Gemfile更新: test-unit >= 2.5.4
+ * .travis.yml に Ruby2.0 を追加
+
+ * Gemfile
+ * 'thor 0.18.1' に対応
+ * 'rack 1.5.2' に対応
+
+ * ファイル構造の整理 : findgrep/findgrep.rb -> grep/findgrep.rb
+
+* バグ修正
+ * Issues#47 add meta tag for favicon (thanks y-ken)
+
=== 0.9.9 2013/02/26
* ワイド範囲検索のサポート
@@ -13,7 +54,6 @@
* export MILKODE_SINATRA_RELOADER=1
* Delete 'milkode/cdweb/app_error.rb'
- * Recommend 'RACK_ENV=production'
=== 0.9.8 2013/02/27
View
29 HISTORY.rdoc
@@ -1,3 +1,31 @@
+=== 1.0.0.rc.1 2013/05/05
+
+* milk web
+ * Add favorite-list
+ * Add info
+ * Add 「newtab」button
+ * Renewal help.haml
+
+* gmilk
+ * Fast startup time
+ * Fast directpath search('gmilk /path/to/file:5') more
+ * Fix 'gmilk -d'
+
+* milk
+ * Add 'milk fav --sync-yaml'
+
+* etc
+ * Support Ruby2.0.0
+
+ * Gemfile
+ * Support 'thor 0.18.1'
+ * Support 'rack 1.5.2'
+
+ * findgrep/findgrep.rb -> grep/findgrep.rb
+
+* Bug fix
+ * Issues#47 add meta tag for favicon (thanks y-ken)
+
=== 0.9.9 2013/02/26
* Suppor wide range search
@@ -5,7 +33,6 @@
* Support sinatra-reloader
* export MILKODE_SINATRA_RELOADER=1
* Delete 'milkode/cdweb/app_error.rb'
- * Recommend 'RACK_ENV=production'
=== 0.9.8 2013/02/27
View
2  VERSION
@@ -1 +1 @@
-0.9.9
+1.0.0.rc.1
View
2  bin/gmilk
@@ -6,5 +6,5 @@
require 'rubygems'
require 'milkode/grep/cli_grep'
-Version = "0.9.9"
+Version = "1.0.0.rc.1"
Milkode::CLI_Grep.execute(STDOUT, ARGV)
View
2  bin/milk
@@ -6,5 +6,5 @@
require 'rubygems'
require 'milkode/cli'
-Version = "0.9.9"
+Version = "1.0.0.rc.1"
Milkode::CLI.start(ARGV)
View
16 lib/milkode/cdstk/cdstk.rb
@@ -428,7 +428,21 @@ def list(args, options)
def fav(args, options)
db_open
- if (args.empty?)
+ if (options[:sync_yaml])
+ is_dirty = false
+
+ @yaml.contents.each do |package|
+ db_fav = @grndb.packages.fav?(package.name)
+ if package.fav? != db_fav
+ @out.puts "#{package.name} : #{package.fav?} -> #{db_fav}"
+ package.set_fav(db_fav)
+ is_dirty = true
+ end
+ end
+
+ @yaml.save if is_dirty
+
+ elsif (args.empty?)
@out.puts @grndb.packages.favs.map{|r| r.name}
else
is_dirty = false
View
16 lib/milkode/cdstk/package.rb
@@ -69,6 +69,22 @@ def ==(rhs)
name == rhs.name && directory == rhs.directory && ignore == rhs.ignore
end
+ def fav?
+ options[:fav] == true
+ end
+
+ def set_fav(value)
+ if value
+ if @hash['options']
+ @hash['options'][:fav] = true
+ else
+ @hash['options'] = {:fav => true}
+ end
+ else
+ @hash['options'].delete(:fav) if @hash['options']
+ end
+ end
+
private
def normalize
View
81 lib/milkode/cdweb/app.rb
@@ -15,19 +15,21 @@
require 'haml'
$LOAD_PATH.unshift '../..'
+require 'milkode/common/util'
require 'milkode/cdweb/lib/database'
require 'milkode/cdweb/lib/command'
require 'milkode/cdweb/lib/mkurl'
require 'milkode/cdweb/lib/web_setting'
require 'milkode/cdweb/lib/package_list'
-require 'milkode/common/util'
+require 'milkode/cdweb/lib/info_home'
+require 'milkode/cdweb/lib/info_package'
set :haml, :format => :html5
get '/' do
if Database.validate?
@setting = WebSetting.new
- @version = "0.9.9"
+ @version = "1.0.0.rc.1"
@package_num = Database.instance.yaml_package_num
@file_num = Database.instance.totalRecords
@@ -85,6 +87,10 @@ def package_path(path)
result = Database.instance.update(params[:name])
update_result_str(result, before)
end
+ when 'favorite'
+ Database.instance.set_fav(params[:name], params[:favorited] == 'true')
+ @package_list = PackageList.new(Database.instance.grndb)
+ "お気に入り: " + @package_list.favorite_list({})
end
end
@@ -92,6 +98,7 @@ def package_path(path)
before = Time.now
path = path.sub(/^\//, "")
record = Database.instance.record(path)
+ @package_list = PackageList.new(Database.instance.grndb)
if path.empty?
if (params[:query] and !params[:query].empty?)
@@ -112,9 +119,37 @@ def package_path(path)
get %r{/help} do
@setting = WebSetting.new
+ @path = ""
haml :help
end
+get '/info' do
+ obj = InfoHome.new
+
+ @setting = WebSetting.new
+ @path = ""
+ @summary_content = obj.summary_content
+ @record_content = obj.record_content
+
+ haml :info_home
+end
+
+get '/info/:package' do
+ before = Time.now
+
+ name = params[:package]
+ obj = InfoPackage.new(name)
+
+ @setting = WebSetting.new
+ @path = name
+ @summary_content = obj.summary_content
+ @plang_content = obj.plang_content
+
+ @elapsed = Time.now - before
+
+ haml :info_package
+end
+
# -- helper function --
helpers do
@@ -127,8 +162,12 @@ def escape_path(src)
end
# -- utility --
- def link(query)
- "<a href='#{'/home?query=' + escape_url(query)}'>#{query}</a>"
+ def link(query, text = nil)
+ if text.nil?
+ "<a href='#{'/home?query=' + escape_url(query)}'>#{query}</a>"
+ else
+ "<a href='#{'/home?query=' + escape_url(query)}'>#{text}</a>"
+ end
end
def create_select_shead(value)
@@ -187,12 +226,15 @@ def create_headmenu(path, query, flistpath = '')
modal_body = "#{package_name} を更新しますか?"
end
+ info_path = "/info"
+ info_path = File.join(info_path, package_name) if package_name != ""
+
<<EOF
- #{headicon('go-home-5.png')} <a href="/home" class="headmenu">ホーム</a>
- #{headicon('document-new-4.png')} <a href="#{href}" class="headmenu" onclick="window.open(document.URL); return false;">タブを複製</a>
- #{headicon('directory.png')} <a href="#{flist}" class="headmenu">ディレクトリ</a>
- #{headicon('view-refresh-4.png')} <a href="#updateModal" class="headmenu" data-toggle="modal">パッケージを更新</a>
- #{headicon('help.png')} <a href="/help" class="headmenu">ヘルプ</a>
+ #{headicon('go-home-5.png')}<a href="/home" class="headmenu">ホーム</a>&nbsp;
+ #{headicon('directory.png')}<a href="#{flist}" class="headmenu">ディレクトリ</a>
+ #{headicon('view-refresh-4.png')}<a href="#updateModal" class="headmenu" data-toggle="modal">パッケージを更新</a>&nbsp;
+ #{headicon('info.png')}<a href="#{info_path}" class="headmenu">統計情報</a>&nbsp;
+ #{headicon('help.png')}<a href="/help" class="headmenu">ヘルプ</a>
<div id="updateModal" class="modal hide fade">
<div class="modal-header">
@@ -227,6 +269,16 @@ def create_headmenu(path, query, flistpath = '')
EOF
end
+ def create_favorite_list(package_list)
+ <<EOF
+ <div class="favorite_list">
+ お気に入り:
+ #{package_list.favorite_list(params)}
+ </div>
+ </div>
+EOF
+ end
+
def headicon(name)
"<img alt='' style='vertical-align:center; border: 0px; margin: 0px;' src='/images/#{name}'>"
end
@@ -295,6 +347,17 @@ def update_result_str(result, before)
"#{r.join(', ')} (#{Time.now - before} sec)"
end
+ def favstar(path)
+ pname = package_name(path)
+
+ if pname != "root"
+ classes = Database.instance.fav?(pname) ? "star favorited" : "star"
+ "<a href=\"javascript:\" class=\"#{classes}\" milkode-package-name=\"#{pname}\">Favorite Me</a>"
+ else
+ ""
+ end
+ end
+
# .search-summary に追加情報を表示したい時はこの関数をオーバーライド
def search_summary_hook(path)
""
View
80 lib/milkode/cdweb/cli_cdweb.rb
@@ -5,59 +5,6 @@
require 'optparse'
require 'milkode/cdweb/lib/database'
-module Rack
- class Server
- def start
- if options[:warn]
- $-w = true
- end
-
- if includes = options[:include]
- $LOAD_PATH.unshift(*includes)
- end
-
- if library = options[:require]
- require library
- end
-
- if options[:debug]
- $DEBUG = true
- require 'pp'
- p options[:server]
- pp wrapped_app
- pp app
- end
-
- # Touch the wrapped app, so that the config.ru is loaded before
- # daemonization (i.e. before chdir, etc).
- wrapped_app
-
- daemonize_app if options[:daemonize]
- write_pid if options[:pid]
-
- trap(:INT) do
- if server.respond_to?(:shutdown)
- server.shutdown
- else
- exit
- end
- end
-
- server.run wrapped_app, options do
- if (options[:LaunchBrowser])
- host = options[:Host] || options[:BindAddress] # options[:BindAddress] for WEBrick
-
- if (options[:LaunchURL])
- Launchy.open("http://#{host}:#{options[:Port]}#{options[:LaunchURL]}")
- else
- Launchy.open("http://#{host}:#{options[:Port]}")
- end
- end
- end
- end
- end
-end
-
module Milkode
class CLI_Cdweb
def self.execute(stdout, argv)
@@ -104,13 +51,36 @@ def self.execute_with_options(stdout, options)
# サーバースクリプトのある場所へ移動
FileUtils.cd(File.dirname(__FILE__))
- # Rackサーバー起動
- Rack::Server.start(options)
+ # Rackサーバー生成
+ rack_server = Rack::Server.new(options)
+
+ # 起動URL生成
+ launch_url = create_launch_url(options)
+
+ # 起動
+ rack_server.start do
+ # この時点でoptions[:Host]やoptions[:Port]などの値が壊れてしまっているため事前にURLを生成している
+ Launchy.open(launch_url) if launch_url
+ end
else
create_customize_file(dbdir)
end
end
+ def self.create_launch_url(options)
+ if (options[:LaunchBrowser])
+ host = options[:Host] || options[:BindAddress] # options[:BindAddress] for WEBrick
+
+ if (options[:LaunchURL])
+ "http://#{host}:#{options[:Port]}#{options[:LaunchURL]}"
+ else
+ "http://#{host}:#{options[:Port]}"
+ end
+ else
+ nil
+ end
+ end
+
def self.select_dbdir
# if (Dbdir.dbdir?('.') || !Dbdir.dbdir?(Dbdir.default_dir))
if Dbdir.dbdir?('.')
View
14 lib/milkode/cdweb/lib/database.rb
@@ -120,6 +120,11 @@ def totalRecords
@documents.size
end
+ # 指定パッケージに属する全てのレコードを得る
+ def package_records(name)
+ @documents.package_records(name)
+ end
+
# yamlからパッケージの総数を得る
# @todo PackageTableから取得するように変更する
def yaml_package_num
@@ -178,6 +183,15 @@ def touch_viewtime(path)
@grndb.packages.touch_if(package, :viewtime) if package
end
+ def fav?(name)
+ @grndb.packages.fav?(name)
+ end
+
+ def set_fav(name, favorited)
+ time = favorited ? Time.now : Time.at(0)
+ @grndb.packages.touch_if(name, :favtime, time)
+ end
+
def update(name)
result = Updater::ResultAccumulator.new
result << update_in(yaml_load.find_name(name))
View
30 lib/milkode/cdweb/lib/info_home.rb
@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+#
+# @file
+# @brief
+# @author ongaeshi
+# @date 2013/05/04
+
+module Milkode
+ class InfoHome
+ attr_reader :record_content
+ attr_reader :summary_content
+
+ def initialize
+ packages = Database.instance.packages(nil)
+
+ @summary_content = <<EOF
+<table class="table-striped table-bordered table-condensed">
+ <tr><td>パッケージ数</td><td align="right">#{packages.size}</td></tr>
+ <tr><td>ファイル数</td><td align="right">#{Database.instance.totalRecords}</td></tr>
+</table>
+EOF
+
+ @record_content = packages.map do |name|
+ "<dt class='result-file'><img src='/images/info.png' /><a href='/info/#{name}'>#{name}</a></dt>"
+ end.join("\n")
+ end
+
+ end
+end
+
View
83 lib/milkode/cdweb/lib/info_package.rb
@@ -0,0 +1,83 @@
+# -*- coding: utf-8 -*-
+#
+# @file
+# @brief
+# @author ongaeshi
+# @date 2013/05/04
+
+require 'milkode/cdweb/lib/database'
+require 'milkode/common/plang_detector'
+
+module Milkode
+ class InfoPackage
+ attr_reader :summary_content
+ attr_reader :plang_content
+
+ def initialize(name)
+ records = Database.instance.package_records(name)
+ # plangs = sorted_plangs(records)
+
+ @summary_content = <<EOF
+<table class="table-striped table-bordered table-condensed">
+ <tr><td>ファイル数</td><td align="right">#{records.size}</td></tr>
+ <tr><td>行数</td><td align="right">#{line_count_total(records)}</td></tr>
+</table>
+EOF
+
+ @plang_content = <<EOF
+<table class="table-striped table-bordered table-condensed">
+#{breakdown_detail(records)}
+</table>
+EOF
+ end
+
+ def line_count_total(records)
+ records.reduce(0) do |total, record|
+ begin
+ unless record.content.nil?
+ total + record.content.count($/) + 1
+ else
+ total
+ end
+ rescue ArgumentError
+ # warning_alert("invalid byte sequence : #{record.path}")
+ total
+ end
+ end
+ end
+
+ def breakdown_detail(records)
+ sorted_plangs(records).map {|name, count|
+ percent = (count.to_f / records.size * 100).to_i
+ "<tr><td>#{name}</td><td align=\"right\">#{count}</td><td align=\"right\">#{percent}%</td></tr>"
+ }.join("\n")
+ end
+
+ def sorted_plangs(records)
+ total = {}
+
+ records.each do |record|
+ lang = PlangDetector.new(record.restpath)
+
+ if total[lang.name]
+ total[lang.name] += 1
+ else
+ total[lang.name] = 1
+ end
+ end
+
+ total.map {|name, count|
+ [name, count]
+ }.sort {|a, b|
+ if (a[0] == PlangDetector::UNKNOWN)
+ -1
+ elsif (b[0] == PlangDetector::UNKNOWN)
+ 1
+ else
+ a[1] <=> b[1]
+ end
+ }.reverse
+ end
+ end
+end
+
View
18 lib/milkode/cdweb/lib/package_list.rb
@@ -13,6 +13,8 @@ class PackageList
ADD_NUM = 5
UPDATE_NUM = 5
FAV_NUM = 7
+
+ FAVORITE_LIST_NUM = 7
def initialize(grndb)
@grndb = grndb
@@ -41,6 +43,22 @@ def top_fav
top_list(a[0...FAV_NUM], 'favtime')
end
+ def favorite_list(params)
+ names = @grndb.packages.favs.map{|r| r.name}[0..FAVORITE_LIST_NUM-1]
+
+ list = names.map_with_index {|v, index|
+ "<strong><a id='favorite_list_#{index}' href='#{Mkurl.new('/home/' + v, params).inherit_query_shead}' onclick='topic_path(\"favorite_list_#{index}\");'>#{v}</a></strong>"
+ }.join("&nbsp;&nbsp;\n")
+
+ <<EOF
+#{list}&nbsp;&nbsp;
+<a href="/home?sort=favtime">...</a>
+EOF
+ end
+
+ # ------------------------------------------------------
+ private
+
def grndb_list(column_name, num)
a = @grndb.packages.sort(column_name).map {|r| r.name}
top_list(a[0...num], column_name)
View
101 lib/milkode/cdweb/public/css/milkode.css
@@ -7,6 +7,8 @@ div.header {
div.footer {
}
+/* search-summary */
+
div.search-summary {
/* border-color: #e92926; */
/* background-color:#FFF0F0; */
@@ -23,6 +25,21 @@ div.search-summary {
padding-left:5px;
}
+.search-summary .keyword {
+ font-weight: bold;
+}
+
+.search-summary .ss-box {
+ float: left;
+ margin-right: 5px;
+}
+
+.search-summary .ss-end {
+ clear: both;
+}
+
+/* result */
+
dt.result-record {
font-size: 105%;
}
@@ -62,11 +79,7 @@ pre.lines {
padding-bottom: 5px;
}
-span.keyword {
- font-weight: bold;
-}
-
-span.sort-change {
+.sort-change {
font-weight: bold;
margin-right: 10px;
}
@@ -88,13 +101,22 @@ input#query {
input#search {
margin-left: 10px;
width: 80px;
+ height: 36px;
font-size: 20px;
}
+input#newtab {
+ margin-left: 0px;
+ width: 60px;
+ height: 32px;
+ font-size: 12px;
+}
+
input#clear {
margin-left: 0px;
- width: 80px;
- font-size: 18px;
+ width: 60px;
+ height: 32px;
+ font-size: 12px;
}
ul.unstyled_margin {
@@ -170,8 +192,56 @@ label.ui-corner-all {
/* mainpage - help */
-#mainpage .sample-code {
+#mainpage .help-content {
+ margin-top: 20px;
+}
+
+#mainpage .help-content h1 {
+ margin-top: 30px;
+ margin-bottom: 15px;
+}
+
+#mainpage .help-content h2 {
+ margin-top: 30px;
+ margin-bottom: 15px;
+}
+
+#mainpage .help-content ul li {
+ list-style: none;
+ margin-top: 10px;
+ margin-bottom: 10px;
+}
+
+#mainpage .help-content p {
+ font-size: 108%;
+ margin-left: 10px;
+}
+
+#mainpage .help-content img {
+ margin-left: 10px;
+}
+
+#mainpage .help-content pre {
+ margin-left: 10px;
+}
+
+#mainpage .help-content .comment {
+ color: #008E1D;
+}
+
+/* mainpage - info_package */
+
+#mainpage .info-package-content {
+ margin-top: 25px;
+}
+
+#mainpage .info-package-content h1 {
+ margin-bottom: 15px;
+}
+
+#mainpage .info-package-content h2 {
margin-top: 20px;
+ margin-bottom: 10px;
}
/* lineno-modal */
@@ -179,3 +249,18 @@ label.ui-corner-all {
#lineno-copyall {
font-size: 13px;
}
+
+/* star */
+
+.star {
+ text-indent: -5000px;
+ display: block;
+ background: transparent url(/images/milkode-star.png) 20px;
+ height: 20px;
+ width: 20px;
+}
+
+.star.favorited {
+ background-position: 0px;
+}
+
View
BIN  lib/milkode/cdweb/public/images/info-big.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  lib/milkode/cdweb/public/images/info.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  lib/milkode/cdweb/public/images/milkode-directpath-copy.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  lib/milkode/cdweb/public/images/milkode-star.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
40 lib/milkode/cdweb/public/js/milkode.js
@@ -15,7 +15,7 @@ function replace_query_param(url, value) {
return url + "?query=" + value;
else
return url;
-
+
} else {
var params = url_s[1].split("&");
var found_query = false;
@@ -69,6 +69,12 @@ function select_package_home() {
document.location = url + "/home/" + name;
}
+function favorite_list(id) {
+ var url = document.getElementById(id).href;
+ url = replace_query_param(url, document.searchform.query.value);
+ document.getElementById(id).href = url;
+}
+
function update_package(package_name) {
// click button
$("#updateModal .modal-body").html("<h4>更新中... <img src='/images/waiting.gif'/></h4>");
@@ -90,7 +96,7 @@ function update_package(package_name) {
}
function clippy_text(text, bgcolor) {
- return ' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' +
+ return ' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' +
' width="110"' +
' height="14"' +
' id="clippy" >' +
@@ -136,6 +142,10 @@ function lineno_setup(path, lineno) {
$("#lineno-copyall").html("Lineno + Text" + clippy_text(directpath + " " + escapeHTML(n_lineno_dom.text()), '#F5F5F5'));
}
+function open_newtab() {
+ window.open(replace_query_param(document.URL, document.searchform.query.value));
+}
+
$(document).ready(function() {
$("select#package").multiselect({
multiple: false,
@@ -170,7 +180,27 @@ $(document).ready(function() {
$('#shead').change(function(){
$('#search').click();
});
-});
-
-
+ $('.star').click(function() {
+ // 星の表示を切り替え
+ $(this).toggleClass('favorited');
+ var isFavorited = $(this).hasClass('favorited');
+
+ // パッケージ名を取得
+ var pname = $(this).attr('milkode-package-name');
+
+ // ajax通信
+ $.post(
+ '/command',
+ {
+ kind: 'favorite',
+ name: pname,
+ favorited: isFavorited
+ },
+ function(data) {
+ // @todo お気に入り一覧を更新
+ $(".favorite_list").html(data);
+ }
+ );
+ });
+});
View
10 lib/milkode/cdweb/views/filelist.haml
@@ -4,7 +4,15 @@
= haml :search_form
.search-summary
- <span class="keyword">#{topic_path(@path, params)}</span> <span class="total-entries">#{@total_records}</span>件(#{@elapsed}秒) #{search_summary_hook(@path)}
+ .favstar.ss-box
+ #{favstar(@path)}
+ .keyword.ss-box
+ #{topic_path(@path, params)}
+ .total-entries.ss-box
+ #{@total_records}件(#{@elapsed}秒)
+ .search-summary-hook.ss-box
+ #{search_summary_hook(@path)}
+ .ss-end
~ @record_content
View
2  lib/milkode/cdweb/views/header_menu.haml
@@ -1,5 +1,5 @@
.header
%h1
<a href="/"><img src=#{@setting.header_icon} alt="milkode-icon-mini" border="0" height="75px"/></a>
- #{@setting.header_title}
+ #{@setting.header_title} &nbsp;
= create_headmenu(@path, params, defined?(flistpath) ? flistpath : '')
View
93 lib/milkode/cdweb/views/help.haml
@@ -1,29 +1,76 @@
-- @title = 'help'
-
-.header
- %h1
- <a href="/"><img src=#{@setting.header_icon} alt="milkode-icon-mini" border="0" height="75px"/></a>
- #{@title} - #{@setting.header_title}
+= haml :header_menu
.content
- .sample-code
- %h2 基本
+ .help-content
+ %h1 ヘルプ
+
%ol
- %li キーワードを並べてAND検索<br>#{link('def open')}
- %li 1フレーズとして検索<br>#{link('"def open"')}
+ %li <a href="#search">検索</a>
+ %li <a href="#refine">絞り込みオプション</a>
+ %li <a href="#directpath">ダイレクトパス</a>
+
+ %h2#search 検索
+ %ul
+ %li キーワードを並べてAND検索
+
+ %pre
+ :preserve
+ def open
+
+ %li 1フレーズとして検索
+ %pre
+ :preserve
+ "def open"
- %h2 オプション
- %ol
- %li パッケージ名で絞り込み<br>#{link('def open p:milkode')}
- %li ファイル名で絞り込み<br>#{link('def open f:test')}
- %li 拡張子で絞り込み<br>#{link('s:rb')}
- %li ファイル名もしくはパッケージ名で絞り込み<br>#{link('fp:milkode')}
- %li ファイル名、パッケージ名、もしくはファイルの内容<br>#{link('k:test')}
+ %h2#refine 絞り込みオプション
+ %p
+ 検索キーワードと組み合わせて使う
- %h2 ダイレクトパス
- %ol
- %li viewモードで行番号をクリックするとダイレクトパス(現在行を表すテキスト)を表示
- %li ダイレクトパスで検索すると直接ジャンプ<br>#{link('/milkode/lib/milkode/cdstk/cdstk.rb:81')}
- %li 空白を含むダイレクトパスは""で囲む<br>#{link('"/path/a to text/dir:3"')}
- %li ダイレクトパスは空白で区切って複数渡せる<br>#{link('/milkode/lib/milkode/cli.rb:41 /milkode/lib/milkode/cdstk/cdstk.rb:121')}
+ %ul
+ %li パッケージ名で絞り込み
+ %pre
+ :preserve
+ p:milkode
+
+ %li ファイル名で絞り込み
+ %pre
+ :preserve
+ f:test
+ %li 拡張子で絞り込み
+ %pre
+ :preserve
+ s:rb
+
+ %li ファイル名もしくはパッケージ名で絞り込み
+ %pre
+ :preserve
+ fp:milkode
+
+ %li ファイル名、パッケージ名、もしくはファイルの内容
+ %pre
+ :preserve
+ k:test
+
+ %li 検索範囲を複数行に広げる
+ %pre
+ :preserve
+ w:7 read write <span class="comment"># 7行以内に'read'と'write'が含まれる箇所</span>
+ w:0 read write <span class="comment"># 'w:0'ならファイル内全て</span>
+
+ %h2#directpath ダイレクトパス
+ %p
+ Milkodeにおける<strong>"絶対パス"</strong>に相当するもの
+
+ %ul
+ %li ダイレクトパスで検索すると直接ジャンプ
+ %pre
+ :preserve
+ /proj/a/file.rb:81 <span class="comment"># /パッケージ名/ファイル名:行番号</span>
+ "/proj/a file.rb:3" <span class="comment"># 空白を含むダイレクトパスは""で囲む</span>
+ /proj1/file.rb:1 /proj2/file.c:2 <span class="comment"># 空白で区切れば複数個渡せる</span>
+
+ %li ファイルモードで行番号をクリックすると取得可能
+ <img src="/images/milkode-directpath-copy.gif" />
+
+ %li <a href="https://github.com/ongaeshi/emacs-milkode">emacs-milkode</a>との連携にも使う
View
14 lib/milkode/cdweb/views/info_home.haml
@@ -0,0 +1,14 @@
+= haml :header_menu
+
+.content
+ .info-package-content
+
+ %h1 <a href="/home">全体</a>の統計
+
+ ~ @summary_content
+
+ %h2 各パッケージ
+
+ ~ @record_content
+
+
View
13 lib/milkode/cdweb/views/info_package.haml
@@ -0,0 +1,13 @@
+= haml :header_menu
+
+.content
+ .info-package-content
+ %h1 <a href="/info"><img src="/images/info-big.png"/></a> <a href="/home/#{@path}">#{@path}</a>の統計
+
+ %h2 基本情報
+ ~ @summary_content
+
+ %h2 言語別
+ ~ @plang_content
+
+
View
8 lib/milkode/cdweb/views/packages.haml
@@ -4,8 +4,12 @@
= haml :search_form
.search-summary
- <span class="sort-change">#{@sort_change_content}</span> <span class="total-entries">#{@total_records}</span>件(#{@elapsed}秒)
- .sort_change
+ .sort-change.ss-box
+ #{@sort_change_content}
+ .total-entries.ss-box
+ #{@total_records}</span>件(#{@elapsed}秒)
+ .ss-end
+
~ @record_content
View
20 lib/milkode/cdweb/views/search.haml
@@ -4,11 +4,17 @@
= haml :search_form
.search-summary
- <span class="keyword">#{topic_path(@path, params)}</span>
- <span class="hit-num">#{@total_records}</span>ファイル中</span>
- <span class="search-range">#{@range.first} - #{@range.last}ファイルを検索</span>
- <span class="match-num">#{@match_num}</span>件マッチ</span>
- (#{@elapsed}秒)
- #{search_summary_hook(@path)}
-
+ .favstar.ss-box
+ #{favstar(@path)}
+ .keyword.ss-box
+ #{topic_path(@path, params)}
+ .hit-num.ss-box
+ #{@total_records}</span>ファイル中
+ .search-range.ss-box
+ #{@range.first} - #{@range.last}ファイルを検索
+ .match-num.ss-box
+ #{@match_num}</span>件マッチ(#{@elapsed}秒)
+ .search-summary-hook.ss-box
+ #{search_summary_hook(@path)}
+ .ss-end
~ @record_content
View
2  lib/milkode/cdweb/views/search_form.haml
@@ -7,6 +7,7 @@
%p
%input#query(name="query" size="70" type="text" style="width: 419px;"){:value => params[:query]}
%input#search(type="submit" name="search" value="検索" onclick="set_pathname()")
+ %input#newtab(type="submit" name="newtab" value="新規タブ" onclick="open_newtab(); return false;")
%input#clear(type="submit" name="clear" value="クリア" onclick="set_pathname()")
%br
範囲:
@@ -15,5 +16,6 @@
= create_select_package(@path)
= create_checkbox('onematch', params[:onematch], '1ファイル1マッチ')
= create_checkbox('sensitive', params[:sensitive], '大文字/小文字を区別')
+ = create_favorite_list(@package_list)
%input(name="pathname" type="hidden" value="")
View
10 lib/milkode/cdweb/views/view.haml
@@ -4,7 +4,15 @@
= haml :search_form
.search-summary
- <span class="keyword">#{topic_path(@path, params)}</span>#{additional_info(@path, params)}(#{@elapsed}秒) #{search_summary_hook(@path)}
+ .favstar.ss-box
+ #{favstar(@path)}
+ .keyword.ss-box
+ #{topic_path(@path, params)}
+ .additional-info.ss-box
+ #{additional_info(@path, params)}(#{@elapsed}秒)
+ .search-summary-hook.ss-box
+ #{search_summary_hook(@path)}
+ .ss-end
~ @record_content
View
5 lib/milkode/cli.rb
@@ -144,7 +144,8 @@ def ignore(*paths)
end
desc "fav [package1 package2 ...]", "Add favorite"
- option :delete, :type => :boolean, :aliases => '-d', :desc => "Delete favorite."
+ option :delete , :type => :boolean, :aliases => '-d', :desc => "Delete favorite."
+ option :sync_yaml , :type => :boolean, :aliases => '-s', :desc => "Sync yaml with database."
def fav(*paths)
cdstk.fav(paths, options)
end
@@ -208,7 +209,7 @@ def shell
# デフォルトメソッドを上書きして -h を処理
# defined in /lib/thor/invocation.rb
- def invoke_task(task, *args)
+ def invoke_command(task, *args)
if options[:help] && task.name != 'grep'
CLI.task_help(shell, task.name)
elsif options[:version] && task.name == 'help'
View
10 lib/milkode/common/archive-zip.rb
@@ -1,10 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# @file
-# @brief archive-zipがRuby1.9.2に対応するまでのパッチ
-# @author ongaeshi
-# @date 2011/08/04
-
-# 0.4.0になったため、必要なくなった。
-# $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../../../vendor')
-require 'archive/zip'
View
8 lib/milkode/common/util.rb
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
require 'rubygems'
-require 'milkode/common/archive-zip'
require 'fileutils'
require 'pathname'
require 'kconv'
-require 'groonga'
module Milkode
module Util
@@ -16,6 +14,8 @@ class ZipfileNotFound < RuntimeError ; end
# zipファイルを展開し、展開フォルダ名を返す
# ファイルが見つからなかった時はnilを返す
def zip_extract(filename, dst_dir)
+ require 'archive/zip'
+
raise ZipfileNotFound unless File.exist?(filename)
root_list = root_entrylist(filename)
@@ -55,6 +55,10 @@ def relative_path(path, basedir)
end
end
+ def ruby20?
+ RUBY_VERSION >= '2.0.0'
+ end
+
def ruby19?
RUBY_VERSION >= '1.9.0'
end
View
4 lib/milkode/database/document_table.rb
@@ -356,6 +356,10 @@ def to_a
@table.to_a
end
+ def package_records(name)
+ search(:strict_packages => [name])
+ end
+
private
def load_content(filename)
View
4 lib/milkode/database/package_table.rb
@@ -97,6 +97,10 @@ def favs
sorted
end
end
+
+ def fav?(name)
+ @table[name].favtime != Time.at(0)
+ end
end
end
View
43 lib/milkode/findgrep/result.rb
@@ -1,43 +0,0 @@
-# -*- coding: utf-8 -*-
-require 'find'
-require 'milkode/common/util'
-include Gren
-
-module FindGrep
- class Result
- attr_accessor :count
- attr_accessor :search_count
- attr_accessor :match_file_count
- attr_accessor :match_count
- attr_accessor :size
- attr_accessor :search_size
-
- attr_accessor :search_files
- attr_accessor :match_files
- attr_accessor :unreadable_files
- attr_accessor :prune_dirs
- attr_accessor :ignore_files
-
- def initialize(start_dir)
- @start_dir = File.expand_path(start_dir)
- @count, @search_count, @match_file_count, @match_count, @size, @search_size = 0, 0, 0, 0, 0, 0
- @start_time = Time.now
- @search_files, @match_files, @unreadable_files, @prune_dirs, @ignore_files = [], [], [], [], []
- end
-
- def time_stop
- @end_time = Time.now
- end
-
- def time
- @end_time - @start_time
- end
-
- def print(stdout)
- stdout.puts "dir : #{@start_dir} (#{Gren::Util::time_s(time)})"
- stdout.puts "files : #{@search_count} in #{@count} (#{Gren::Util::size_s(@search_size)} in #{Gren::Util::size_s(@size)})"
- stdout.puts "match : #{@match_file_count} files, #{match_count} hit"
- end
-
- end
-end
View
84 lib/milkode/grep/cli_grep.rb
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
-require 'optparse'
-require 'milkode/findgrep/findgrep'
-require 'milkode/common/dbdir'
-require 'milkode/cdstk/cdstk'
-require 'milkode/cdstk/yaml_file_wrapper'
-require 'milkode/cdstk/package'
require 'kconv'
+require 'milkode/cdstk/package'
+require 'milkode/cdstk/yaml_file_wrapper'
+require 'milkode/common/dbdir'
+require 'milkode/common/util'
+require 'milkode/grep/findgrep_option'
+require 'optparse'
module Milkode
class CLI_Grep
@@ -16,7 +16,7 @@ def self.execute(stdout, arguments=[])
arguments = arguments.map{|arg| Kconv.kconv(arg, Kconv::UTF8)}
end
- option = FindGrep::FindGrep::DEFAULT_OPTION.dup
+ option = FindGrepOption::create_default
# default option
option.dbFile = Dbdir.groonga_path(Dbdir.default_dir)
@@ -111,10 +111,10 @@ def self.execute(stdout, arguments=[])
# 現在位置のパッケージを記録
if option.packages.empty? && !my_option[:all] && !is_abs_path
- if (current_package)
- option.strict_packages << current_package.name
- elsif (package_dir_in? current_dir)
+ if package_dir_in?(current_dir)
option.filePatterns << current_dir
+ elsif current_package
+ option.strict_packages << current_package.name
else
stdout.puts "fatal: Not package dir '#{current_dir}'."
return
@@ -124,6 +124,7 @@ def self.execute(stdout, arguments=[])
if (arguments.size > 0 || my_option[:find_mode])
# update
if my_option[:update]
+ require 'milkode/cdstk/cdstk'
cdstk = Cdstk.new(stdout, Dbdir.select_dbdir)
if (my_option[:all])
@@ -139,35 +140,46 @@ def self.execute(stdout, arguments=[])
stdout.puts
end
- if (my_option[:count])
- # count mode
- option.isSilent = true
- findGrep = FindGrep::FindGrep.new(arguments, option)
- records = findGrep.pickupRecords
- # stdout.puts "#{records.size} records (#{findGrep.time_s})"
- stdout.puts "#{records.size} records"
- elsif my_option[:gotoline_data]
- # gotoline mode
- basePatterns = option.filePatterns
-
- my_option[:gotoline_data].each do |v|
- if is_abs_path
- package, restpath = Util::divide_shortpath(v[0][0])
- # p [package, restpath]
- option.packages = [package]
- option.filePatterns = [restpath]
- else
- option.filePatterns = basePatterns + v[0]
+ if is_abs_path
+ require 'milkode/grep/fast_gotoline'
+
+ obj = FastGotoline.new(my_option[:gotoline_data], yaml_load)
+ obj.search_and_print(stdout)
+
+ else
+ require 'milkode/grep/findgrep'
+
+ if (my_option[:count])
+ # count mode
+ option.isSilent = true
+ findGrep = FindGrep.new(arguments, option)
+ records = findGrep.pickupRecords
+ # stdout.puts "#{records.size} records (#{findGrep.time_s})"
+ stdout.puts "#{records.size} records"
+ elsif my_option[:gotoline_data]
+ # gotoline mode
+ basePatterns = option.filePatterns
+
+ my_option[:gotoline_data].each do |v|
+ if is_abs_path
+ # @memo ここにはこないはず
+ package, restpath = Util::divide_shortpath(v[0][0])
+ # p [package, restpath]
+ option.packages = [package]
+ option.filePatterns = [restpath]
+ else
+ option.filePatterns = basePatterns + v[0]
+ end
+
+ option.gotoline = v[1]
+ findGrep = FindGrep.new(arguments, option)
+ findGrep.searchAndPrint(stdout)
end
-
- option.gotoline = v[1]
- findGrep = FindGrep::FindGrep.new(arguments, option)
+ else
+ # search mode
+ findGrep = FindGrep.new(arguments, option)
findGrep.searchAndPrint(stdout)
end
- else
- # search mode
- findGrep = FindGrep::FindGrep.new(arguments, option)
- findGrep.searchAndPrint(stdout)
end
else
stdout.print opt.help
View
53 lib/milkode/grep/fast_gotoline.rb
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+#
+# @file
+# @brief
+# @author ongaeshi
+# @date 2013/05/03
+
+require 'milkode/common/util'
+
+module Milkode
+ class FastGotoline
+ def initialize(gotolines, yaml)
+ @gotolines = gotolines
+ @yaml = yaml
+ end
+
+ def search_and_print(stdout)
+ @gotolines.each do |gotoline|
+ package_name, restpath = Util::divide_shortpath(gotoline[0][0])
+ package = @yaml.find_name(package_name)
+
+ if package
+ path = File.join(package.directory, restpath)
+ relative_path = Util::relative_path(path, Dir.pwd).to_s
+ lineno = gotoline[1]
+ content = get_text_lineno(path, lineno)
+
+ if content
+ stdout.puts "#{relative_path}:#{lineno} #{content}"
+ end
+ end
+ end
+ end
+
+ def get_text_lineno(path, no)
+ index = no - 1
+
+ begin
+ open(path, "r") do |file|
+ file.each_with_index do |line, i|
+ return line.chomp if i == index
+ end
+ end
+ rescue Errno::ENOENT
+ # ファイルが見つからない時もnilを返す
+ end
+
+ nil
+ end
+
+ end
+end
+
View
98 lib/milkode/findgrep/findgrep.rb → lib/milkode/grep/findgrep.rb
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
+
require 'find'
-require 'milkode/findgrep/result'
require 'rubygems'
-require 'termcolor'
+# require 'termcolor'
require 'kconv'
require 'milkode/common/platform'
require 'milkode/common/grenfiletest'
@@ -13,59 +13,44 @@
require 'pathname'
require 'milkode/database/groonga_database'
-module FindGrep
+module Milkode
class FindGrep
- Option = Struct.new(:patternsNot,
- :patternsOr,
- :directory,
- :depth,
- :ignoreCase,
- :caseSensitive,
- :colorHighlight,
- :isSilent,
- :debugMode,
- :packages,
- :strict_packages,
- :filePatterns,
- :suffixs,
- :ignoreFiles,
- :ignoreDirs,
- :kcode,
- :noSnip,
- :dbFile,
- :groongaOnly,
- :isMatchFile,
- :dispHtml,
- :matchCountLimit,
- :keywords,
- :gotoline)
-
- DEFAULT_OPTION = Option.new([],
- [],
- ".",
- -1,
- false,
- false,
- false,
- false,
- false,
- [],
- [],
- [],
- [],
- [],
- [],
- # Platform.get_shell_kcode,
- Kconv::UTF8,
- false,
- nil,
- false,
- false,
- false,
- -1,
- [],
- -1)
-
+ class Result
+ attr_accessor :count
+ attr_accessor :search_count
+ attr_accessor :match_file_count
+ attr_accessor :match_count
+ attr_accessor :size
+ attr_accessor :search_size
+
+ attr_accessor :search_files
+ attr_accessor :match_files
+ attr_accessor :unreadable_files
+ attr_accessor :prune_dirs
+ attr_accessor :ignore_files
+
+ def initialize(start_dir)
+ @start_dir = File.expand_path(start_dir)
+ @count, @search_count, @match_file_count, @match_count, @size, @search_size = 0, 0, 0, 0, 0, 0
+ @start_time = Time.now
+ @search_files, @match_files, @unreadable_files, @prune_dirs, @ignore_files = [], [], [], [], []
+ end
+
+ def time_stop
+ @end_time = Time.now
+ end
+
+ def time
+ @end_time - @start_time
+ end
+
+ def print(stdout)
+ stdout.puts "dir : #{@start_dir} (#{Gren::Util::time_s(time)})"
+ stdout.puts "files : #{@search_count} in #{@count} (#{Gren::Util::size_s(@search_size)} in #{Gren::Util::size_s(@size)})"
+ stdout.puts "match : #{@match_file_count} files, #{match_count} hit"
+ end
+ end
+
class MatchCountOverError < RuntimeError ; end
attr_reader :documents
@@ -80,7 +65,8 @@ def initialize(patterns, option)
@ignoreFiles = strs2regs_simple(option.ignoreFiles)
@ignoreDirs = strs2regs_simple(option.ignoreDirs)
@result = Result.new(option.directory)
- open_database if (@option.dbFile)
+ open_database if @option.dbFile
+ require 'termcolor' if @option.colorHighlight
end
def open_database()
@@ -90,7 +76,7 @@ def open_database()
# データベース開く
if dbfile.exist?
if !@grndb || @grndb.closed?
- @grndb = GroongaDatabase.new
+ @grndb = Milkode::GroongaDatabase.new
@grndb.open_file(dbfile.to_s)
@documents = @grndb.documents
puts "open : #{dbfile.to_s} open." unless @option.isSilent
View
63 lib/milkode/grep/findgrep_option.rb
@@ -0,0 +1,63 @@
+# -*- coding: utf-8 -*-
+#
+# @file
+# @brief
+# @author ongaeshi
+# @date 2013/05/03
+
+module Milkode
+ class FindGrepOption
+ Option = Struct.new(:patternsNot,
+ :patternsOr,
+ :directory,
+ :depth,
+ :ignoreCase,
+ :caseSensitive,
+ :colorHighlight,
+ :isSilent,
+ :debugMode,
+ :packages,
+ :strict_packages,
+ :filePatterns,
+ :suffixs,
+ :ignoreFiles,
+ :ignoreDirs,
+ :kcode,
+ :noSnip,
+ :dbFile,
+ :groongaOnly,
+ :isMatchFile,
+ :dispHtml,
+ :matchCountLimit,
+ :keywords,
+ :gotoline)
+
+ def self.create_default
+ Option.new([],
+ [],
+ ".",
+ -1,
+ false,
+ false,
+ false,
+ false,
+ false,
+ [],
+ [],
+ [],
+ [],
+ [],
+ [],
+ Kconv::UTF8, # Platform.get_shell_kcode,
+ false,
+ nil,
+ false,
+ false,
+ false,
+ -1,
+ [],
+ -1)
+ end
+ end
+end
+
View
35 milkode.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{milkode}
- s.version = "0.9.9"
+ s.version = "1.0.0.rc.1"
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["ongaeshi"]
- s.date = %q{2013-03-26}
+ s.date = %q{2013-05-05}
s.description = %q{Line based local source code search engine & grep-command & web-app.}
s.email = %q{ongaeshi0621@gmail.com}
s.executables = ["gmilk", "milk"]
@@ -43,6 +43,8 @@ Gem::Specification.new do |s|
"lib/milkode/cdweb/lib/command.rb",
"lib/milkode/cdweb/lib/database.rb",
"lib/milkode/cdweb/lib/grep.rb",
+ "lib/milkode/cdweb/lib/info_home.rb",
+ "lib/milkode/cdweb/lib/info_package.rb",
"lib/milkode/cdweb/lib/mkurl.rb",
"lib/milkode/cdweb/lib/package_list.rb",
"lib/milkode/cdweb/lib/query.rb",
@@ -82,6 +84,10 @@ Gem::Specification.new do |s|
"lib/milkode/cdweb/public/images/file.png",
"lib/milkode/cdweb/public/images/go-home-5.png",
"lib/milkode/cdweb/public/images/help.png",
+ "lib/milkode/cdweb/public/images/info-big.png",
+ "lib/milkode/cdweb/public/images/info.png",
+ "lib/milkode/cdweb/public/images/milkode-directpath-copy.gif",
+ "lib/milkode/cdweb/public/images/milkode-star.png",
"lib/milkode/cdweb/public/images/view-refresh-4.png",
"lib/milkode/cdweb/public/images/waiting.gif",
"lib/milkode/cdweb/public/img/glyphicons-halflings-white.png",
@@ -97,13 +103,14 @@ Gem::Specification.new do |s|
"lib/milkode/cdweb/views/header_menu.haml",
"lib/milkode/cdweb/views/help.haml",
"lib/milkode/cdweb/views/index.haml",
+ "lib/milkode/cdweb/views/info_home.haml",
+ "lib/milkode/cdweb/views/info_package.haml",
"lib/milkode/cdweb/views/layout.haml",
"lib/milkode/cdweb/views/packages.haml",
"lib/milkode/cdweb/views/search.haml",
"lib/milkode/cdweb/views/search_form.haml",
"lib/milkode/cdweb/views/view.haml",
"lib/milkode/cli.rb",
- "lib/milkode/common/archive-zip.rb",
"lib/milkode/common/array_diff.rb",
"lib/milkode/common/dbdir.rb",
"lib/milkode/common/dir.rb",
@@ -122,9 +129,10 @@ Gem::Specification.new do |s|
"lib/milkode/database/groonga_database.rb",
"lib/milkode/database/package_table.rb",
"lib/milkode/database/updater.rb",
- "lib/milkode/findgrep/findgrep.rb",
- "lib/milkode/findgrep/result.rb",
"lib/milkode/grep/cli_grep.rb",
+ "lib/milkode/grep/fast_gotoline.rb",
+ "lib/milkode/grep/findgrep.rb",
+ "lib/milkode/grep/findgrep_option.rb",
"milkode.gemspec",
"test/data/.gitignore",
"test/data/.gitignore.sjis",
@@ -200,7 +208,7 @@ Gem::Specification.new do |s|
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<rroonga>, [">= 1.1.0"])
- s.add_runtime_dependency(%q<rack>, [">= 1.3.4", "~> 1.4.0"])
+ s.add_runtime_dependency(%q<rack>, [">= 1.5.2"])
s.add_runtime_dependency(%q<sinatra>, [">= 1.2.6"])
s.add_runtime_dependency(%q<launchy>, [">= 0.3.7"])
s.add_runtime_dependency(%q<coderay>, [">= 1.0.5"])
@@ -208,15 +216,16 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<archive-zip>, [">= 0.4.0"])
s.add_runtime_dependency(%q<haml>, [">= 3.1.2"])
s.add_runtime_dependency(%q<sass>, [">= 3.1.3"])
- s.add_runtime_dependency(%q<thor>, ["~> 0.15.0"])
+ s.add_runtime_dependency(%q<thor>, [">= 0.18.1"])
s.add_development_dependency(%q<bundler>, [">= 0"])
s.add_development_dependency(%q<jeweler>, [">= 0"])
s.add_development_dependency(%q<rack-test>, [">= 0"])
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<rroonga>, [">= 1.1.0"])
- s.add_dependency(%q<rack>, [">= 1.3.4", "~> 1.4.0"])
+ s.add_dependency(%q<rack>, [">= 1.5.2"])
s.add_dependency(%q<sinatra>, [">= 1.2.6"])
s.add_dependency(%q<launchy>, [">= 0.3.7"])
s.add_dependency(%q<coderay>, [">= 1.0.5"])
@@ -224,16 +233,17 @@ Gem::Specification.new do |s|
s.add_dependency(%q<archive-zip>, [">= 0.4.0"])
s.add_dependency(%q<haml>, [">= 3.1.2"])
s.add_dependency(%q<sass>, [">= 3.1.3"])
- s.add_dependency(%q<thor>, ["~> 0.15.0"])
+ s.add_dependency(%q<thor>, [">= 0.18.1"])
s.add_dependency(%q<bundler>, [">= 0"])
s.add_dependency(%q<jeweler>, [">= 0"])
s.add_dependency(%q<rack-test>, [">= 0"])
s.add_dependency(%q<sinatra-reloader>, [">= 0"])
+ 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<rroonga>, [">= 1.1.0"])
- s.add_dependency(%q<rack>, [">= 1.3.4", "~> 1.4.0"])
+ s.add_dependency(%q<rack>, [">= 1.5.2"])
s.add_dependency(%q<sinatra>, [">= 1.2.6"])
s.add_dependency(%q<launchy>, [">= 0.3.7"])
s.add_dependency(%q<coderay>, [">= 1.0.5"])
@@ -241,11 +251,12 @@ Gem::Specification.new do |s|
s.add_dependency(%q<archive-zip>, [">= 0.4.0"])
s.add_dependency(%q<haml>, [">= 3.1.2"])
s.add_dependency(%q<sass>, [">= 3.1.3"])
- s.add_dependency(%q<thor>, ["~> 0.15.0"])
+ s.add_dependency(%q<thor>, [">= 0.18.1"])
s.add_dependency(%q<bundler>, [">= 0"])
s.add_dependency(%q<jeweler>, [">= 0"])
s.add_dependency(%q<rack-test>, [">= 0"])
s.add_dependency(%q<sinatra-reloader>, [">= 0"])
+ s.add_dependency(%q<test-unit>, [">= 2.5.4"])
end
end
View
4 test/test_cli.rb
@@ -11,7 +11,7 @@
class TestCLI < Test::Unit::TestCase
def setup
- $stdout = StringIO.new
+ $stdout = @stringio = StringIO.new
@first_default_dir = Dbdir.default_dir
@work = MilkodeTestWork.new({:default_db => true})
@work.add_package "db1", @work.expand_path("../data/a_project")
@@ -65,8 +65,10 @@ def test_setdb_reset
def test_fav
command("fav")
command("fav a_not_found_package_xxxxxxx")
+ @stringio.string = ""
# command("fav package")
# command("fav -d package")
+ assert_equal "", command("fav --sync-yaml")
end
def test_help_with_h_option
View
2  test/test_cli_grep.rb
@@ -5,7 +5,7 @@
# @author ongaeshi
# @date 2011/12/03
-require 'milkode/grep/cli_grep.rb'
+require 'milkode/grep/cli_grep'
require 'test_helper'
require 'milkode_test_work'
View
4 test/test_findgrep.rb
@@ -7,9 +7,9 @@
require 'test_helper'
require 'file_assert'
-require 'milkode/findgrep/findgrep'
+require 'milkode/grep/findgrep'
-module FindGrep
+module Milkode
class TestFindGrep < Test::Unit::TestCase
def test_basic
View
52 test/test_milkode_yaml.rb
@@ -19,7 +19,7 @@ class TestMilkodeYaml < Test::Unit::TestCase
- directory: /a/dir1
- directory: /path/to/dir
ignore:
- - ! '*.bak'
+ - '*.bak'
- /rdoc
- directory: /a/b/c
EOF
@@ -36,7 +36,21 @@ class TestMilkodeYaml < Test::Unit::TestCase
def test_dump
obj = MilkodeYaml.new(SRC)
- assert_equal SRC, obj.dump if Milkode::Util::ruby19?
+ if Milkode::Util::ruby20?
+ assert_equal SRC, obj.dump
+ elsif Milkode::Util::ruby19?
+ assert_equal <<EOF, obj.dump
+---
+version: '0.2'
+contents:
+- directory: /a/dir1
+- directory: /path/to/dir
+ ignore:
+ - ! '*.bak'
+ - /rdoc
+- directory: /a/b/c
+EOF
+ end
end
def test_version
@@ -75,7 +89,19 @@ def test_remove
assert_equal 2, obj.contents.size
- assert_equal <<EOF, obj.dump if Milkode::Util::ruby19?
+ if Milkode::Util::ruby20?
+ assert_equal <<EOF, obj.dump
+---
+version: '0.2'
+contents:
+- directory: /a/dir1
+- directory: /path/to/dir
+ ignore:
+ - '*.bak'
+ - /rdoc
+EOF
+ elsif Milkode::Util::ruby19?
+ assert_equal <<EOF, obj.dump
---
version: '0.2'
contents:
@@ -85,6 +111,8 @@ def test_remove
- ! '*.bak'
- /rdoc
EOF
+ end
+
end
def test_migrate
@@ -117,7 +145,21 @@ def test_update
p = Package.create(p.directory, p.ignore + ['*.a'])
obj.update(p)
- assert_equal <<EOF, obj.dump if Milkode::Util::ruby19?
+ if Milkode::Util::ruby20?
+ assert_equal <<EOF, obj.dump
+---
+version: '0.2'
+contents:
+- directory: /a/dir1
+- directory: /path/to/dir
+ ignore:
+ - '*.bak'
+ - /rdoc
+ - '*.a'
+- directory: /a/b/c
+EOF
+ elsif Milkode::Util::ruby19?
+ assert_equal <<EOF, obj.dump
---
version: '0.2'
contents:
@@ -129,6 +171,8 @@ def test_update
- ! '*.a'
- directory: /a/b/c
EOF
+ end
+
p = Package.create("not_found")
assert_raise(RuntimeError) { obj.update(p) }
View
2  test/test_query.rb
@@ -88,6 +88,8 @@ def test_wide_match_range
assert_equal 6 , create_query("w:5 w:6").wide_match_range
assert_equal 0 , create_query("w:0").wide_match_range
assert_equal 0 , create_query("w:aaa").wide_match_range
+ assert_equal 0 , create_query("w:日本語").wide_match_range
+ assert_equal false , create_query("w:日本語").wide_match_range_empty?
end
private
Please sign in to comment.
Something went wrong with that request. Please try again.