Class: Milkode::CLI_Cdweb

Inherits:
Object
  • Object
show all
Defined in:
lib/milkode/cdweb/cli_cdweb.rb

Class Method Summary collapse

Class Method Details

.create_customize_file(dbdir) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/milkode/cdweb/cli_cdweb.rb', line 67

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"
:home_font_size : "100%"

:header_title: "Milkode"
:header_icon : "/images/MilkodeIcon135.png"

:favicon: "/images/favicon.ico"

:display_about_milkode: true
:hide_update_button: false

:eliminate_extname: ""
EOF
    end
  end
end

.create_launch_url(options) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/milkode/cdweb/cli_cdweb.rb', line 42

def self.create_launch_url(options)
  if (options[:LaunchBrowser])
    host = options[:Host] || options[:BindAddress] # options[:BindAddress] for WEBrick

    base = "http://#{host}:#{options[:Port]}"

    if options[:url]
      File.join(base, options[:url])
    else
      "http://#{host}:#{options[:Port]}"
    end
  else
    nil
  end
end

.execute_with_options(stdout, options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/milkode/cdweb/cli_cdweb.rb', line 10

def self.execute_with_options(stdout, options)
  dbdir = File.expand_path(options[:DbDir])
  
  unless options[:customize]
    # 使用するデータベースの位置設定
    Database.setup(dbdir)

    # サーバースクリプトのある場所へ移動
    FileUtils.cd(File.dirname(__FILE__))

    # Rackサーバー生成
    rack_server = Rack::Server.new(options)

    # 起動URL生成
    launch_url = create_launch_url(options)

    # URL設定
    ENV['MILKODE_RELATIVE_URL'] = File.join('/', options[:url]) if options[:url]

    # Allow "http://127.0.0.1:9292/gomilk"
    ENV['MILKODE_SUPPORT_GOMILK'] = "true" if options[:gomilk]

    # 起動
    rack_server.start do
      # この時点でoptions[:Host]やoptions[:Port]などの値が壊れてしまっているため事前にURLを生成している
      Launchy.open(launch_url) if launch_url
    end
  else
    create_customize_file(dbdir)
  end
end

.select_dbdirObject



58
59
60
61
62
63
64
65
# File 'lib/milkode/cdweb/cli_cdweb.rb', line 58

def self.select_dbdir
  # if (Dbdir.dbdir?('.') || !Dbdir.dbdir?(Dbdir.default_dir))
  if Dbdir.dbdir?('.')
    '.'
  else
    Dbdir.default_dir
  end
end