narou 2.2.0 → 2.3.0.pre.test1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of narou might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a9cc66fa7d7873927dcdac0675c060686d8c6bb
4
- data.tar.gz: c44b78430ef874d4488667174da67d02eea7ef42
3
+ metadata.gz: 327c038f5e42467a9985f1b1b52c7f17c5210e55
4
+ data.tar.gz: 575c24c68e7096c5f9783e23ab83129008784b68
5
5
  SHA512:
6
- metadata.gz: 7501674b3578691b88163968d81630077df110b455423aaea166924391b0418610f51c3af7baf4ceb1913933ad32daa62d293c578cb7b6d60db7699becf33317
7
- data.tar.gz: 1a93c12d0aa52b059c94e0344dabcf19f00882119eb0f129518a4309ea3c97c378afde947c7c038a578f71c33c4b2208ca19488b4b296e6b41e3f168f579bed7
6
+ metadata.gz: 57fb75c7730087201accffda2ef0f24b24cb5b85c7c30c236e9b6e15666690287be0e80d74304924c07222342bc69310f0bb1775e30178f09552a8f3b2294719
7
+ data.tar.gz: 4f8eec0a920e12c083bca9df8987b3292782b9da7863988fb1b99d4b2601723110141426b3cc9a5238ad389d4a54a0184d0ce7b3d6b123993714bf0711f5c684
data/ChangeLog.md CHANGED
@@ -2,6 +2,20 @@
2
2
  更新履歴 - ChangeLog
3
3
  ====================
4
4
 
5
+ 2.3.0 : 2015/xx/xx
6
+ ------------------
7
+ #### 追加機能
8
+ - Kindle端末で単語の選択を出来るようにするために、小説別変換設定に
9
+ `enable_insert_word_separator` オプションが追加されました
10
+ + このオプションを使うためには `narou init` を実行して AozoraEpub3 の設定を
11
+ 修正する必要があります
12
+ + 各小説の setting.ini 内に `enable_insert_word_separator=true` と追加で書き
13
+ 込むか、 `narou s force.enable_insert_word_separator=true` とコマンドを打ち
14
+ 込むことで有効に出来ます。(WEB UI で設定すると楽です)
15
+ + このオプションは、Kindle端末で単語が選択出来ない問題に対応するものです。
16
+ device が kindle の時のみ使用可能です。また、Send to Kindle で mobi を azw3
17
+ に変換する場合は単語選択は可能なので、設定する必要はありません
18
+
5
19
  2.2.0 : 2015/02/19
6
20
  ------------------
7
21
  #### 追加機能
@@ -97,6 +97,17 @@ module Command
97
97
  trigger(:error, msg, name)
98
98
  end
99
99
 
100
+ def sweep_dust_variable(target_name, settings)
101
+ deleted = false
102
+ settings.each_value do |scoped_settings|
103
+ if scoped_settings.has_key?(target_name)
104
+ scoped_settings.delete(target_name)
105
+ deleted = true
106
+ end
107
+ end
108
+ deleted
109
+ end
110
+
100
111
  def execute(argv)
101
112
  super
102
113
  if argv.empty?
@@ -116,15 +127,25 @@ module Command
116
127
  output_error("書式が間違っています。変数名=値 のように書いて下さい")
117
128
  next
118
129
  end
119
- scope = get_scope_of_variable_name(name)
120
- unless scope
121
- output_error("#{name} という変数は存在しません", name)
122
- next
123
- end
124
130
  if value.nil?
125
131
  output_error("書式が間違っています。#{name}=値 のように書いて下さい", name)
126
132
  next
127
133
  end
134
+ scope = get_scope_of_variable_name(name)
135
+ unless scope
136
+ if value == ""
137
+ # 定義上ではすでに存在しないが、設定ファイルには残っている古い変数
138
+ # を削除できるようにする
139
+ if sweep_dust_variable(name, settings)
140
+ puts "#{name} の設定を削除しました"
141
+ else
142
+ output_error("#{name} という変数は存在しません", name)
143
+ end
144
+ else
145
+ output_error("#{name} という変数は設定出来ません", name)
146
+ end
147
+ next
148
+ end
128
149
  if value == ""
