rpub 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -1
- data/.rspec +0 -1
- data/.travis.yml +3 -4
- data/.yardopts +1 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +70 -46
- data/Guardfile +6 -0
- data/HISTORY.md +10 -0
- data/README.md +1 -1
- data/Rakefile +7 -2
- data/bin/rpub +64 -1
- data/doc/.gitignore +8 -0
- data/doc/api/Rpub.html +339 -0
- data/doc/api/Rpub/Book.html +983 -0
- data/doc/api/Rpub/Chapter.html +737 -0
- data/doc/api/Rpub/Command.html +356 -0
- data/doc/api/Rpub/Commands.html +117 -0
- data/doc/api/Rpub/Commands/Clean.html +216 -0
- data/doc/api/Rpub/Commands/Compile.html +218 -0
- data/doc/api/Rpub/Commands/Generate.html +242 -0
- data/doc/api/Rpub/Commands/Package.html +230 -0
- data/doc/api/Rpub/Commands/Preview.html +216 -0
- data/doc/api/Rpub/Commands/Stats.html +226 -0
- data/doc/api/Rpub/Compressor.html +687 -0
- data/doc/api/Rpub/Context.html +553 -0
- data/doc/api/Rpub/Document.html +647 -0
- data/doc/api/Rpub/Document/OutlineElement.html +388 -0
- data/doc/api/Rpub/Epub.html +465 -0
- data/doc/api/Rpub/Epub/Container.html +224 -0
- data/doc/api/Rpub/Epub/Content.html +344 -0
- data/doc/api/Rpub/Epub/Cover.html +236 -0
- data/doc/api/Rpub/Epub/HtmlToc.html +240 -0
- data/doc/api/Rpub/Epub/Toc.html +244 -0
- data/doc/api/Rpub/FilesystemSource.html +544 -0
- data/doc/api/Rpub/HashDelegation.html +281 -0
- data/doc/api/Rpub/HashDelegation/ClassMethods.html +175 -0
- data/doc/api/Rpub/MediaType.html +192 -0
- data/doc/api/Rpub/Preview.html +464 -0
- data/doc/api/Rpub/XmlFile.html +457 -0
- data/doc/api/_index.html +405 -0
- data/doc/api/class_list.html +54 -0
- data/doc/api/css/common.css +1 -0
- data/doc/api/css/full_list.css +57 -0
- data/doc/api/css/style.css +339 -0
- data/doc/api/file.HISTORY.html +131 -0
- data/doc/api/file.LICENSE.html +92 -0
- data/doc/api/file.README.html +337 -0
- data/doc/api/file_list.html +62 -0
- data/doc/api/frames.html +26 -0
- data/doc/api/index.html +337 -0
- data/doc/api/js/app.js +219 -0
- data/doc/api/js/full_list.js +178 -0
- data/doc/api/js/jquery.js +4 -0
- data/doc/api/method_list.html +533 -0
- data/doc/api/top-level-namespace.html +112 -0
- data/doc/index.html +312 -0
- data/doc/javascripts/scale.fix.js +17 -0
- data/doc/params.json +1 -0
- data/doc/stylesheets/pygment_trac.css +69 -0
- data/doc/stylesheets/styles.css +255 -0
- data/features/clean.feature +31 -0
- data/features/compile.feature +49 -0
- data/features/embedded_assets.feature +51 -0
- data/features/generate.feature +63 -0
- data/features/layout.feature +41 -0
- data/features/package.feature +30 -0
- data/features/previews.feature +66 -0
- data/features/stats.feature +18 -0
- data/features/step_definitions/general_steps.rb +60 -0
- data/features/styles.feature +33 -0
- data/features/support/env.rb +7 -0
- data/features/table_of_contents.feature +35 -0
- data/lib/rpub.rb +28 -31
- data/lib/rpub/book.rb +9 -16
- data/lib/rpub/chapter.rb +4 -54
- data/lib/rpub/command.rb +32 -0
- data/lib/rpub/commands/clean.rb +4 -49
- data/lib/rpub/commands/compile.rb +4 -49
- data/lib/rpub/commands/generate.rb +10 -67
- data/lib/rpub/commands/package.rb +9 -37
- data/lib/rpub/commands/preview.rb +4 -54
- data/lib/rpub/commands/stats.rb +6 -10
- data/lib/rpub/compressor.rb +3 -3
- data/lib/rpub/context.rb +48 -0
- data/lib/rpub/document.rb +68 -0
- data/lib/rpub/epub.rb +8 -7
- data/lib/rpub/epub/content.rb +9 -30
- data/lib/rpub/epub/cover.rb +1 -8
- data/lib/rpub/epub/html_toc.rb +4 -9
- data/lib/rpub/epub/toc.rb +16 -13
- data/lib/rpub/filesystem_source.rb +47 -0
- data/lib/rpub/media_type.rb +16 -0
- data/lib/rpub/preview.rb +29 -0
- data/lib/rpub/version.rb +1 -1
- data/lib/rpub/xml_file.rb +4 -1
- data/rpub.gemspec +6 -7
- data/spec/rpub/book_spec.rb +45 -45
- data/spec/rpub/chapter_spec.rb +87 -22
- data/spec/rpub/epub/container_spec.rb +3 -5
- data/spec/rpub/epub/content_spec.rb +62 -41
- data/spec/rpub/epub/cover_spec.rb +3 -5
- data/spec/rpub/epub/html_toc_spec.rb +8 -8
- data/spec/rpub/epub/toc_spec.rb +20 -22
- data/spec/rpub_spec.rb +1 -3
- data/spec/spec_helper.rb +28 -0
- data/support/config.yml +1 -0
- data/support/styles.css +3 -3
- metadata +131 -120
- data/lib/rpub/commander.rb +0 -23
- data/lib/rpub/commands/base.rb +0 -33
- data/lib/rpub/commands/help.rb +0 -37
- data/lib/rpub/commands/main.rb +0 -45
- data/lib/rpub/compilation_helpers.rb +0 -73
- data/lib/rpub/subclass_tracker.rb +0 -53
- data/spec/rpub/commands/clean_spec.rb +0 -46
- data/spec/rpub/commands/generate_spec.rb +0 -52
- data/spec/rpub/commands/main_spec.rb +0 -26
- data/spec/rpub/commands/package_spec.rb +0 -33
- data/spec/rpub/commands/preview_spec.rb +0 -43
data/spec/rpub/chapter_spec.rb
CHANGED
@@ -1,81 +1,146 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Rpub::Chapter do
|
4
2
|
let(:subject) { described_class.new('foo', 1, 'document') }
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
describe '#content' do
|
5
|
+
subject { super().content }
|
6
|
+
it { is_expected.to eq('foo') }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#number' do
|
10
|
+
subject { super().number }
|
11
|
+
it { is_expected.to eq(1) }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#layout' do
|
15
|
+
subject { super().layout }
|
16
|
+
it { is_expected.to eq('document') }
|
17
|
+
end
|
9
18
|
|
10
19
|
describe '#uid' do
|
11
20
|
it 'should change when content changes' do
|
12
|
-
subject.uid.
|
21
|
+
expect(subject.uid).to_not eql(described_class.new('bar', 1, 'bar').uid)
|
13
22
|
end
|
14
23
|
|
15
24
|
it 'should change when layout changes' do
|
16
|
-
subject.uid.
|
25
|
+
expect(subject.uid).to_not eql(described_class.new('foo', 1, 'qux').uid)
|
17
26
|
end
|
18
27
|
|
19
28
|
it 'should change when content changes' do
|
20
|
-
subject.uid.
|
29
|
+
expect(subject.uid).to_not eql(described_class.new('foo', 2, 'bar').uid)
|
21
30
|
end
|
22
31
|
end
|
23
32
|
|
24
33
|
describe '#xml_id' do
|
25
|
-
|
34
|
+
describe '#xml_id' do
|
35
|
+
subject { super().xml_id }
|
36
|
+
it { is_expected.to eq('chapter-1') }
|
37
|
+
end
|
26
38
|
end
|
27
39
|
|
28
40
|
describe '#filename' do
|
29
|
-
|
41
|
+
describe '#filename' do
|
42
|
+
subject { super().filename }
|
43
|
+
it { is_expected.to eq('chapter-1-untitled.html') }
|
44
|
+
end
|
30
45
|
end
|
31
46
|
|
32
47
|
describe '#outline' do
|
33
48
|
context 'when there are no headings' do
|
34
49
|
let(:subject) { described_class.new('foo', 1, 'document') }
|
35
|
-
|
36
|
-
|
50
|
+
|
51
|
+
describe '#outline' do
|
52
|
+
subject { super().outline }
|
53
|
+
|
54
|
+
it 'has no elements' do
|
55
|
+
expect(subject.size).to eq(0)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#outline' do
|
60
|
+
subject { super().outline }
|
61
|
+
it { is_expected.to be_empty }
|
62
|
+
end
|
37
63
|
end
|
38
64
|
|
39
65
|
context 'when there are headings' do
|
40
66
|
let(:subject) { described_class.new('# foo', 1, 'document') }
|
41
|
-
|
67
|
+
|
68
|
+
describe '#outline' do
|
69
|
+
subject { super().outline }
|
70
|
+
|
71
|
+
it 'has 1 element' do
|
72
|
+
expect(subject.size).to eq(1)
|
73
|
+
end
|
74
|
+
end
|
42
75
|
|
43
76
|
context 'a single heading entry' do
|
44
77
|
let(:subject) { described_class.new('# foo', 1, 'document').outline.first }
|
45
|
-
|
46
|
-
|
47
|
-
|
78
|
+
|
79
|
+
describe '#level' do
|
80
|
+
subject { super().level }
|
81
|
+
it { is_expected.to eq(1) }
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#text' do
|
85
|
+
subject { super().text }
|
86
|
+
it { is_expected.to eq('foo') }
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#html_id' do
|
90
|
+
subject { super().html_id }
|
91
|
+
it { is_expected.to eq('foo') }
|
92
|
+
end
|
48
93
|
end
|
49
94
|
end
|
50
95
|
end
|
51
96
|
|
52
97
|
describe '#title' do
|
53
98
|
context 'without a suitable markdown title' do
|
54
|
-
|
99
|
+
describe '#title' do
|
100
|
+
subject { super().title }
|
101
|
+
it { is_expected.to eq('untitled') }
|
102
|
+
end
|
55
103
|
end
|
56
104
|
|
57
105
|
context 'with a markdown heading' do
|
58
106
|
let(:subject) { described_class.new('# My Title', 1, 'bar') }
|
59
|
-
|
107
|
+
|
108
|
+
describe '#title' do
|
109
|
+
subject { super().title }
|
110
|
+
it { is_expected.to eq('My Title') }
|
111
|
+
end
|
60
112
|
end
|
61
113
|
end
|
62
114
|
|
63
115
|
describe 'markdown parsing' do
|
64
116
|
let(:subject) { described_class.new('foo', 1, nil) }
|
65
|
-
|
117
|
+
|
118
|
+
describe '#to_html' do
|
119
|
+
subject { super().to_html }
|
120
|
+
it { is_expected.to eq("<p>foo</p>\n") }
|
121
|
+
end
|
66
122
|
end
|
67
123
|
|
68
124
|
describe '#images' do
|
69
125
|
let(:subject) { described_class.new('![alt](foo.png)', 1, 'document') }
|
70
126
|
|
71
|
-
it
|
72
|
-
|
127
|
+
it 'has 1 image' do
|
128
|
+
expect(subject.images.size).to eq(1)
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '#images' do
|
132
|
+
subject { super().images }
|
133
|
+
describe '#first' do
|
134
|
+
subject { super().first }
|
135
|
+
it { is_expected.to eq('foo.png') }
|
136
|
+
end
|
137
|
+
end
|
73
138
|
end
|
74
139
|
|
75
140
|
describe '#outline' do
|
76
141
|
let(:subject) { described_class.new("# foo\n\nbla bla bla \n\n## bar\n\n# baz", 1, nil) }
|
77
142
|
it 'should list headings in order' do
|
78
|
-
subject.outline.map(&:text).
|
143
|
+
expect(subject.outline.map(&:text)).to eql(%w[foo bar baz])
|
79
144
|
end
|
80
145
|
end
|
81
146
|
end
|
@@ -1,8 +1,6 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Rpub::Epub::Container do
|
4
2
|
let(:subject) { described_class.new.render }
|
5
|
-
it {
|
6
|
-
it {
|
7
|
-
it {
|
3
|
+
it { is_expected.to have_xpath('/xmlns:container') }
|
4
|
+
it { is_expected.to have_xpath('/xmlns:container[@version="1.0"]') }
|
5
|
+
it { is_expected.to have_xpath('/xmlns:container/xmlns:rootfiles/xmlns:rootfile[@media-type="application/oebps-package+xml"]') }
|
8
6
|
end
|
@@ -1,21 +1,25 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Rpub::Epub::Content do
|
2
|
+
let(:config) do
|
3
|
+
OpenStruct.new({
|
4
|
+
'creator' => 'anonymous',
|
5
|
+
'title' => 'title',
|
6
|
+
'language' => 'en',
|
7
|
+
'publisher' => 'none',
|
8
|
+
'description' => 'foo bar',
|
9
|
+
'subject' => 'baz qux',
|
10
|
+
'rights' => 'copyright',
|
11
|
+
'cover_image' => 'image.jpg'
|
12
|
+
})
|
13
|
+
end
|
4
14
|
let(:book) do
|
5
15
|
double('book', {
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:uid => 'abcd',
|
14
|
-
:has_cover? => false,
|
15
|
-
:has_fonts? => false,
|
16
|
-
:has_toc? => false,
|
17
|
-
:images => [],
|
18
|
-
:chapters => []
|
16
|
+
:config => config,
|
17
|
+
:uid => 'abcd',
|
18
|
+
:has_cover? => false,
|
19
|
+
:has_fonts? => false,
|
20
|
+
:has_toc? => false,
|
21
|
+
:images => [],
|
22
|
+
:chapters => []
|
19
23
|
})
|
20
24
|
end
|
21
25
|
let(:subject) { described_class.new(book).render }
|
@@ -24,53 +28,70 @@ describe Rpub::Epub::Content do
|
|
24
28
|
attr = options.inject('') do |str, (k, v)|
|
25
29
|
str << "[@#{k}=\"#{v}\"]"
|
26
30
|
end
|
27
|
-
it {
|
31
|
+
it { is_expected.to have_xpath(%Q{/xmlns:package/xmlns:metadata/dc:#{name}[text()="#{value}"]#{attr}}, 'dc' => 'http://purl.org/dc/elements/1.1/', 'xmlns' => 'http://www.idpf.org/2007/opf') }
|
28
32
|
end
|
29
33
|
|
30
34
|
context 'with an empty book' do
|
31
35
|
|
32
|
-
it {
|
33
|
-
it {
|
36
|
+
it { is_expected.to have_xpath('/xmlns:package[@unique-identifier="BookId"][@version="2.0"]') }
|
37
|
+
it { is_expected.to have_xpath('/xmlns:package[@unique-identifier="BookId"][@version="2.0"]') }
|
34
38
|
|
35
|
-
it_should_have_metadata 'title',
|
36
|
-
it_should_have_metadata 'creator',
|
37
|
-
it_should_have_metadata 'publisher',
|
38
|
-
it_should_have_metadata 'subject',
|
39
|
-
it_should_have_metadata 'identifier',
|
40
|
-
it_should_have_metadata 'rights',
|
39
|
+
it_should_have_metadata 'title', "title"
|
40
|
+
it_should_have_metadata 'creator', "anonymous", 'xmlns:role' => 'aut'
|
41
|
+
it_should_have_metadata 'publisher', "none"
|
42
|
+
it_should_have_metadata 'subject', "baz qux"
|
43
|
+
it_should_have_metadata 'identifier', "abcd", :id => 'BookId'
|
44
|
+
it_should_have_metadata 'rights', "copyright"
|
41
45
|
it_should_have_metadata 'description', "foo bar"
|
42
46
|
end
|
43
47
|
|
44
48
|
context 'when the book has a cover' do
|
45
|
-
before
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
it {
|
49
|
+
before do
|
50
|
+
allow(book).to receive(:has_cover?).and_return(true)
|
51
|
+
allow(config).to receive(:cover_image).and_return('foo.jpg')
|
52
|
+
end
|
53
|
+
|
54
|
+
it { is_expected.to have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="cover"][@href="cover.html"][@media-type="application/xhtml+xml"]') }
|
55
|
+
it { is_expected.to have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="cover-image"][@href="foo.jpg"][@media-type="image/jpeg"]') }
|
56
|
+
it { is_expected.to have_xpath('/xmlns:package/xmlns:metadata/xmlns:meta[@name="cover"][@content="cover-image"]') }
|
57
|
+
it { is_expected.to have_xpath('/xmlns:package/xmlns:guide/xmlns:reference[@type="cover"][@title="Cover"][@href="cover.html"]') }
|
58
|
+
it { is_expected.to have_xpath('/xmlns:package/xmlns:spine[@toc="ncx"]/xmlns:itemref[@idref="cover"][@linear="no"]') }
|
51
59
|
end
|
52
60
|
|
53
61
|
context 'when the book has embedded fonts' do
|
54
|
-
before
|
55
|
-
|
62
|
+
before do
|
63
|
+
allow(book).to receive(:has_fonts?).and_return(true)
|
64
|
+
allow(book).to receive(:fonts).and_return(['font.otf'])
|
65
|
+
end
|
66
|
+
|
67
|
+
it { is_expected.to have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="font.otf"][@href="font.otf"][@media-type="font/opentype"]') }
|
56
68
|
end
|
57
69
|
|
58
70
|
context 'when the book has a ToC' do
|
59
|
-
before
|
60
|
-
|
61
|
-
|
71
|
+
before do
|
72
|
+
allow(book).to receive(:has_toc?).and_return(true)
|
73
|
+
end
|
74
|
+
|
75
|
+
it { is_expected.to have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="toc"][@href="toc.html"][@media-type="application/xhtml+xml"]') }
|
76
|
+
it { is_expected.to have_xpath('/xmlns:package/xmlns:guide/xmlns:reference[@type="toc"][@title="Table of Contents"][@href="toc.html"]') }
|
62
77
|
end
|
63
78
|
|
64
79
|
context 'when the book has images' do
|
65
|
-
before
|
66
|
-
|
67
|
-
|
80
|
+
before do
|
81
|
+
allow(book).to receive(:images).and_return(['foo.png', 'bar.gif'])
|
82
|
+
end
|
83
|
+
|
84
|
+
it { is_expected.to have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="foo.png"][@href="foo.png"][@media-type="image/png"]') }
|
85
|
+
it { is_expected.to have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="bar.gif"][@href="bar.gif"][@media-type="image/gif"]') }
|
68
86
|
end
|
69
87
|
|
70
88
|
context 'when the book has chapters' do
|
71
89
|
let(:chapter) { double('chapter', :filename => 'chapter.html', :xml_id => 'chapter1') }
|
72
|
-
before
|
73
|
-
|
74
|
-
|
90
|
+
before do
|
91
|
+
allow(book).to receive(:chapters).and_return([chapter])
|
92
|
+
end
|
93
|
+
|
94
|
+
it { is_expected.to have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="chapter1"][@href="chapter.html"][@media-type="application/xhtml+xml"]') }
|
95
|
+
it { is_expected.to have_xpath('/xmlns:package/xmlns:spine[@toc="ncx"]/xmlns:itemref[@idref="chapter1"]') }
|
75
96
|
end
|
76
97
|
end
|
@@ -1,9 +1,7 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Rpub::Epub::Cover do
|
4
|
-
let(:book) { double('book', :cover_image => 'cover.jpg', :title => 'title') }
|
2
|
+
let(:book) { double('book', :config => double('config', :cover_image => 'cover.jpg', :title => 'title')) }
|
5
3
|
let(:subject) { described_class.new(book).render }
|
6
4
|
|
7
|
-
it {
|
8
|
-
it {
|
5
|
+
it { is_expected.to have_xpath('/xmlns:html/xmlns:head/xmlns:title[text()="Cover"]') }
|
6
|
+
it { is_expected.to have_xpath('/xmlns:html/xmlns:body/xmlns:div/xmlns:img[@src="cover.jpg"][@alt="title"]') }
|
9
7
|
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Rpub::Epub::HtmlToc do
|
4
2
|
let(:outline) { [] }
|
5
|
-
let(:book) { double('book', :outline => outline) }
|
3
|
+
let(:book) { double('book', :outline => outline, :config => config) }
|
4
|
+
let(:config) { OpenStruct.new({ 'max_level' => 1 }) }
|
6
5
|
let(:subject) { described_class.new(book).render }
|
7
6
|
|
8
|
-
it {
|
9
|
-
it {
|
7
|
+
it { is_expected.to have_xpath('/div/h1[text()="Table of Contents"]') }
|
8
|
+
it { is_expected.to have_xpath('/div/div[@class="toc"]') }
|
10
9
|
|
11
10
|
context 'without headings in the outline' do
|
12
|
-
it {
|
11
|
+
it { is_expected.not_to have_xpath('//a') }
|
13
12
|
end
|
14
13
|
|
15
14
|
context 'with heading in the outline' do
|
16
|
-
let(:outline) { [['foo.html', [double('heading', :text => 'link', :html_id => 'bar', :level => 1)]]] }
|
17
|
-
it {
|
15
|
+
let(:outline) { [['foo.html', [double('heading 1', :text => 'link 1', :html_id => 'bar', :level => 1), double('heading 2', :text => 'link 2', :html_id => 'bar', :level => 2)]]] }
|
16
|
+
it { is_expected.to have_xpath('/div/div/div[@class="level-1"]/a[@href="foo.html#bar"][text()="link 1"]') }
|
17
|
+
it { is_expected.not_to have_xpath('/div/div/div[@class="level-1"]/a[@href="foo.html#bar"][text()="link 2"]') }
|
18
18
|
end
|
19
19
|
end
|
data/spec/rpub/epub/toc_spec.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Rpub::Epub::Toc do
|
4
2
|
let(:chapters) { [] }
|
5
|
-
let(:config) { {} }
|
6
|
-
let(:book) { double('book', :uid => 'foo', :
|
3
|
+
let(:config) { OpenStruct.new({ 'title' => 'title' }) }
|
4
|
+
let(:book) { double('book', :uid => 'foo', :chapters => chapters, :config => config) }
|
7
5
|
let(:subject) { described_class.new(book).render }
|
8
6
|
|
9
|
-
it {
|
10
|
-
it {
|
11
|
-
it {
|
12
|
-
it {
|
13
|
-
it {
|
14
|
-
it {
|
7
|
+
it { is_expected.to have_xpath('/xmlns:ncx') }
|
8
|
+
it { is_expected.to have_xpath('/xmlns:ncx/xmlns:head/xmlns:meta[@name="dtb:uid"][@content="foo"]') }
|
9
|
+
it { is_expected.to have_xpath('/xmlns:ncx/xmlns:head/xmlns:meta[@name="dtb:depth"][@content="2"]') }
|
10
|
+
it { is_expected.to have_xpath('/xmlns:ncx/xmlns:head/xmlns:meta[@name="dtb:totalPageCount"][@content="0"]') }
|
11
|
+
it { is_expected.to have_xpath('/xmlns:ncx/xmlns:head/xmlns:meta[@name="dtb:maxPageNumber"][@content="0"]') }
|
12
|
+
it { is_expected.to have_xpath('/xmlns:ncx/xmlns:docTitle/xmlns:text[text()="title"]') }
|
15
13
|
|
16
14
|
context 'without chapters' do
|
17
|
-
it {
|
15
|
+
it { is_expected.not_to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint') }
|
18
16
|
end
|
19
17
|
|
20
18
|
context 'with chapters' do
|
@@ -22,19 +20,19 @@ describe Rpub::Epub::Toc do
|
|
22
20
|
let(:heading2) { double('heading', :children => [], :value => double('value', :options => { :level => 2, :raw_text => 'chapter title 2' }), :attr => { :id => 'bar' }) }
|
23
21
|
let(:toc) { double('toc', :children => [heading1])}
|
24
22
|
let(:chapters) { [double('chapter', :title => 'chapter title', :filename => 'filename', :xml_id => 'id', :toc => toc)] }
|
25
|
-
it {
|
26
|
-
it {
|
27
|
-
it {
|
28
|
-
it {
|
29
|
-
it {
|
30
|
-
it {
|
23
|
+
it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint[@id="foo"]') }
|
24
|
+
it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navLabel/xmlns:text[text()="chapter title"]') }
|
25
|
+
it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:content[@src="filename#foo"]') }
|
26
|
+
it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navPoint[@id="bar"]') }
|
27
|
+
it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navPoint/xmlns:navLabel/xmlns:text[text()="chapter title 2"]') }
|
28
|
+
it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navPoint/xmlns:content[@src="filename#bar"]') }
|
31
29
|
|
32
30
|
context 'with low max_level' do
|
33
|
-
let(:config) { {
|
34
|
-
it {
|
35
|
-
it {
|
36
|
-
it {
|
37
|
-
it {
|
31
|
+
let(:config) { OpenStruct.new({ 'title' => 'title', 'max_level' => 1 }) }
|
32
|
+
it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint[@id="foo"]') }
|
33
|
+
it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navLabel/xmlns:text[text()="chapter title"]') }
|
34
|
+
it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:content[@src="filename#foo"]') }
|
35
|
+
it { is_expected.not_to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navPoint') }
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
data/spec/rpub_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -3,11 +3,39 @@ if RUBY_VERSION >= '1.9' && ENV.has_key?('COVERAGE')
|
|
3
3
|
SimpleCov.start
|
4
4
|
end
|
5
5
|
|
6
|
+
if ENV.has_key?('TRAVIS')
|
7
|
+
require 'coveralls'
|
8
|
+
Coveralls.wear!
|
9
|
+
end
|
10
|
+
|
6
11
|
require 'rpub'
|
7
12
|
require 'nokogiri'
|
8
13
|
|
9
14
|
FIXTURES_DIRECTORY = File.expand_path('../fixtures', __FILE__)
|
10
15
|
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.filter_run :focus
|
18
|
+
config.run_all_when_everything_filtered = true
|
19
|
+
|
20
|
+
if config.files_to_run.one?
|
21
|
+
config.default_formatter = 'doc'
|
22
|
+
else
|
23
|
+
config.profile_examples = 10
|
24
|
+
end
|
25
|
+
|
26
|
+
config.order = :random
|
27
|
+
Kernel.srand config.seed
|
28
|
+
|
29
|
+
config.expect_with :rspec do |expectations|
|
30
|
+
expectations.syntax = :expect
|
31
|
+
end
|
32
|
+
|
33
|
+
config.mock_with :rspec do |mocks|
|
34
|
+
mocks.syntax = :expect
|
35
|
+
mocks.verify_partial_doubles = true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
11
39
|
RSpec::Matchers.define :remove_file do |filename|
|
12
40
|
match do |block|
|
13
41
|
before = File.exist?(filename)
|