epub_validator 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# epubValidator - Check your EPUB Books
|
2
2
|
|
3
|
-
This library will check that your
|
3
|
+
This library will check that your .epub files are valid IDPF EPUB v2.x documents and return a successful or error message. It can be called as a Ruby library, or invoked from the command line.
|
4
4
|
|
5
5
|
For more about the IDPF see http://idpf.org
|
6
6
|
|
@@ -21,19 +21,21 @@ Sample usage and output:
|
|
21
21
|
require 'epub_validator'
|
22
22
|
|
23
23
|
ev = EpubValidator.check('/path/to/sample.epub')
|
24
|
-
ev
|
24
|
+
puts ev[:valid]
|
25
|
+
ev[:message].each do |m|
|
25
26
|
puts m
|
26
27
|
end
|
27
|
-
=>
|
28
|
-
=>
|
28
|
+
=> 0
|
29
|
+
=> ERROR: OPS/toc.ncx(21): 'OPS/': referenced resource exists, but not declared in the OPF file
|
29
30
|
```
|
30
31
|
|
31
32
|
Now from the command line:
|
32
33
|
|
33
34
|
``` terminal
|
34
|
-
$
|
35
|
-
|
36
|
-
FAILED!
|
35
|
+
$ epub_validator /path/to/sample.epub
|
36
|
+
|
37
|
+
Checking....FAILED!
|
38
|
+
|
37
39
|
ERROR: OPS/toc.ncx(21): 'OPS/': referenced resource exists, but not declared in the OPF file
|
38
40
|
```
|
39
41
|
|
@@ -44,6 +46,6 @@ Java must be installed and set in your PATH.
|
|
44
46
|
|
45
47
|
## Future Features
|
46
48
|
|
47
|
-
*
|
48
|
-
*
|
49
|
+
* Command line: accept directory containing many .epub files for processing.
|
50
|
+
* Command line: have switch for writing results to log file
|
49
51
|
* Format "ERROR" and "WARNING" output for more intuitive instructions.
|
data/bin/epub_validator
CHANGED
@@ -6,7 +6,7 @@ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
|
6
6
|
require 'epub_validator'
|
7
7
|
#require 'epub_validator/command'
|
8
8
|
|
9
|
-
#
|
9
|
+
# From heroku!
|
10
10
|
args = ARGV.dup
|
11
11
|
ARGV.clear
|
12
12
|
command = args.shift.strip rescue 'help'
|
@@ -14,7 +14,12 @@ command = args.shift.strip rescue 'help'
|
|
14
14
|
# need to implement Command class
|
15
15
|
#EpubValidator::Command.run(command, args)
|
16
16
|
|
17
|
-
|
17
|
+
print "\nChecking...."
|
18
18
|
ev = EpubValidator.check(command)
|
19
|
-
|
19
|
+
if (ev[:valid] == 1)
|
20
|
+
print "Passed.\n"
|
21
|
+
else
|
22
|
+
print "FAILED!\n\n"
|
23
|
+
puts ev[:message]
|
24
|
+
end
|
20
25
|
|
data/epub_validator.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
23
|
s.require_paths = ["lib"]
|
24
24
|
|
25
|
-
s.add_development_dependency
|
26
|
-
s.add_development_dependency
|
27
|
-
s.add_development_dependency
|
25
|
+
s.add_development_dependency('rspec', '>= 2.8.0')
|
26
|
+
s.add_development_dependency('ZenTest', '>= 4.6.2')
|
27
|
+
s.add_development_dependency('autotest-growl', '>= 0.2.16')
|
28
28
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module EpubValidator
|
2
2
|
class FormatMessage
|
3
3
|
def process_message(message)
|
4
|
-
|
4
|
+
status = Hash.new
|
5
|
+
status[:valid] = 1
|
6
|
+
return status if message.match('No errors or warnings detected')
|
5
7
|
|
6
8
|
m_array = message.split(/\n/)
|
7
9
|
|
@@ -12,7 +14,9 @@ module EpubValidator
|
|
12
14
|
s.match('^Check finished.*')
|
13
15
|
end
|
14
16
|
|
15
|
-
|
17
|
+
status[:valid] = 0
|
18
|
+
status[:message] = m_array
|
19
|
+
return status
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
@@ -2,27 +2,33 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module EpubValidator
|
4
4
|
describe FormatMessage do
|
5
|
-
context "when it
|
6
|
-
it "should return a
|
5
|
+
context "when it receives a missing file message" do
|
6
|
+
it "should return a failed hash message" do
|
7
7
|
message = "ERROR: test.epub: I/O error: test.epub (No such file or directory)"
|
8
|
-
formatted_message = ["
|
8
|
+
formatted_message = ["#{message}"]
|
9
|
+
|
9
10
|
errm = FormatMessage.new
|
10
|
-
errm.process_message(message)
|
11
|
+
m = errm.process_message(message)
|
12
|
+
m[:valid].should eq(0)
|
13
|
+
m[:message].should eq(formatted_message)
|
11
14
|
end
|
12
15
|
end
|
13
|
-
context "when it
|
14
|
-
it "should return
|
16
|
+
context "when it receives a valid file message" do
|
17
|
+
it "should return :valid => 1" do
|
15
18
|
message = "Epubcheck Version 1.2\n\nNo errors or warnings detected\n"
|
16
19
|
errm = FormatMessage.new
|
17
|
-
errm.process_message(message).should eq(
|
20
|
+
errm.process_message(message).should eq(:valid => 1)
|
18
21
|
end
|
19
22
|
end
|
20
23
|
context "when it recieves an invalid file message" do
|
21
24
|
it "should return error message as an array" do
|
22
25
|
message = "Epubcheck Version 1.2\n\nERROR: book.epub: resource OEBPS/stylesheets/handbookish.css is missing\n\nCheck finished with warnings or errors!"
|
23
|
-
formatted_message = ["
|
26
|
+
formatted_message = ["ERROR: book.epub: resource OEBPS/stylesheets/handbookish.css is missing"]
|
27
|
+
|
24
28
|
errm = FormatMessage.new
|
25
|
-
errm.process_message(message)
|
29
|
+
m = errm.process_message(message)
|
30
|
+
m[:valid].should eq(0)
|
31
|
+
m[:message].should eq(formatted_message)
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
@@ -11,9 +11,12 @@ module EpubValidator
|
|
11
11
|
end
|
12
12
|
it "should return the output message formatted" do
|
13
13
|
message = "Epubcheck Version 1.2\n\nERROR: book.epub: resource OEBPS/stylesheets/handbookish.css is missing\n\nCheck finished with warnings or errors!"
|
14
|
-
formatted_message = ["
|
14
|
+
formatted_message = ["ERROR: book.epub: resource OEBPS/stylesheets/handbookish.css is missing"]
|
15
|
+
|
15
16
|
ec = ProcessEpub.new
|
16
|
-
ec.format_epubcheck_output(message)
|
17
|
+
m = ec.format_epubcheck_output(message)
|
18
|
+
m[:valid].should eq(0)
|
19
|
+
m[:message].should eq(formatted_message)
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epub_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,41 +9,41 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-08 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &18848460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 2.8.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *18848460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: ZenTest
|
27
|
-
requirement: &
|
27
|
+
requirement: &18847980 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 4.6.2
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *18847980
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: autotest-growl
|
38
|
-
requirement: &
|
38
|
+
requirement: &18847500 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
43
|
+
version: 0.2.16
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *18847500
|
47
47
|
description: EPUB Validator lets you check that your EPUB 2 files are valid IDPF documents
|
48
48
|
with the help of the epubcheck tool.
|
49
49
|
email:
|