129
150
  hook_call(:modify_settings, settings[scope], name, nil)
130
151
  next
data/lib/converterbase.rb CHANGED
@@ -7,6 +7,7 @@ require "stringio"
7
7
  require "date"
8
8
  require "uri"
9
9
  require "nkf"
10
+ require_relative "narou"
10
11
  require_relative "progressbar"
11
12
  require_relative "inspector"
12
13
 
@@ -52,6 +53,7 @@ class ConverterBase
52
53
  @num_and_comma_list = {}
53
54
  @force_indent_special_chapter_list = {}
54
55
  @in_author_comment_block = nil
56
+ @device = Narou.get_device
55
57
  end
56
58
 
57
59
  def outputs(data = "", force = false)
@@ -399,9 +401,8 @@ class ConverterBase
399
401
  # おかしくなりやすい矢印文字の変換
400
402
  #
401
403
  def convert_arrow(data)
402
- @@device ||= Narou.get_device
403
404
  # Kindle PW でしか確認してないのでとりあえず device=kindle の場合のみ変換
404
- if @@device && @@device.kindle?
405
+ if @device && @device.kindle?
405
406
  data.tr!("⇒⇐", "→←")
406
407
  end
407
408
  end
@@ -1129,6 +1130,49 @@ class ConverterBase
1129
1130
  after(io, @text_type)
1130
1131
  end
1131
1132
 
1133
+ WORD_SEPARATOR = "[#zws]"
1134
+
1135
+ def insert_word_separator(str)
1136
+ return str unless @setting.enable_insert_word_separator && @device && @device.kindle?
1137
+ return str if @text_type != "body" && @text_type != "textfile"
1138
+ buffer = ""
1139
+ ss = StringScanner.new(str)
1140
+ before_symbol = false
1141
+ while char = ss.getch
1142
+ symbol = false
1143
+ case char
1144
+ when "["
1145
+ if ss.scan(/^#.+?]/)
1146
+ buffer << "[#{ss.matched}"
1147
+ next
1148
+ end
1149
+ symbol = true
1150
+ when /[\d0-9]/
1151
+ ss.scan(/[\d0-9]+/)
1152
+ when /[ぁ-んゝゞ]/
1153
+ ss.scan(/[ぁ-んゝゞー]+/)
1154
+ when /[ァ-ヶ]/
1155
+ ss.scan(/[ァ-ヶー・]+/)
1156
+ when /[A-Za-zA-Za-z]/
1157
+ ss.scan(/[A-Za-zA-Za-z]+/)
1158
+ when /[一-龥朗-鶴]/
1159
+ ss.scan(/[一-龥朗-鶴]+/)
1160
+ else
1161
+ symbol = true
1162
+ end
1163
+ if before_symbol && !symbol
1164
+ buffer << WORD_SEPARATOR
1165
+ end
1166
+ buffer << char
1167
+ unless symbol
1168
+ buffer << ss.matched if ss.matched?
1169
+ buffer << WORD_SEPARATOR
1170
+ end
1171
+ before_symbol = symbol
1172
+ end
1173
+ buffer
1174
+ end
1175
+
1132
1176
  def convert(text, text_type)
1133
1177
  return "" if text == ""
1134
1178
  @text_type = text_type
@@ -1136,7 +1180,7 @@ class ConverterBase
1136
1180
  (io = before_convert(io)).rewind
1137
1181
  (io = convert_main(io)).rewind
1138
1182
  (io = after_convert(io)).rewind
1139
- return io.read
1183
+ return insert_word_separator(io.read)
1140
1184
  end
1141
1185
 
1142
1186
  #
@@ -1228,7 +1272,6 @@ class ConverterBase
1228
1272
  convert_double_angle_quotation_to_gaiji(data)
1229
1273
  delete_dust_char(data)
1230
1274
  if title_and_author
1231
- puts title_and_author
1232
1275
  data.replace(title_and_author + data)
1233
1276
  end
1234
1277
  data.rstrip!
data/lib/device/ibooks.rb CHANGED
@@ -23,7 +23,7 @@ module Device::Ibooks
23
23
  @@__ibooks_container_dir = File.expand_path(IBOOKS_CONTAINER_DIR)
24
24
  unless File.exist?(@@__ibooks_container_dir)
25
25
  error "iBooksの管理フォルダが見つかりませんでした。" \
26
- "MacOSX Mavericks以降のiBooksのみ管理に対応しています"
26
+ "OSX Mavericks以降のiBooksのみ管理に対応しています"
27
27
  @@__ibooks_container_dir = nil
28
28
  end
29
29
  @@__already_exec_change_settings = true
@@ -159,7 +159,8 @@ class NovelConverter
159
159
  # 失敗した場合はjavaが実行できない場合と確定できる
160
160
  unless res[2].success?
161
161
  puts
162
- error "Javaがインストールされていない可能性があります。EPUBを作成出来ませんでした"
162
+ puts res
163
+ error "JavaがインストールされていないかAozoraEpub3実行時にエラーが発生しました。EPUBを作成出来ませんでした"
163
164
  return :error
164
165
  end
165
166
 
data/lib/novelsetting.rb CHANGED
@@ -341,5 +341,11 @@ class NovelSetting
341
341
  value: true,
342
342
  help: "漢字の二と間違えてカタカナのニを使っていそうなのを、漢字に直すかどうか"
343
343
  },
