narou 1.7.2 → 2.0.0

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.

Files changed (100) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +1 -0
  3. data/ChangeLog.md +35 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE.txt +100 -0
  6. data/README.md +28 -39
  7. data/lib/color.rb +0 -2
  8. data/lib/command.rb +1 -0
  9. data/lib/command/convert.rb +33 -4
  10. data/lib/command/diff.rb +5 -4
  11. data/lib/command/download.rb +9 -1
  12. data/lib/command/flag.rb +2 -2
  13. data/lib/command/list.rb +1 -1
  14. data/lib/command/mail.rb +3 -3
  15. data/lib/command/remove.rb +2 -1
  16. data/lib/command/send.rb +7 -6
  17. data/lib/command/setting.rb +39 -95
  18. data/lib/command/tag.rb +25 -13
  19. data/lib/command/update.rb +6 -1
  20. data/lib/command/version.rb +5 -1
  21. data/lib/command/web.rb +111 -0
  22. data/lib/commandbase.rb +5 -2
  23. data/lib/commandline.rb +16 -0
  24. data/lib/converterbase.rb +20 -14
  25. data/lib/device.rb +5 -4
  26. data/lib/downloader.rb +68 -39
  27. data/lib/eventable.rb +72 -0
  28. data/lib/helper.rb +105 -37
  29. data/lib/ini.rb +2 -1
  30. data/lib/input.rb +68 -0
  31. data/lib/inventory.rb +4 -0
  32. data/lib/kindlestrip.rb +2 -2
  33. data/lib/logger.rb +41 -19
  34. data/lib/narou.rb +10 -0
  35. data/lib/narou/api.rb +1 -1
  36. data/lib/novelconverter.rb +8 -21
  37. data/lib/novelsetting.rb +79 -4
  38. data/lib/version.rb +1 -1
  39. data/lib/web/all.rb +12 -0
  40. data/lib/web/appserver.rb +612 -0
  41. data/lib/web/helper4web.rb +15 -0
  42. data/lib/web/progressbar4web.rb +32 -0
  43. data/lib/web/public/favicon.ico +0 -0
  44. data/lib/web/public/resources/bootbox.min.js +6 -0
  45. data/lib/web/public/resources/common.ui.js +143 -0
  46. data/lib/web/public/resources/dataTables.colVis.js +1113 -0
  47. data/lib/web/public/resources/help/rect_select.png +0 -0
  48. data/lib/web/public/resources/help/ssmain.png +0 -0
  49. data/lib/web/public/resources/help/tag.png +0 -0
  50. data/lib/web/public/resources/jquery.moveto.js +44 -0
  51. data/lib/web/public/resources/jquery.outerclick.js +60 -0
  52. data/lib/web/public/resources/jquery.slidenavbar.js +89 -0
  53. data/lib/web/public/resources/narou.library.js +815 -0
  54. data/lib/web/public/resources/narou.ui.js +993 -0
  55. data/lib/web/public/resources/perfect-scrollbar.min.css +5 -0
  56. data/lib/web/public/resources/perfect-scrollbar.min.js +4 -0
  57. data/lib/web/public/resources/shortcut.js +223 -0
  58. data/lib/web/public/resources/sort_asc.png +0 -0
  59. data/lib/web/public/resources/sort_desc.png +0 -0
  60. data/lib/web/public/resources/toggle-switch.css +322 -0
  61. data/lib/web/public/robots.txt +3 -0
  62. data/lib/web/public/test/jquery.outerclick.html +72 -0
  63. data/lib/web/pushserver.rb +110 -0
  64. data/lib/web/settingmessages.rb +14 -0
  65. data/lib/web/streaminginput.rb +103 -0
  66. data/lib/web/streaminglogger.rb +52 -0
  67. data/lib/web/views/about.haml +11 -0
  68. data/lib/web/views/help.haml +105 -0
  69. data/lib/web/views/index.haml +245 -0
  70. data/lib/web/views/js/widget.erb +74 -0
  71. data/lib/web/views/layout.haml +49 -0
  72. data/lib/web/views/novels/setting.haml +177 -0
  73. data/lib/web/views/settings.haml +115 -0
  74. data/lib/web/views/style.scss +737 -0
  75. data/lib/web/views/widget.haml +39 -0
  76. data/lib/web/web-socket-ruby/.gitignore +1 -0
  77. data/lib/web/web-socket-ruby/README.txt +75 -0
  78. data/lib/web/web-socket-ruby/lib/web_socket.rb +601 -0
  79. data/lib/web/web-socket-ruby/samples/chat_server.rb +58 -0
  80. data/lib/web/web-socket-ruby/samples/echo_server.rb +33 -0
  81. data/lib/web/web-socket-ruby/samples/stdio_client.rb +25 -0
  82. data/lib/web/worker.rb +87 -0
  83. data/narou.gemspec +36 -3
  84. data/narou.rb +8 -6
  85. data/preset/ncode.syosetu.com/n8725k/converter.rb +2 -1
  86. data/spec/data/convert_test/replace/correct_test_replace.txt +1 -1
  87. data/spec/data/convert_test/replace/test_replace.txt +1 -1
  88. data/spec/data/convert_test/ruby/correct_test_ruby.txt +18 -1
  89. data/spec/data/convert_test/ruby/test_ruby.txt +18 -0
  90. data/spec/downloader_spec.rb +37 -0
  91. data/spec/eventable_spec.rb +172 -0
  92. data/spec/exit_code_spec.rb +67 -0
  93. data/spec/helper_spec.rb +72 -0
  94. data/spec/input_spec.rb +76 -0
  95. data/spec/logger_spec.rb +53 -0
  96. data/spec/novelsetting_spec.rb +35 -0
  97. data/spec/worker_spec.rb +56 -0
  98. data/template/ibunko_novel.txt.erb +2 -2
  99. data/template/novel.txt.erb +2 -2
  100. metadata +213 -29
