Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents dac8749 + 334ddd2 commit d8ca5658fe5c304a26ff6cb3ed8b870e8a29459d @ongaeshi committed Nov 28, 2013
View
@@ -42,4 +42,5 @@ pkg
# For vim:
#*.swp
-.sass-cache
+.sass-cache
+TAGS
View
@@ -15,6 +15,7 @@ gem 'archive-zip' , '>= 0.4.0'
gem 'haml' , '>= 3.1.2'
gem 'sass' , '>= 3.1.3'
gem 'thor' , '>= 0.18.1'
+gem 'i18n' , '~> 0.6.5'
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
View
@@ -1 +1 @@
-1.3.0
+1.4.0
View
@@ -6,5 +6,5 @@
require 'rubygems'
require 'milkode/grep/cli_grep'
-Version = "1.3.0"
+Version = "1.4.0"
Milkode::CLI_Grep.execute(STDOUT, ARGV)
View
@@ -6,5 +6,5 @@
require 'rubygems'
require 'milkode/cli'
-Version = "1.3.0"
+Version = "1.4.0"
Milkode::CLI.start(ARGV)
View
@@ -119,6 +119,10 @@ def update_for_grep(dir)
def add(dirs, options)
update_display_info(options)
+ if options[:from_file]
+ dirs = File.read(options[:from_file]).split("\n")
+ end
+
print_result do
# データベースを開く
db_open
@@ -131,15 +135,22 @@ def add(dirs, options)
# YAMLに追加
package = Package.create(dir, options[:ignore])
- add_yaml(package)
+ skip_add = options[:from_file] && @yaml.find_name(package.name)
+ add_yaml(package) unless skip_add
# オプション設定
is_update_with_git_pull = git_protocol?(options, v)
is_update_with_svn_update = svn_protocol?(options, v)
set_yaml_options(package, options, is_update_with_git_pull, is_update_with_svn_update)
# アップデート
- update_dir_in(dir) unless options[:empty]
+ unless options[:empty]
+ if skip_add
+ update_package_in(package, options)
+ else
+ update_dir_in(dir)
+ end
+ end
end
rescue AddError => e
error_alert(e.message)
@@ -281,17 +292,23 @@ def download_file_in(url)
end
def git_clone_in(url, options)
- alert("git", url)
-
dst_dir = File.join(@db_dir, "packages/git")
name = options[:name] || File.basename(url).sub(/\.git\Z/, "")
filename = File.join(dst_dir, name)
- # git output progress to stderr.
- # `git clone #{url} #{filename} 2>&1`
+ unless File.exist?(filename)
+ # git output progress to stderr.
+ # `git clone #{url} #{filename} 2>&1`
- # with output
- system("git clone #{url} #{filename}")
+ # with output
+ if options[:branch_name]
+ alert("git", "#{url} (#{options[:branch_name]})")
+ system("git clone #{url} #{filename} -b #{options[:branch_name]}")
+ else
+ alert("git", url)
+ system("git clone #{url} #{filename}")
+ end
+ end
filename
end
View
@@ -1,18 +1,14 @@
# -*- coding: utf-8 -*-
-#
-# @file
-# @brief
-# @author ongaeshi
-# @date 2011/06/25
-
require 'rubygems'
require 'sinatra'
+require 'sass'
+require 'haml'
+require 'i18n'
+
if ENV['MILKODE_SINATRA_RELOADER']
require 'sinatra/reloader'
also_reload '../../**/*.rb'
end
-require 'sass'
-require 'haml'
$LOAD_PATH.unshift '../..'
require 'milkode/common/util'
@@ -25,7 +21,10 @@
require 'milkode/cdweb/lib/info_package'
require 'sinatra/url_for'
+I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'locales', '*.yml').to_s]
+
set :haml, :format => :html5
+enable :sessions
get '/js/:filename' do
content_type :js
@@ -44,7 +43,7 @@
get '/' do
if Database.validate?
@setting = WebSetting.new
- @version = "1.3.0"
+ @version = "1.4.0"
@package_num = Database.instance.yaml_package_num
@file_num = Database.instance.totalRecords
@@ -107,7 +106,7 @@ def package_path(homeurl, path)
when 'favorite'
Database.instance.set_fav(params[:name], params[:favorited] == 'true')
@package_list = PackageList.new(Database.instance.grndb, url_for(''))
- "お気に入り: " + @package_list.favorite_list({})
+ t(:favorite) + ": " + @package_list.favorite_list({})
end
end
@@ -117,18 +116,19 @@ def package_path(homeurl, path)
record = Database.instance.record(path)
@package_list = PackageList.new(Database.instance.grndb, url_for(''))
suburl = url_for('')
+ update_locale
if path.empty?
if (params[:query] and !params[:query].empty?)
- search(path, params, before, suburl)
+ search(path, params, before, suburl, @locale)
else
- packages(params, before, suburl)
+ packages(params, before, suburl, @locale)
end
elsif (record)
view(record, params, before)
else
if (params[:query] and !params[:query].empty?)
- search(path, params, before, suburl)
+ search(path, params, before, suburl, @locale)
else
filelist(path, params, before, suburl)
end
@@ -192,9 +192,9 @@ def create_select_shead(value)
value ||= "package"
data = [
- ['all' , '全て' ],
- ['package' , 'パッケージ' ],
- ['directory', 'ディレクトリ'],
+ ['all' , t(:all) ],
+ ['package' , t(:package) ],
+ ['directory', t(:directory)],
]
<<EOF
@@ -239,27 +239,28 @@ def create_headmenu(path, query, flistpath = '')
flist = File.join("#{suburl}/home/#{path}", flistpath)
package_name = ""
- modal_body = "全てのパッケージを更新しますか?"
+ modal_body = t(:update_all)
if (path != "")
package_name = path.split('/')[0]
- modal_body = "#{package_name} を更新しますか?"
+ update_locale
+ modal_body = I18n.t(:update_package, {package_name: package_name, locale: @locale})
end
info_path = "#{suburl}/info"
info_path = File.join(info_path, package_name) if package_name != ""
<<EOF
- #{headicon('go-home-5.png', suburl)}<a href="#{suburl}/home" class="headmenu">ホーム</a>&nbsp;
- #{headicon('directory.png', suburl)}<a href="#{flist}" class="headmenu">ディレクトリ</a>
- #{headicon('view-refresh-4.png', suburl)}<a href="#updateModal" class="headmenu" data-toggle="modal">パッケージを更新</a>&nbsp;
- #{headicon('info.png', suburl)}<a href="#{info_path}" class="headmenu">統計情報</a>&nbsp;
- #{headicon('help.png', suburl)}<a href="#{suburl}/help" class="headmenu">ヘルプ</a>
+ #{headicon('go-home-5.png', suburl)}<a href="#{suburl}/home" class="headmenu">#{t(:home)}</a>&nbsp;
+ #{headicon('directory.png', suburl)}<a href="#{flist}" class="headmenu">#{t(:directory)}</a>
+ #{headicon('view-refresh-4.png', suburl)}<a href="#updateModal" class="headmenu" data-toggle="modal">#{t(:update_packages)}</a>&nbsp;
+ #{headicon('info.png', suburl)}<a href="#{info_path}" class="headmenu">#{t(:stats)}</a>&nbsp;
+ #{headicon('help.png', suburl)}<a href="#{suburl}/help" class="headmenu">#{t(:help)}</a>
<div id="updateModal" class="modal hide fade">
<div class="modal-header">
<a href="#" class="close" data-dismiss="modal">&times;</a>
- <h3>パッケージを更新</h3>
+ <h3>#{t(:update_packages)}</h3>
</div>
<div class="modal-body">
<h4>#{modal_body}</h4>
@@ -292,7 +293,7 @@ def create_headmenu(path, query, flistpath = '')
def create_favorite_list(package_list)
<<EOF
<div class="favorite_list">
- お気に入り:
+ #{t(:favorite)}:
#{package_list.favorite_list(params)}
</div>
</div>
@@ -399,6 +400,32 @@ def goto_github_project(path)
def search_summary_hook(path)
goto_github_project(path)
end
+
+ ## for I18N
+ def ua_locale
+ # Pulls the browser's language
+ @env["HTTP_ACCEPT_LANGUAGE"][0,2]
+ end
+
+ def update_locale
+ unless @locale
+ begin
+ # Support session
+ @locale = params[:locale] || session[:locale] || ua_locale || 'en'
+ session[:locale] = @locale
+ rescue NameError # 'session' variable can't find during testing
+ @locale = 'en'
+ end
+
+ # Reload with sinatra-reloader
+ I18n.reload! if ENV['MILKODE_SINATRA_RELOADER']
+ end
+ end
+
+ def t(*args)
+ update_locale
+ I18n.t(*args, locale: @locale)
+ end
end
class Array
@@ -56,7 +56,7 @@ def view(record, params, before)
haml :view
end
- def search(path, params, before, suburl)
+ def search(path, params, before, suburl, locale)
@setting = WebSetting.new
@path = path
query = Query.new(params[:query])
@@ -73,7 +73,7 @@ def search(path, params, before, suburl)
if Util::gotoline_keyword?(query.keywords[0])
searcher = SearchGotoLine.new(path, params, query, suburl)
else
- searcher = SearchContents.new(path, params, query, suburl)
+ searcher = SearchContents.new(path, params, query, suburl, locale)
if searcher.directjump?
redirect searcher.directjump_url
@@ -105,24 +105,25 @@ def filelist(path, params, before, suburl)
haml :filelist
end
- def packages(params, before, suburl)
+ def packages(params, before, suburl, locale)
@setting = WebSetting.new
@title = "Package List"
@path = ""
packages = Database.instance.packages(params["sort"])
@total_records = packages.size
+ @locale = locale
@sort_change_content =
[
- sort_change_content(params["sort"], '名前'),
+ sort_change_content(params["sort"], I18n.t(:name, locale: @locale)),
'|',
- sort_change_content(params["sort"], '最近使った', 'viewtime'),
+ sort_change_content(params["sort"], I18n.t(:recently_viewed, locale: @locale), 'viewtime'),
'|',
- sort_change_content(params["sort"], '追加順' , 'addtime'),
+ sort_change_content(params["sort"], I18n.t(:added, locale: @locale), 'addtime'),
'|',
- sort_change_content(params["sort"], '更新順' , 'updatetime'),
+ sort_change_content(params["sort"], I18n.t(:updated, locale: @locale), 'updatetime'),
'|',
- sort_change_content(params["sort"], 'お気に入り', 'favtime'),
+ sort_change_content(params["sort"], I18n.t(:favorite, locale: @locale), 'favtime'),
].join("\n")
@record_content = packages.map do |v|
@@ -87,11 +87,11 @@ def search(patterns, keywords, packages, current_path, fpaths, suffixs, fpath_or
end
# 検索
- result, total_records = [], 0
+ records, total_records, result = [], 0, nil
begin
unless is_not_search
- result, total_records = @documents.search_with_match(
+ records, total_records, result = @documents.search_with_match(
:patterns => patterns,
:keywords => keywords,
:paths => paths,
@@ -108,7 +108,7 @@ def search(patterns, keywords, packages, current_path, fpaths, suffixs, fpath_or
end
# 結果
- return result.map{|r| DocumentRecord.new(r)}, total_records
+ return records.map{|r| DocumentRecord.new(r)}, total_records, result
end
def selectAll(offset, limit)
Oops, something went wrong.

0 comments on commit d8ca565

Please sign in to comment.