344
+ {
345
+ name: "enable_insert_word_separator",
346
+ type: :boolean,
347
+ value: false,
348
+ help: "単語選択がうまく出来るようにダミーの区切りデータを挿入する(Kindle専用)"
349
+ },
344
350
  ]
345
351
  end
data/lib/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  # Copyright 2013 whiteleaf. All rights reserved.
4
4
  #
5
5
 
6
- Version = "2.2.0"
6
+ Version = "2.3.0-test1"
7
7
 
@@ -15,5 +15,6 @@
15
15
  濁点終わり </span>
16
16
  ここから柱 <div class="running_head yoko"> 1
17
17
  ここで柱終わり </div> 1
18
+ zws &#8203;
18
19
 
19
- ### Narou.rb embedded custom chuki ###
20
+ ### Narou.rb embedded custom chuki ###
@@ -12,10 +12,13 @@ describe ConverterBase do
12
12
  novelsetting = NovelSetting.new("", true)
13
13
  inspector = Inspector.new(novelsetting)
14
14
  @converter = ConverterBase.new(novelsetting, inspector, nil)
15
- @converter.instance_variable_set(:@text_type, "textfile")
16
15
  end
17
16
 
18
17
  context "#erase_comments_block" do
18
+ before do
19
+ @converter.instance_variable_set(:@text_type, "textfile")
20
+ end
21
+
19
22
  context "コメントブロックが存在した場合" do
20
23
  before do
21
24
  @text = <<-EOS
@@ -69,22 +72,88 @@ opqrstu
69
72
  context "#modify_kana_ni_to_kanji_ni" do
70
73
  describe "ニ(カタカナ)の前後1文字がカタカナの場合" do
71
74
  it "カタカナのまま" do
72
- expect(@converter.modify_kana_ni_to_kanji_ni("イチニサン")). to eq "イチニサン"
73
- expect(@converter.modify_kana_ni_to_kanji_ni("ニーサン")). to eq "ニーサン"
75
+ expect(@converter.modify_kana_ni_to_kanji_ni("イチニサン")).to eq "イチニサン"
76
+ expect(@converter.modify_kana_ni_to_kanji_ni("ニーサン")).to eq "ニーサン"
74
77
  end
75
78
  end
76
79
 
77
80
  describe "ニ(カタカナ)の前後1文字がカタカナではなく、さらにその前後がカタカナの場合" do
78
81
  it "カタカナのまま" do