@@ -0,0 +1,172 @@
1
+ # -*- Encoding: utf-8 -*-
2
+ #
3
+ # Copyright 2013 whiteleaf. All rights reserved.
4
+ #
5
+
6
+ module Narou end
7
+ require_relative "../lib/eventable"
8
+
9
+ class Dummy
10
+ include Narou::Eventable
11
+ end
12
+
13
+ describe Narou::Eventable do
14
+ context "when an event exist" do
15
+ before do
16
+ @temp1 = 0
17
+ Dummy.add_event_listener(:regist_new_book) do
18
+ @temp1 = 1
19
+ end
20
+ end
21
+
22
+ it "should triggered event" do
23
+ Dummy.trigger_event(:regist_new_book)
24
+ expect(@temp1).to eq 1
25
+ end
26
+ end
27
+
28
+ context "when multi events exist" do
29
+ before do
30
+ @temp1 = 0
31
+ Dummy.add_event_listener(:temp_add_event) do
32
+ @temp1 += 1
33
+ end
34
+ Dummy.add_event_listener(:temp_add_event) do
35
+ @temp1 += 1
36
+ end
37
+ end
38
+
39
+ it "should be @temp1 eq 2" do
40
+ Dummy.trigger_event(:temp_add_event)
41
+ expect(@temp1).to eq 2
42
+ end
43
+ end
44
+
45
+ context "when give arguments" do
46
+ it do
47
+ Dummy.add_event_listener(:give_argument) do |arg|
48
+ expect(arg).to eq 0
49
+ end
50
+ Dummy.trigger_event(:give_arguments, 0)
51
+ end
52
+
53
+ it do
54
+ Dummy.add_event_listener(:give_arguments) do |arg1, arg2|
55
+ expect(arg1).to eq 1
56
+ expect(arg2).to eq :two
57
+ end
58
+ Dummy.trigger_event(:give_arguments, 1, :two)
59
+ end
60
+ end
61
+
62
+ context "without block" do
63
+ it "should be raise error" do
64
+ expect { Dummy.add_event_listener(:test1) }.to raise_error(Narou::Eventable::NonBlockError)
65
+ end
66
+ end
67
+
68
+ context "if do not register events yet" do
69
+ it "do nothing" do
70
+ expect { Dummy.trigger_event(:dont_registered_event) }.not_to raise_error
71
+ end
72
+ end
73
+
74
+ context "when call #add_event_listener and .add_event_listener" do
75
+ before do
76
+ @anser = nil
77
+ @dummy = Dummy.new
78
+ @dummy.add_event_listener(:instance_or_class) do
79
+ @anser = :instance
80
+ end
81
+ Dummy.add_event_listener(:instance_or_class) do
82
+ @anser = :class
83
+ end
84
+ end
85
+
86
+ it "instance method is called" do
87
+ @dummy.trigger_event(:instance_or_class)
88
+ expect(@anser).to eq :instance
89
+ end
90
+
91
+ it "class method is called" do
92
+ Dummy.trigger_event(:instance_or_class)
93
+ expect(@anser).to eq :class
94
+ end
95
+ end
96
+
97
+ context "multi call" do
98
+ before do
99
+ @state = 0
100
+ @dummy = Dummy.new
101
+ @dummy.add_event_listener(:multi) do
102
+ @state += 1
103
+ end
104
+ end
105
+
106
+ it do
107
+ @dummy.trigger_event(:multi)
108
+ expect(@state).to eq 1
109
+ @dummy.trigger_event(:multi)
110
+ expect(@state).to eq 2
111
+ @dummy.trigger_event(:multi)
112
+ expect(@state).to eq 3
113
+ end
114
+ end
115
+
116
+ context "#remove_event_listener" do
117
+ before do
118
+ @state = 100
119
+ @dummy = Dummy.new
120
+ end
121
+
122
+ context "remove all events" do
123
+ before do
124
+ @dummy.add_event_listener(:inc_state) do
125
+ @state += 200
126
+ end
127
+ @dummy.add_event_listener(:inc_state) do
128
+ @state += 200
129
+ end
130
+ end
131
+
132
+ it "@state should be 100" do
133
+ @dummy.remove_event_listener(:inc_state)
134
+ @dummy.trigger_event(:inc_state)
135
+ expect(@state).to eq 100
136
+ end
137
+ end
138
+
139
+ context "remove specify event" do
140
+ before do
141
+ @inc_100 = -> { @state += 100 }
142
+ @inc_200 = -> { @state += 200 }
143
+ @dummy.add_event_listener(:inc_state2, &@inc_100)
144
+ @dummy.add_event_listener(:inc_state2, &@inc_200)
145
+ end
146
+
147
+ it "@state should be 300" do
148
+ @dummy.remove_event_listener(:inc_state2, &@inc_100)
149
+ @dummy.trigger_event(:inc_state2)
150
+ expect(@state).to eq 300
151
+ end
152
+ end
153
+ end
154
+
155
+ context "#one" do
156
+ before do
157
+ @state = 0
158
+ @dummy = Dummy.new
159
+ @dummy.one(:one_event) do
160
+ @state += 1
161
+ end
162
+ end
163
+
164
+ it "@state should be 1" do
165
+ @dummy.trigger(:one_event)
166
+ expect(@state).to eq 1
167
+ @dummy.trigger(:one_event)
168
+ expect(@state).to eq 1
169
+ end
170
+ end
171
+ end
172
+
@@ -0,0 +1,67 @@
1
+ # -*- Encoding: utf-8 -*-
2
+ #
3
+ # Copyright 2013 whiteleaf. All rights reserved.
4
+ #
5
+
6
+ require_relative "../lib/commandline"
7
+ require_relative "../lib/logger"
8
+
9
+ describe "exit code" do
10
+ before do
11
+ $stdout.silent = true
12
+ $stderr.silent = true
13
+ end
14
+
15
+ describe "download command" do
16
+ describe "return mistook count" do
17
+ context "when novel is nothing" do
18
+ it { expect(CommandLine.run!(%w(download foo))).to eq 1 }
19
+ it { expect(CommandLine.run!(%w(download foo bar))).to eq 2 }
20
+ it { expect(CommandLine.run!(%w(download foo bar baz))).to eq 3 }
21
+ end
22
+
23
+ context "when novel is alrady existed" do
24
+ before do
25
+ # 事前に最低3つは凍結している小説を用意しておく
26
+ @ids = `narou l -f nonfrozen`.split
27
+ end
28
+
29
+ it "got 3" do
30
+ expect(CommandLine.run!(["download"] + @ids[0,3])).to eq 3
31
+ end
32
+ end
33
+
34
+ context "when novel is alrady frozen" do
35
+ before do
36
+ # 事前に最低2つは凍結している小説を用意しておく
37
+ @ids = `narou l -f frozen`.split
38
+ end
39
+
40
+ it "got 2" do
41
+ expect(CommandLine.run!(["download"] + @ids[0,2])).to eq 2
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "update command" do
48
+ describe "return mistook count" do
49
+ context "when novel is nothing" do
50
+ it { expect(CommandLine.run!(%w(update foo))).to eq 1 }
51
+ it { expect(CommandLine.run!(%w(update foo bar))).to eq 2 }
52
+ it { expect(CommandLine.run!(%w(update foo bar baz))).to eq 3 }
53
+ end
54
+
55
+ context "when novel is alrady frozen" do
56
+ before do
57
+ @ids = `narou l -f frozen`.split
58
+ end
59
+
60
+ it "got 2" do
61
+ expect(CommandLine.run!(["update"] + @ids[0,2])).to eq 2
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+
@@ -0,0 +1,72 @@
1
+ # -*- Encoding: utf-8 -*-
2
+ #
3
+ # Copyright 2013 whiteleaf. All rights reserved.
4
+ #
5
+
6
+ require "tmpdir"
7
+ require "tempfile"
8
+ require_relative "../lib/helper"
9
+
10
+ describe Helper do
11
+ describe ".string_cast_to_type" do
12
+ context "boolean" do
13
+ it { expect(Helper.string_cast_to_type("true", :boolean)).to eq true }
14
+ it { expect(Helper.string_cast_to_type("TRUE", :boolean)).to eq true }
15
+ it { expect(Helper.string_cast_to_type("false", :boolean)).to eq false }
16
+ it { expect(Helper.string_cast_to_type("FALSE", :boolean)).to eq false }
17
+ it "should be error" do
18
+ expect { Helper.string_cast_to_type("1", :boolean) }.to raise_error
19
+ expect { Helper.string_cast_to_type("abc", :boolean) }.to raise_error
20
+ expect { Helper.string_cast_to_type("TrueClass", :boolean) }.to raise_error
21
+ end
22
+ end
23
+
24
+ context "integer" do
25
+ it { expect(Helper.string_cast_to_type("100", :integer)).to eq 100 }
26
+ it { expect(Helper.string_cast_to_type("+100", :integer)).to eq 100 }
27
+ it { expect(Helper.string_cast_to_type("-100", :integer)).to eq -100 }
28
+ it { expect(Helper.string_cast_to_type("+10_00", :integer)).to eq +1000 }
29
+ it "should be error" do
30
+ expect { Helper.string_cast_to_type("10.0", :integer) }.to raise_error
31
+ expect { Helper.string_cast_to_type("abc", :integer) }.to raise_error
32
+ end
33
+ end
34
+
35
+ context "float" do
36
+ it { expect(Helper.string_cast_to_type("100", :float)).to eq 100.0 }
37
+ it { expect(Helper.string_cast_to_type("100.1", :float)).to eq 100.1 }
38
+ it { expect(Helper.string_cast_to_type("-100.1", :float)).to eq -100.1 }
39
+ it { expect(Helper.string_cast_to_type("-10.2e3", :float)).to eq -10200.0 }
40
+ it "should be error" do
41
+ expect { Helper.string_cast_to_type("abc", :float) }.to raise_error
42
+ end
43
+ end
44
+
45
+ context "directory" do
46
+ it do
47
+ Dir.mktmpdir do |tmpdir|
48
+ expect(Helper.string_cast_to_type(tmpdir, :directory)).to eq File.expand_path(tmpdir)
49
+ end
50
+ end
51
+ it "should be error" do
52
+ expect { Helper.string_cast_to_type("/foobarbazz", :directory) }.to raise_error
53
+ end
54
+ end
55
+
56
+ context "file" do
57
+ it do
58
+ Tempfile.open("temp") do |fp|
59
+ fp.puts "test"
60
+ expect(Helper.string_cast_to_type(fp.path, :file)).to eq File.expand_path(fp.path)
61
+ end
62
+ end
63
+ it "should be error" do
64
+ expect { Helper.string_cast_to_type("/foobarbazz.txt", :file) }.to raise_error
65
+ end
66
+ end
67
+
68
+ context "string" do
69
+ it { expect(Helper.string_cast_to_type("string", :string)).to eq "string" }
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,76 @@
1
+ # -*- Encoding: utf-8 -*-
2
+ #
3
+ # Copyright 2013 whiteleaf. All rights reserved.
4
+ #
5
+
6
+ require "stringio"
7
+ require_relative "../lib/input"
8
+
9
+ describe Narou::Input do
10
+ before :all do
11
+ $stdout = StringIO.new
12
+ end
13
+
14
+ after :all do
15
+ $stdout = STDOUT
16
+ end
17
+
18
+ describe ".confirm" do
19
+ it "y の時 true を返すべき" do
20
+ $stdin = double("$stdin yes", getch: "y", tty?: true)
21
+ expect(Narou::Input.confirm("")).to eq true
22
+ end
23
+
24
+ it "Y の時 true を返すべき" do
25
+ $stdin = double("$stdin yes", getch: "Y", tty?: true)
26
+ expect(Narou::Input.confirm("")).to eq true
27
+ end
28
+
29
+ it "n の時 false を返すべき" do
30
+ $stdin = double("$stdin no", getch: "n", tty?: true)
31
+ expect(Narou::Input.confirm("")).to eq false
32
+ end
33
+
34
+ it "N の時 fale を返すべき" do
35
+ $stdin = double("$stdin no", getch: "N", tty?: true)
36
+ expect(Narou::Input.confirm("")).to eq false
37
+ end
38
+
39
+ it "enter をおした時 false を返すべき" do
40
+ $stdin = double("$stdin enter", getch: "\n", tty?: true)
41
+ expect(Narou::Input.confirm("")).to eq false
42
+ end
43
+
44
+ it "pipe で接続された時 true を返すべき" do
45
+ $stdin = double("$stdin nontty", tty?: false)
46
+ expect(Narou::Input.confirm("")).to eq true
47
+ end
48
+ end
49
+
50
+ describe ".choose" do
51
+ before do
52
+ @choices = { "japanese" => "日本語", "english" => "English", default: "japanese" }
53
+ end
54
+
55
+ it "japanese を入力された時 japanese を返すべき" do
56
+ $stdin = double("$stdin japanese", gets: "japanese\n", tty?: true)
57
+ expect(Narou::Input.choose("", @choices)).to eq "japanese"
58
+ end
59
+
60
+ it "JAPANESE を入力された時 japanese を返すべき" do
61
+ $stdin = double("$stdin JAPANESE", gets: "JAPANESE\n", tty?: true)
62
+ expect(Narou::Input.choose("", @choices)).to eq "japanese"
63
+ end
64
+
65
+ it "English を入力された時 english を返すべき" do
66
+ $stdin = double("$stdin English", gets: "English\n", tty?: true)
67
+ expect(Narou::Input.choose("", @choices)).to eq "english"
68
+ end
69
+
70
+ it "pipe で接続された時 japanese を返すべき" do
71
+ $stdin = double("$stdin nontty", tty?: false)
72
+ expect(Narou::Input.choose("", @choices)).to eq "japanese"
73
+ end
74
+ end
75
+ end
76
+
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright 2013 whiteleaf. All rights reserved.
4
+ #
5
+
6
+ require_relative "../lib/logger"
7
+
8
+ describe Narou::Logger do
9
+ after :all do
10
+ $stdout = STDOUT
11
+ $stderr = STDERR
12
+ end
13
+
14
+ describe "#capture" do
15
+ context "when non block" do
16
+ it "raise error" do
17
+ expect {
18
+ $stdout.capture
19
+ }.to raise_error(StandardError, "#capture block given")
20
+ end
21
+ end
22
+
23
+ context "when empty" do
24
+ it do
25
+ expect($stdout.capture {}).to eq ""
26
+ end
27
+ end
28
+
29
+ context "when puts one line" do
30
+ it do
31
+ expect($stdout.capture { puts "hello" }).to eq "hello\n"
32
+ end
33
+ end
34
+
35
+ context "when puts multi line" do
36
+ it do
37
+ expect($stdout.capture { puts "hello"; puts "world" }).to eq "hello\nworld\n"
38
+ end
39
+ end
40
+
41
+ context "when puts binary strings" do
42
+ it do
43
+ expect($stdout.capture { puts "\e[31mhello\e[0m" }).to eq "hello\n"
44
+ end
45
+ end
46
+
47
+ context "with ansicolor NON strip option" do
48
+ it do
49
+ expect($stdout.capture(false) { puts "\e[31mhello\e[0m" }).to eq "\e[31mhello\e[0m\n"
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,35 @@
1
+ # -*- Encoding: utf-8 -*-
2
+ #
3
+ # Copyright 2013 whiteleaf. All rights reserved.
4
+ #
5
+
6
+ require "tmpdir"
7
+ require_relative "../lib/inventory"
8
+ require_relative "../lib/novelsetting"
9
+
10
+ describe NovelSetting do
11
+ context "setting.ini 書き出し関係" do
12
+ before do
13
+ @tmpdir = Dir.mktmpdir
14
+ @novel_setting = NovelSetting.new(@tmpdir, true)
15
+ @inipath = File.join(@tmpdir, NovelSetting::INI_NAME)
16
+ end
17
+
18
+ after do
19
+ FileUtils.remove_entry_secure @tmpdir
20
+ end
21
+
22
+ it "読み込んだ設定を setting.ini に書き出せるか" do
23
+ @novel_setting.save_settings
24
+ expect(File.exist?(@inipath)).to be_truthy
25
+ end
26
+
27
+ it "オリジナル設定も setting.ini に書きだされるか" do
28
+ @novel_setting["original"] = "hoge"
29
+ @novel_setting.save_settings
30
+ lines = File.read(@inipath).split("\n")
31
+ expect(lines.last).to eq "original = hoge"
32
+ end
33
+ end
34
+ end
35
+