Permalink
Browse files

Merge branch 'web_setting' into develop

  • Loading branch information...
2 parents 93c7c01 + 7daa3f2 commit 3013114be9d6d2c9cceb201a4313bee542b7c94e @ongaeshi committed Mar 24, 2012
@@ -120,6 +120,7 @@ def self.setup_web
opts.on('-p', '--port PORT', 'use PORT (default: 9292)') {|v| options[:Port] = v }
opts.on("-s", "--server SERVER", "serve using SERVER (default : thin)") {|s| options[:server] = s }
opts.on('-n', '--no-browser', 'No launch browser.') {|v| options[:LaunchBrowser] = false }
+ opts.on('--customize', 'Create customize file.') {|v| options[:customize] = true }
# --hostが'-h'を上書きするので、'-h'を再定義してあげる
opts.on_tail("-h", "-?", "--help", "Show this message") do
@@ -14,10 +14,12 @@
require 'milkode/cdweb/lib/database'
require 'milkode/cdweb/lib/command'
require 'milkode/cdweb/lib/mkurl'
+require 'milkode/cdweb/lib/web_setting'
set :haml, :format => :html5
get '/' do
+ @setting = WebSetting.new
@version = "0.5.0"
@package_num = Database.instance.yaml_package_num
@file_num = Database.instance.totalRecords
@@ -66,6 +68,7 @@ def package_path(path)
end
get %r{/help} do
+ @setting = WebSetting.new
haml :help
end
@@ -75,6 +75,7 @@ def self.execute(stdout, argv)
opts.on('-p', '--port PORT', 'use PORT (default: 9292)') {|v| options[:Port] = v }
opts.on("-s", "--server SERVER", "serve using SERVER (default : thin)") {|s| options[:server] = s }
opts.on('-n', '--no-browser', 'No launch browser.') {|v| options[:LaunchBrowser] = false }
+ opts.on('--customize', 'Create customize file.') {|v| options[:customize] = true }
# --hostが'-h'を上書きするので、'-h'を再定義してあげる
opts.on_tail("-h", "-?", "--help", "Show this message") do
@@ -89,16 +90,21 @@ def self.execute(stdout, argv)
end
def self.execute_with_options(stdout, options)
- # 使用するデータベースの位置設定
- Database.setup(File.expand_path(options[:DbDir]))
+ dbdir = File.expand_path(options[:DbDir])
+
+ unless options[:customize]
+ # 使用するデータベースの位置設定
+ Database.setup(dbdir)
- # サーバースクリプトのある場所へ移動
- FileUtils.cd(File.dirname(__FILE__))
+ # サーバースクリプトのある場所へ移動
+ FileUtils.cd(File.dirname(__FILE__))
- # Rackサーバー起動
- Rack::Server.start(options)
+ # Rackサーバー起動
+ Rack::Server.start(options)
+ else
+ create_customize_file(dbdir)
+ end
end
-
def self.select_dbdir
if (Dbdir.dbdir?('.') || !Dbdir.dbdir?(Dbdir.default_dir))
@@ -107,5 +113,31 @@ def self.select_dbdir
Dbdir.default_dir
end
end
+
+ def self.create_customize_file(dbdir)
+ fname = File.join(dbdir, "milkweb.yaml")
+
+ if File.exist? fname
+ puts "Already exist '#{fname}'"
+ else
+ puts <<EOF
+Create '#{fname}'.
+ Please customize yaml parameter.
+EOF
+
+ File.open(fname, "w") do |f|
+ f.write <<EOF
+---
+:home_title : "Milkode"
+:home_icon : "/images/MilkodeIcon135.png"
+
+:header_title: "Milkode"
+:header_icon : "/images/MilkodeIcon135.png"
+
+:display_about_milkode: true
+EOF
+ end
+ end
+ end
end
end
@@ -14,6 +14,7 @@
module Milkode
def view(record, params, before)
+ @setting = WebSetting.new
@title = record.shortpath
@path = record.shortpath
@@ -32,6 +33,7 @@ def view(record, params, before)
end
def search(path, params, before)
+ @setting = WebSetting.new
@path = path
query = Query.new(params[:query])
@title = "'#{query.query_string}' in #{path_title(path)}"
@@ -51,6 +53,7 @@ def search(path, params, before)
end
def filelist(path, params, before)
+ @setting = WebSetting.new
@title = filelist_title(path)
@path = path
fileList = Database.instance.fileList(path)
@@ -23,16 +23,18 @@ def self.setup(db_dir)
@@db_dir = db_dir
end
+ def self.dbdir
+ @@db_dir || Dbdir.default_dir
+ end
+
attr_reader :yaml
def initialize
- db_dir = @@db_dir || Dbdir.default_dir
- open(db_dir)
- @yaml = YamlFileWrapper.load_if(db_dir)
+ open(Database.dbdir)
end
def yaml_reload
- @yaml = YamlFileWrapper.load_if(@@db_dir || Dbdir.default_dir)
+ # @yaml = YamlFileWrapper.load_if(@@db_dir || Dbdir.default_dir)
end
def open(db_dir)
@@ -106,7 +108,7 @@ def totalRecords
# yamlからパッケージの総数を得る
def yaml_package_num
- @yaml.contents.size
+ yaml_load.contents.size
end
# @sample test/test_database.rb:43 TestDatabase#t_fileList
@@ -116,7 +118,7 @@ def fileList(base)
# 'depth==0'の時はMilkodeYaml#contentsからファイルリストを生成して高速化
if (base_depth == 0)
- return @yaml.contents.sort_by{|v| v.name}.map{|v| [v.name, false] }
+ return yaml_load.contents.sort_by{|v| v.name}.map{|v| [v.name, false] }
end
# shortpathにマッチするものだけに絞り込む
@@ -180,7 +182,7 @@ def cleanup
def reopen_patch
# 削除系のコマンドが上手く動作しないためのパッチ
# 本質的な解決にはなっていないと思う
- open(@@db_dir || Dbdir.default_dir)
+ open(Database.dbdir)
end
def searchMain(patterns, packages, fpaths, suffixs, offset, limit)
@@ -288,7 +290,11 @@ def convert_packages(packages)
end
def expand_packages(keyword)
- @yaml.match_all(keyword).map{|p| p.directory}
+ yaml_load.match_all(keyword).map{|p| p.directory}
+ end
+
+ def yaml_load
+ YamlFileWrapper.load_if(Database.dbdir)
end
# --- error ---
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+#
+# @file
+# @brief
+# @author ongaeshi
+# @date 2012/03/24
+
+require 'milkode/cdweb/lib/database'
+require 'yaml'
+
+module Milkode
+ class WebSetting
+ DEFAULT_SETTING = {
+ :home_title => "Milkode",
+ :home_icon => "/images/MilkodeIcon135.png",
+
+ :header_title => "Milkode",
+ :header_icon => "/images/MilkodeIcon135.png",
+
+ :display_about_milkode => true
+ }
+
+ def self.hash_method(name)
+ define_method(name) do
+ @data[name]
+ end
+ end
+
+ def initialize
+ fname = File.join(Database.dbdir, "milkweb.yaml")
+ if FileTest.exist? fname
+ open(fname) do |f|
+ @data = YAML.load(f.read)
+ end
+ else
+ @data = DEFAULT_SETTING
+ end
+ end
+
+ hash_method :home_title
+ hash_method :home_icon
+
+ hash_method :header_title
+ hash_method :header_icon
+
+ def about_milkode
+ if (@data[:display_about_milkode])
+ ', <a href="http://milkode.ongaeshi.me">milkodeについて</a>'
+ else
+ ''
+ end
+ end
+ end
+end
+
@@ -1,5 +1,5 @@
.header
%h1
- <a href="/"><img src="/images/MilkodeIcon135.png" alt="milkode-icon-mini" border="0" height="75px"/></a>
- Milkode
+ <a href="/"><img src=#{@setting.header_icon} alt="milkode-icon-mini" border="0" height="75px"/></a>
+ #{@setting.header_title}
= create_headmenu(@path, params, defined?(flistpath) ? flistpath : '')
@@ -2,8 +2,8 @@
.header
%h1
- <a href="/"><img src="/images/MilkodeIcon135.png" alt="milkode-icon-mini" border="0" height="75px"/></a>
- #{@title} - Milkode
+ <a href="/"><img src=#{@setting.header_icon} alt="milkode-icon-mini" border="0" height="75px"/></a>
+ #{@title} - #{@setting.header_title}
.content
.sample-code
@@ -1,6 +1,6 @@
%div(align="center")
.header_home
- %h1 <a href="/"><img src="/images/MilkodeIcon135.png" alt="milkode-icon" border="0" height="135px"/></a> Milkode <font class="version">#{@version}</font>
+ %h1 <a href="/"><img src=#{@setting.home_icon} alt="milkode-icon" border="0" height="135px"/></a> #{@setting.home_title} <font class="version">#{@version}</font>
.content
%form(method="post" action="/search")
@@ -12,7 +12,7 @@
.footer_home
<a href="/home">#{@package_num}</a>のパッケージ<br>
<a href="/home?query=f:*">#{@file_num}</a>のファイル<br>
- <a href="/help">ヘルプ</a> ,
- <a href="http://milkode.ongaeshi.me">milkodeについて</a>
+ <a href="/help">ヘルプ</a>
+ = @setting.about_milkode

0 comments on commit 3013114

Please sign in to comment.