Module: Narou
- Extended by:
- Memoist
- Defined in:
- lib/web/settingmessages.rb,
lib/input.rb,
lib/narou.rb,
lib/logger.rb,
lib/narou/api.rb,
lib/web/pushserver.rb,
lib/web/streaminginput.rb
Overview
Copyright 2013 whiteleaf. All rights reserved.
Defined Under Namespace
Modules: Eventable, Input, LoggerModule, ServerHelpers
Classes: API, AppServer, Logger, LoggerError, PushServer, StreamingLogger, Worker
Constant Summary
collapse
- LOCAL_SETTING_DIR =
".narou"
- GLOBAL_SETTING_DIR =
".narousetting"
- AOZORAEPUB3_JAR_NAME =
"AozoraEpub3.jar"
- AOZORAEPUB3_DIR =
"AozoraEpub3"
- PRESET_DIR =
"preset"
- MISC_DIR =
"misc"
- GLOBAL_REPLACE_NAME =
"replace.txt"
- EXIT_ERROR_CODE =
127
- EXIT_INTERRUPT =
126
- UPDATE_SORT_KEYS =
{
"id" => "ID", "last_update" => "更新日", "title" => "タイトル", "author" => "作者名",
"new_arrivals_date" => "新着日", "general_lastup" => "最新話掲載日"
}
- SETTING_VARIABLES_WEBUI_MESSAGES =
WEB UI > 環境設定画面で表示する各項目の説明 ここになければ元々の説明が表示される
{
"convert.multi-device" => "複数の端末用に同時に変換する。deviceよりも優先される。\nただのEPUBを出力したい場合はepubを指定",
"device" => "変換、送信対象の端末",
"difftool" => "Diffで使うツールのパスを指定する\n※WEB UIでは使われません",
"update.sort-by" => "アップデートを指定した項目順で行う",
"default.title_date_align" => "enable_add_date_to_title で付与する日付の位置",
"force.title_date_align" => "enable_add_date_to_title で付与する日付の位置",
"difftool.arg" => "difftoolで使う引数(指定しなければ単純に新旧ファイルを引数に呼び出す)\n" \
"特殊な変数\n" \
"<b>%NEW</b> : 最新データの差分用ファイルパス\n" \
"<b>%OLD</b> : 古い方の差分用ファイルパス",
"no-color" => "コンソールのカラー表示を無効にする\n※要WEB UIサーバ再起動",
"economy" => "容量節約に関する設定"
}
- @@is_web =
false
Class Method Summary
collapse
Class Method Details
.alias_to_id(target) ⇒ Object
target が alias だった場合はIDに変換する
全てのtarget照合系はこのメソッドを通過するので、ここで小文字にしてしまう
95
96
97
98
99
100
101
|
# File 'lib/narou.rb', line 95
def alias_to_id(target)
aliases = Inventory.load("alias")
if aliases[target]
return aliases[target]
end
target.kind_of?(Numeric) ? target : target.downcase
end
|
.already_init? ⇒ Boolean
79
80
81
|
# File 'lib/narou.rb', line 79
def already_init?
!!get_root_dir
end
|
.aozoraepub3_directory?(path) ⇒ Boolean
117
118
119
|
# File 'lib/narou.rb', line 117
def aozoraepub3_directory?(path)
File.exist?(create_aozoraepub3_jar_path(path))
end
|
.create_aozoraepub3_jar_path(*paths) ⇒ Object
113
114
115
|
# File 'lib/narou.rb', line 113
def create_aozoraepub3_jar_path(*paths)
File.expand_path(File.join(*paths, AOZORAEPUB3_JAR_NAME))
end
|
.create_novel_filename(novel_data, ext = "") ⇒ Object
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# File 'lib/narou.rb', line 186
def create_novel_filename(novel_data, ext = "")
filename_to_ncode = Inventory.load("local_setting")["convert.filename-to-ncode"]
if filename_to_ncode && novel_data["ncode"]
serialized_domain = novel_data["domain"].to_s.gsub(".", "_")
%!#{serialized_domain}_#{novel_data["ncode"]}#{ext}!
else
if filename_to_ncode
puts "<yellow>ファイル名をNコードにするには一度以上小説を更新して下さい</yellow>".termcolor
end
author, title = %w(author title).map { |k|
Helper.replace_filename_special_chars(novel_data[k], true)
}
"[#{author}] #{title}#{ext}"
end
end
|
.economy?(mode) ⇒ Boolean
257
258
259
260
|
# File 'lib/narou.rb', line 257
def economy?(mode)
eco_modes = Inventory.load("local_setting")["economy"].to_s.split(",").map(&:strip)
eco_modes.include?(mode)
end
|
.get_aozoraepub3_path ⇒ Object
AozoraEpub3 の実行ファイル(.jar)のフルパス取得 検索順序
-
グローバルセッティング (global_setting aozoraepub3dir)
-
小説保存ディレクトリ(Narou.get_root_dir) 直下の AozoraEpub3
-
スクリプト保存ディレクトリ(Narou.get_script_dir) 直下の AozoraEpub3
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/narou.rb', line 168
def get_aozoraepub3_path
global_setting_aozora_path = Inventory.load("global_setting", :global)["aozoraepub3dir"]
if global_setting_aozora_path
aozora_jar_path = create_aozoraepub3_jar_path(global_setting_aozora_path)
if File.exist?(aozora_jar_path)
return aozora_jar_path
end
end
[Narou.get_root_dir, Narou.get_script_dir].each do |dir|
aozora_jar_path = create_aozoraepub3_jar_path(dir, AOZORAEPUB3_DIR)
if File.exist?(aozora_jar_path)
return aozora_jar_path
end
end
nil
end
|
.get_device(device_name = nil) ⇒ Object
219
220
221
222
223
224
225
|
# File 'lib/narou.rb', line 219
def get_device(device_name = nil)
device_name = Inventory.load("local_setting")["device"] unless device_name
if device_name && Device.exists?(device_name)
return Device.create(device_name)
end
nil
end
|
.get_ebook_file_path(target, ext) ⇒ Object
.get_global_setting_dir ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/narou.rb', line 65
def get_global_setting_dir
global_setting_dir = File.expand_path(File.join("~", GLOBAL_SETTING_DIR))
unless File.exist?(global_setting_dir)
FileUtils.mkdir(global_setting_dir)
end
global_setting_dir
end
|
.get_local_setting_dir ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/narou.rb', line 55
def get_local_setting_dir
local_setting_dir = nil
root_dir = get_root_dir
if root_dir
local_setting_dir = File.join(root_dir, LOCAL_SETTING_DIR)
end
local_setting_dir
end
|
.get_misc_dir ⇒ Object
213
214
215
|
# File 'lib/narou.rb', line 213
def get_misc_dir
File.join(get_root_dir, MISC_DIR)
end
|
.get_mobi_path(target) ⇒ Object
202
203
204
|
# File 'lib/narou.rb', line 202
def get_mobi_path(target)
get_ebook_file_path(target, ".mobi")
end
|
.get_preset_dir ⇒ Object
108
109
110
|
# File 'lib/narou.rb', line 108
def get_preset_dir
File.expand_path(File.join(get_script_dir, PRESET_DIR))
end
|
.get_root_dir ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/narou.rb', line 35
def get_root_dir
root_dir = nil
path = Dir.pwd
drive_letter = ""
if Helper.os_windows?
path.encode!(Encoding::UTF_8)
path.gsub!(/^[a-z]:/i, "")
drive_letter = $&
end
while path != ""
if File.directory?("#{drive_letter}#{path}/#{LOCAL_SETTING_DIR}")
root_dir = drive_letter + path
break
end
path.gsub!(%r!/[^/]*$!, "")
end
root_dir
end
|
.get_script_dir ⇒ Object
74
75
76
|
# File 'lib/narou.rb', line 74
def get_script_dir
File.expand_path(File.join(File.dirname(__FILE__), ".."))
end
|
.get_theme ⇒ Object
241
242
243
|
# File 'lib/narou.rb', line 241
def get_theme
Inventory.load("local_setting")["theme"]
end
|
.get_theme_dir(name = nil) ⇒ Object
245
246
247
|
# File 'lib/narou.rb', line 245
def get_theme_dir(name = nil)
File.join([get_script_dir, "lib/web/public/theme", name].compact)
end
|
.get_theme_names ⇒ Object
249
250
251
252
253
254
|
# File 'lib/narou.rb', line 249
def get_theme_names
Dir.glob(get_theme_dir("*")).map do |path|
name = File.basename(path)
name == "fonts" ? nil : name
end.compact
end
|
.global_replace_pattern ⇒ Object
152
153
154
|
# File 'lib/narou.rb', line 152
def global_replace_pattern
@@global_replace_pattern_pairs ||= load_global_replace_pattern
end
|
.load_global_replace_pattern ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/narou.rb', line 139
def load_global_replace_pattern
path = File.join(get_root_dir, GLOBAL_REPLACE_NAME)
if File.exist?(path)
pairs = Helper::CacheLoader.memo(path) do |text|
parse_replace_txt(text)
end
else
pairs = []
end
@@global_replace_pattern_pairs = pairs
pairs
end
|
.novel_frozen?(target) ⇒ Boolean
.parse_replace_txt(text) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/narou.rb', line 121
def parse_replace_txt(text)
pattern = []
text.each_line do |line|
line.sub!(/[\r\n]+\z/, "")
next if line[0] == ";" pair = line.split("\t", 2)
if pair.length == 2 && pair[0]
pattern << pair
end
end
pattern
end
|
.save_global_replace_pattern ⇒ Object
156
157
158
159
|
# File 'lib/narou.rb', line 156
def save_global_replace_pattern
path = File.join(get_root_dir, GLOBAL_REPLACE_NAME)
write_replace_txt(path, @@global_replace_pattern_pairs)
end
|
.update_sort_key_summaries(width = 27) ⇒ Object
235
236
237
238
239
|
# File 'lib/narou.rb', line 235
def update_sort_key_summaries(width = 27)
({"KEY" => "対象"}.merge(UPDATE_SORT_KEYS)).map { |(key, summary)|
"#{key.rjust(width)} : #{summary}"
}.join("\n")
end
|
.web=(bool) ⇒ Object
227
228
229
|
# File 'lib/narou.rb', line 227
def web=(bool)
@@is_web = bool
end
|
.web? ⇒ Boolean
231
232
233
|
# File 'lib/narou.rb', line 231
def web?
@@is_web
end
|
.write_replace_txt(path, pairs) ⇒ Object
134
135
136
137
|
# File 'lib/narou.rb', line 134
def write_replace_txt(path, pairs)
buffer = pairs.each_with_object("\t").map(&:join).join("\n")
File.write(path, buffer)
end
|