79
- expect(@converter.modify_kana_ni_to_kanji_ni("イチ、ニ、サン")). to eq "イチ、ニ、サン"
80
- expect(@converter.modify_kana_ni_to_kanji_ni("『ニ、ニンゲンの――』")). to eq "『ニ、ニンゲンの――』"
81
- expect(@converter.modify_kana_ni_to_kanji_ni("ニ、ニンゲン")). to eq "ニ、ニンゲン"
82
+ expect(@converter.modify_kana_ni_to_kanji_ni("イチ、ニ、サン")).to eq "イチ、ニ、サン"
83
+ expect(@converter.modify_kana_ni_to_kanji_ni("『ニ、ニンゲンの――』")).to eq "『ニ、ニンゲンの――』"
84
+ expect(@converter.modify_kana_ni_to_kanji_ni("ニ、ニンゲン")).to eq "ニ、ニンゲン"
82
85
  end
83
86
  end
84
87
 
85
88
  describe "ニ(カタカナ)の前後1文字がカタカナではなく、さらにその前後がカタカナではない場合" do
86
89
  it "漢字の二に修正する" do
87
- expect(@converter.modify_kana_ni_to_kanji_ni("価格はニ千万円")). to eq "価格は二千万円"
90
+ expect(@converter.modify_kana_ni_to_kanji_ni("価格はニ千万円")).to eq "価格は二千万円"
91
+ end
92
+ end
93
+ end
94
+
95
+ context "#insert_word_separator" do
96
+ before do
97
+ @converter.instance_variable_set(:@text_type, "body")
98
+ setting = @converter.instance_variable_get(:@setting)
99
+ setting.enable_insert_word_separator = true
100
+ end
101
+
102
+ describe "Kindle以外" do
103
+ before do
104
+ @converter.instance_variable_set(:@device, Narou.get_device("reader"))
105
+ end
106
+
107
+ it "何も弄らない" do
108
+ expect(@converter.insert_word_separator("今日もいい天気ですね")).to eq "今日もいい天気ですね"
109
+ end
110
+ end
111
+
112
+ describe "Kindleの場合" do
113
+ before do
114
+ @converter.instance_variable_set(:@device, Narou.get_device("kindle"))
115
+ end
116
+
117
+ it do
118
+ expect(@converter.insert_word_separator \
119
+ "今日もいい天気ですね").to eq \
120
+ "今日[#zws]もいい[#zws]天気[#zws]ですね[#zws]"
121
+ end
122
+
123
+ it do
124
+ expect(@converter.insert_word_separator \
125
+ "合計1500円です").to eq \
126
+ "合計[#zws]1500[#zws]円[#zws]です[#zws]"
127
+ end
128
+
129
+ it do
130
+ expect(@converter.insert_word_separator \
131
+ "[#二分アキ]「注釈内は区切らない」").to eq \
132
+ "[#二分アキ]「[#zws]注釈内[#zws]は[#zws]区切[#zws]らない[#zws]」"
133
+ end
134
+
135
+ it do
136
+ expect(@converter.insert_word_separator \
137
+ "あいう・えお").to eq \
138
+ "あいう[#zws]・[#zws]えお[#zws]"
139
+ end
140
+
141
+ it do
142
+ expect(@converter.insert_word_separator \
143
+ "アイウ・エオ").to eq \
144
+ "アイウ・エオ[#zws]"
145
+ end
146
+
147
+ it do
148
+ expect(@converter.insert_word_separator \
149
+ "彼は――そう……言った").to eq \
150
+ "彼[#zws]は[#zws]――[#zws]そう[#zws]……[#zws]言[#zws]った[#zws]"
151
+ end
152
+
153
+ it do
154
+ expect(@converter.insert_word_separator \
155
+ "「あいう」、「えお」").to eq \
156
+ "「[#zws]あいう[#zws]」、「[#zws]えお[#zws]」"
88
157
  end
89
158
  end
90
159
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: narou
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0.pre.test1
5
5
  platform: ruby
6
6
  authors:
7
7
  - whiteleaf7
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-19 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: termcolorlight
@@ -445,9 +445,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
445
445
  version: 1.9.3
446
446
  required_rubygems_version: !ruby/object:Gem::Requirement
447
447
  requirements:
448
- - - ">="
448
+ - - ">"
449
449
  - !ruby/object:Gem::Version
450
- version: '0'
450
+ version: 1.3.1
451
451
  requirements: []
452
452
  rubyforge_project:
453
453
  rubygems_version: 2.4.5