kitabu 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +14 -11
- data/kitabu.gemspec +2 -0
- data/lib/kitabu.rb +1 -0
- data/lib/kitabu/cli.rb +15 -0
- data/lib/kitabu/stats.rb +45 -0
- data/lib/kitabu/version.rb +1 -1
- data/spec/kitabu/cli/stats_spec.rb +44 -0
- data/spec/kitabu/stats_spec.rb +64 -0
- metadata +37 -2
data/Gemfile.lock
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kitabu (1.0.
|
4
|
+
kitabu (1.0.1)
|
5
5
|
RedCloth
|
6
6
|
activesupport
|
7
7
|
coderay
|
8
8
|
eeepub-with-cover-support
|
9
9
|
i18n
|
10
|
+
listen
|
10
11
|
nokogiri
|
12
|
+
notifier
|
11
13
|
rdiscount
|
12
14
|
thor
|
13
15
|
|
@@ -18,18 +20,19 @@ GEM
|
|
18
20
|
activesupport (3.2.8)
|
19
21
|
i18n (~> 0.6)
|
20
22
|
multi_json (~> 1.0)
|
21
|
-
awesome_print (1.0
|
22
|
-
builder (3.1.
|
23
|
-
coderay (1.0.
|
23
|
+
awesome_print (1.1.0)
|
24
|
+
builder (3.1.4)
|
25
|
+
coderay (1.0.8)
|
24
26
|
diff-lcs (1.1.3)
|
25
27
|
eeepub-with-cover-support (0.8.7)
|
26
28
|
builder
|
27
29
|
rubyzip
|
28
30
|
i18n (0.6.1)
|
29
|
-
|
30
|
-
|
31
|
+
listen (0.5.3)
|
32
|
+
method_source (0.8.1)
|
33
|
+
multi_json (1.3.7)
|
31
34
|
nokogiri (1.5.5)
|
32
|
-
notifier (0.
|
35
|
+
notifier (0.4.1)
|
33
36
|
pry (0.9.10)
|
34
37
|
coderay (~> 1.0.5)
|
35
38
|
method_source (~> 0.8)
|
@@ -43,12 +46,12 @@ GEM
|
|
43
46
|
rspec-expectations (~> 2.11.0)
|
44
47
|
rspec-mocks (~> 2.11.0)
|
45
48
|
rspec-core (2.11.1)
|
46
|
-
rspec-expectations (2.11.
|
49
|
+
rspec-expectations (2.11.3)
|
47
50
|
diff-lcs (~> 1.1.3)
|
48
|
-
rspec-mocks (2.11.
|
51
|
+
rspec-mocks (2.11.3)
|
49
52
|
rubyzip (0.9.9)
|
50
|
-
slop (3.3.
|
51
|
-
test_notifier (1.0.
|
53
|
+
slop (3.3.3)
|
54
|
+
test_notifier (1.0.1)
|
52
55
|
notifier
|
53
56
|
thor (0.16.0)
|
54
57
|
|
data/kitabu.gemspec
CHANGED
@@ -27,6 +27,8 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.add_dependency "thor"
|
28
28
|
s.add_dependency "eeepub-with-cover-support"
|
29
29
|
s.add_dependency "coderay"
|
30
|
+
s.add_dependency "notifier"
|
31
|
+
s.add_dependency "listen"
|
30
32
|
|
31
33
|
s.add_development_dependency "rspec"
|
32
34
|
s.add_development_dependency "test_notifier"
|
data/lib/kitabu.rb
CHANGED
data/lib/kitabu/cli.rb
CHANGED
@@ -100,6 +100,21 @@ module Kitabu
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
+
desc "stats", "Display some stats about your e-book"
|
104
|
+
def stats
|
105
|
+
inside_ebook!
|
106
|
+
stats = Kitabu::Stats.new(root_dir)
|
107
|
+
|
108
|
+
say [
|
109
|
+
"Chapters: #{stats.chapters}",
|
110
|
+
"Words: #{stats.words}",
|
111
|
+
"Images: #{stats.images}",
|
112
|
+
"Links: #{stats.links}",
|
113
|
+
"Footnotes: #{stats.footnotes}",
|
114
|
+
"Code blocks: #{stats.code_blocks}"
|
115
|
+
].join("\n")
|
116
|
+
end
|
117
|
+
|
103
118
|
private
|
104
119
|
def inside_ebook!
|
105
120
|
unless File.exist?(config_path)
|
data/lib/kitabu/stats.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Kitabu
|
2
|
+
class Stats
|
3
|
+
attr_reader :root_dir
|
4
|
+
|
5
|
+
def initialize(root_dir)
|
6
|
+
@root_dir = root_dir
|
7
|
+
end
|
8
|
+
|
9
|
+
def text
|
10
|
+
@text ||= html.text
|
11
|
+
end
|
12
|
+
|
13
|
+
def html
|
14
|
+
@html ||= Nokogiri::HTML(content)
|
15
|
+
end
|
16
|
+
|
17
|
+
def words
|
18
|
+
@words ||= text.split(" ").size
|
19
|
+
end
|
20
|
+
|
21
|
+
def chapters
|
22
|
+
@chapters ||= html.css(".chapter").size
|
23
|
+
end
|
24
|
+
|
25
|
+
def images
|
26
|
+
@images ||= html.css("img").size
|
27
|
+
end
|
28
|
+
|
29
|
+
def footnotes
|
30
|
+
@footnotes ||= html.css("p.footnote").size
|
31
|
+
end
|
32
|
+
|
33
|
+
def links
|
34
|
+
@links ||= html.css("[href^='http']").size
|
35
|
+
end
|
36
|
+
|
37
|
+
def code_blocks
|
38
|
+
@code_blocks ||= html.css("pre").size
|
39
|
+
end
|
40
|
+
|
41
|
+
def content
|
42
|
+
@content ||= Parser::HTML.new(root_dir).content
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/kitabu/version.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Kitabu::Cli, "while running stats" do
|
4
|
+
let(:root_dir) { SPECDIR.join("support/mybook") }
|
5
|
+
before { Dir.chdir(root_dir) }
|
6
|
+
|
7
|
+
it "recognizes command" do
|
8
|
+
expect {
|
9
|
+
capture(:stdout) { Kitabu::Cli.start(["stats"]) }
|
10
|
+
}.to_not raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it "initializes stats with root dir" do
|
14
|
+
Kitabu::Stats
|
15
|
+
.should_receive(:new)
|
16
|
+
.with(root_dir)
|
17
|
+
.and_return(mock.as_null_object)
|
18
|
+
|
19
|
+
capture(:stdout) { Kitabu::Cli.start(["stats"]) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "outputting stats" do
|
23
|
+
let(:stats) { mock("stats", {
|
24
|
+
:chapters => 4,
|
25
|
+
:words => 50,
|
26
|
+
:images => 10,
|
27
|
+
:footnotes => 15,
|
28
|
+
:links => 20,
|
29
|
+
:code_blocks => 25
|
30
|
+
})}
|
31
|
+
|
32
|
+
before { Kitabu::Stats.stub :new => stats }
|
33
|
+
subject(:output) {
|
34
|
+
capture(:stdout) { Kitabu::Cli.start(["stats"]) }
|
35
|
+
}
|
36
|
+
|
37
|
+
it { expect(output).to include("Chapters: 4") }
|
38
|
+
it { expect(output).to include("Words: 50") }
|
39
|
+
it { expect(output).to include("Images: 10") }
|
40
|
+
it { expect(output).to include("Footnotes: 15") }
|
41
|
+
it { expect(output).to include("Links: 20") }
|
42
|
+
it { expect(output).to include("Code blocks: 25") }
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Kitabu::Stats do
|
4
|
+
let(:root_dir) { mock("root dir").as_null_object }
|
5
|
+
let(:parser) { mock("parser").as_null_object }
|
6
|
+
let(:content) { "" }
|
7
|
+
subject(:stats) { Kitabu::Stats.new(root_dir) }
|
8
|
+
before { stats.stub :content => content }
|
9
|
+
|
10
|
+
context "getting content" do
|
11
|
+
it "parses content" do
|
12
|
+
Kitabu::Parser::HTML
|
13
|
+
.should_receive(:new)
|
14
|
+
.with(root_dir)
|
15
|
+
.and_return(parser)
|
16
|
+
|
17
|
+
Kitabu::Stats.new(root_dir).content
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns parser content" do
|
21
|
+
Kitabu::Parser::HTML.stub :new => parser
|
22
|
+
parser.stub :content => "some content"
|
23
|
+
|
24
|
+
expect(Kitabu::Stats.new(root_dir).content).to eql("some content")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "words counting" do
|
29
|
+
let(:content) { "a b c" }
|
30
|
+
it { expect(stats.words).to eql(3) }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "chapters counting" do
|
34
|
+
let(:content) { "<div class='chapter'/>" * 5 }
|
35
|
+
it { expect(stats.chapters).to eql(5) }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "images counting" do
|
39
|
+
let(:content) { "<img/>" * 2 }
|
40
|
+
it { expect(stats.images).to eql(2) }
|
41
|
+
end
|
42
|
+
|
43
|
+
context "footnotes counting" do
|
44
|
+
let(:content) { "<p class='footnote'/>" * 10 }
|
45
|
+
it { expect(stats.footnotes).to eql(10) }
|
46
|
+
end
|
47
|
+
|
48
|
+
context "external links counting" do
|
49
|
+
let(:content) {
|
50
|
+
<<-HTML
|
51
|
+
<a href="http://example.org">example.org</a>
|
52
|
+
<a href="http://subdomain.example.org">subdomain.example.org</a>
|
53
|
+
<a href="#some-anchor">anchor</a>
|
54
|
+
HTML
|
55
|
+
}
|
56
|
+
|
57
|
+
it { expect(stats.links).to eql(2) }
|
58
|
+
end
|
59
|
+
|
60
|
+
context "code blocks" do
|
61
|
+
let(:content) { "<pre/>" * 3 }
|
62
|
+
it { expect(stats.code_blocks).to eql(3) }
|
63
|
+
end
|
64
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitabu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -139,6 +139,38 @@ dependencies:
|
|
139
139
|
- - ! '>='
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: notifier
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :runtime
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: listen
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :runtime
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
142
174
|
- !ruby/object:Gem::Dependency
|
143
175
|
name: rspec
|
144
176
|
requirement: !ruby/object:Gem::Requirement
|
@@ -295,6 +327,7 @@ files:
|
|
295
327
|
- lib/kitabu/parser/mobi.rb
|
296
328
|
- lib/kitabu/parser/pdf.rb
|
297
329
|
- lib/kitabu/parser/txt.rb
|
330
|
+
- lib/kitabu/stats.rb
|
298
331
|
- lib/kitabu/stream.rb
|
299
332
|
- lib/kitabu/syntax.rb
|
300
333
|
- lib/kitabu/syntax/highlight.rb
|
@@ -305,6 +338,7 @@ files:
|
|
305
338
|
- spec/kitabu/cli/export_spec.rb
|
306
339
|
- spec/kitabu/cli/new_spec.rb
|
307
340
|
- spec/kitabu/cli/permalinks_spec.rb
|
341
|
+
- spec/kitabu/cli/stats_spec.rb
|
308
342
|
- spec/kitabu/cli/version_spec.rb
|
309
343
|
- spec/kitabu/extensions/redcloth_spec.rb
|
310
344
|
- spec/kitabu/extensions/string_spec.rb
|
@@ -312,6 +346,7 @@ files:
|
|
312
346
|
- spec/kitabu/parser/epub_spec.rb
|
313
347
|
- spec/kitabu/parser/html_spec.rb
|
314
348
|
- spec/kitabu/parser/pdf_spec.rb
|
349
|
+
- spec/kitabu/stats_spec.rb
|
315
350
|
- spec/kitabu/syntax_spec.rb
|
316
351
|
- spec/kitabu/toc/html_spec.rb
|
317
352
|
- spec/kitabu_spec.rb
|