epub_validator 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -15,26 +15,26 @@ gem install epub_validator
15
15
 
16
16
  ## Basic Usage
17
17
 
18
- Sample usage and output for a missing EPUB file:
18
+ Sample usage and output:
19
19
 
20
20
  ``` ruby
21
21
  require 'epub_validator'
22
22
 
23
- ev = EpubValidator.check_file('/path/to/missing.epub')
23
+ ev = EpubValidator.check('/path/to/sample.epub')
24
24
  ev.message.each do |m|
25
25
  puts m
26
26
  end
27
27
  => # FAILED!
28
- => # ERROR: /path/to/missing.epub: I/O error: path/to/missing.epub (No such file or directory)
28
+ => # ERROR: OPS/toc.ncx(21): 'OPS/': referenced resource exists, but not declared in the OPF file
29
29
  ```
30
30
 
31
31
  Now from the command line:
32
32
 
33
33
  ``` terminal
34
- $ epub_validator /path/to/missing.epub
34
+ $ bin/epub_validator /path/to/sample.epub
35
35
  Checking....
36
36
  FAILED!
37
- ERROR: /path/to/missing.epub: I/O error: /path/to/missing.epub (No such file or directory)
37
+ ERROR: OPS/toc.ncx(21): 'OPS/': referenced resource exists, but not declared in the OPF file
38
38
  ```
39
39
 
40
40
 
@@ -44,6 +44,6 @@ Java must be installed and set in your PATH.
44
44
 
45
45
  ## Future Features
46
46
 
47
- * Accept directory containing many .epub files for processing.
48
- * Write results to log file.
49
- * Format "error" output for more intuitive instructions.
47
+ * Accept a directory containing many .epub files for processing.
48
+ * When using the command line, have option to write results to a log file
49
+ * Format "ERROR" and "WARNING" output for more intuitive instructions.
data/bin/epub_validator CHANGED
@@ -15,6 +15,6 @@ command = args.shift.strip rescue 'help'
15
15
  #EpubValidator::Command.run(command, args)
16
16
 
17
17
  puts "Checking...."
18
- ev = EpubValidator.check_file(command)
19
- puts ev.message
18
+ ev = EpubValidator.check(command)
19
+ puts ev
20
20
 
@@ -7,12 +7,12 @@ Gem::Specification.new do |s|
7
7
 
8
8
  s.name = "epub_validator"
9
9
  s.version = EpubValidator::VERSION
10
- s.summary = %q{Run epubcheck.jar on single/multiple EPUB files.}
11
- s.description = %q{EPUB Validator allows you to check your EPUB files for errors using the epubcheck Java file. You can check just one file at a time for now - eventually directories full of EPUB files and then output any errors to a log file.}
10
+ s.summary = %q{Check that your EPUB book is a valid IDPF document.}
11
+ s.description = %q{EPUB Validator lets you check that your EPUB 2 files are valid IDPF documents with the help of the epubcheck tool.}
12
12
 
13
13
  s.authors = ["Mike Cook"]
14
14
  s.email = ["m@mikecook.co.uk"]
15
- s.homepage = "http://mikecook.co.uk"
15
+ s.homepage = "https://github.com/mrcook/"
16
16
 
17
17
  s.required_ruby_version = ">= 1.9.2"
18
18
  s.required_rubygems_version = ">= 1.3.6"
@@ -22,11 +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
- # Examples
26
- #s.add_dependency('posix-spawn', "~> 0.3.6")
27
- #s.add_runtime_dependency "rest-client"
28
-
29
- s.add_dependency "rspec"
30
- s.add_dependency "ZenTest"
31
- s.add_dependency "autotest-growl"
25
+ s.add_development_dependency "rspec"
26
+ s.add_development_dependency "ZenTest"
27
+ s.add_development_dependency "autotest-growl"
32
28
  end
@@ -1,10 +1,11 @@
1
1
  Dir["#{File.dirname(__FILE__)}/epub_validator/**/*"].each {|file| require(file)}
2
2
 
3
- require 'epub_validator/check_epub'
3
+ require 'epub_validator/process_epub'
4
4
 
5
5
  module EpubValidator
6
- def self.check_file(filename)
7
- CheckEpub.new(filename)
6
+ def self.check(filename)
7
+ validation = ProcessEpub.new
8
+ validation.epubcheck(filename)
8
9
  end
9
10
  end
10
11
 
@@ -0,0 +1,18 @@
1
+ module EpubValidator
2
+ class FormatMessage
3
+ def process_message(message)
4
+ return ['Passed.'] if message.match('No errors or warnings detected')
5
+
6
+ m_array = message.split(/\n/)
7
+
8
+ # clean up all useless info
9
+ m_array.delete_if do |s|
10
+ s.empty? or
11
+ s.match('^Epubcheck Version.*') or
12
+ s.match('^Check finished.*')
13
+ end
14
+
15
+ m_array.unshift('FAILED!')
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module EpubValidator
2
+ class ProcessEpub
3
+ def epubcheck(filename)
4
+ epubcheck_jar = File.expand_path(File.dirname(__FILE__) + '/../epubcheck-1-2/epubcheck-1.2.jar')
5
+ format_epubcheck_output(`java -jar #{epubcheck_jar} "#{filename}" 2>&1`)
6
+ end
7
+
8
+ def format_epubcheck_output(message)
9
+ errm = FormatMessage.new
10
+ errm.process_message(message)
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module EpubValidator
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ module EpubValidator
4
+ describe FormatMessage do
5
+ context "when it recieves a missing file message" do
6
+ it "should return a 'FAILED!' message as an array" do
7
+ message = "ERROR: test.epub: I/O error: test.epub (No such file or directory)"
8
+ formatted_message = ["FAILED!", "ERROR: test.epub: I/O error: test.epub (No such file or directory)"]
9
+ errm = FormatMessage.new
10
+ errm.process_message(message).should eq(formatted_message)
11
+ end
12
+ end
13
+ context "when it recieves a valid file message" do
14
+ it "should return 'Passed.' message as an array" do
15
+ message = "Epubcheck Version 1.2\n\nNo errors or warnings detected\n"
16
+ errm = FormatMessage.new
17
+ errm.process_message(message).should eq(['Passed.'])
18
+ end
19
+ end
20
+ context "when it recieves an invalid file message" do
21
+ it "should return error message as an array" do
22
+ 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 = ["FAILED!", "ERROR: book.epub: resource OEBPS/stylesheets/handbookish.css is missing"]
24
+ errm = FormatMessage.new
25
+ errm.process_message(message).should eq(formatted_message)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module EpubValidator
4
+ describe ProcessEpub do
5
+ context "when it processes a file" do
6
+ it "should return a message" do
7
+ message = "Epubcheck Version 1.2\n\nERROR: rspec-test.epub: resource OEBPS/stylesheets/handbookish.css is missing\n\nCheck finished with warnings or errors!"
8
+ ec = ProcessEpub.new
9
+ ec.stub(:epubcheck).and_return(message)
10
+ ec.epubcheck("test.epub").should eq(message)
11
+ end
12
+ it "should return the output message formatted" do
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 = ["FAILED!", "ERROR: book.epub: resource OEBPS/stylesheets/handbookish.css is missing"]
15
+ ec = ProcessEpub.new
16
+ ec.format_epubcheck_output(message).should eq(formatted_message)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe EpubValidator do
4
4
  context "when given a single EPUB filename" do
5
- it "should validate the file"
5
+ #it "should validate the file"
6
6
  end
7
7
  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.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,44 +9,43 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-29 00:00:00.000000000Z
12
+ date: 2011-11-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &11655920 !ruby/object:Gem::Requirement
16
+ requirement: &11670320 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
- type: :runtime
22
+ type: :development
23
23
  prerelease: false
24
- version_requirements: *11655920
24
+ version_requirements: *11670320
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ZenTest
27
- requirement: &11654780 !ruby/object:Gem::Requirement
27
+ requirement: &11669320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
32
  version: '0'
33
- type: :runtime
33
+ type: :development
34
34
  prerelease: false
35
- version_requirements: *11654780
35
+ version_requirements: *11669320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: autotest-growl
38
- requirement: &11653840 !ruby/object:Gem::Requirement
38
+ requirement: &11668720 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
42
42
  - !ruby/object:Gem::Version
43
43
  version: '0'
44
- type: :runtime
44
+ type: :development
45
45
  prerelease: false
46
- version_requirements: *11653840
47
- description: EPUB Validator allows you to check your EPUB files for errors using the
48
- epubcheck Java file. You can check just one file at a time for now - eventually
49
- directories full of EPUB files and then output any errors to a log file.
46
+ version_requirements: *11668720
47
+ description: EPUB Validator lets you check that your EPUB 2 files are valid IDPF documents
48
+ with the help of the epubcheck tool.
50
49
  email:
51
50
  - m@mikecook.co.uk
52
51
  executables:
@@ -63,7 +62,8 @@ files:
63
62
  - bin/epub_validator
64
63
  - epub_validator.gemspec
65
64
  - lib/epub_validator.rb
66
- - lib/epub_validator/check_epub.rb
65
+ - lib/epub_validator/format_message.rb
66
+ - lib/epub_validator/process_epub.rb
67
67
  - lib/epub_validator/version.rb
68
68
  - lib/epubcheck-1-2/COPYING.txt
69
69
  - lib/epubcheck-1-2/README.txt
@@ -71,10 +71,11 @@ files:
71
71
  - lib/epubcheck-1-2/jing_license.txt
72
72
  - lib/epubcheck-1-2/lib/jing.jar
73
73
  - lib/epubcheck-1-2/lib/saxon.jar
74
- - spec/epub_validator/check_epub_spec.rb
74
+ - spec/epub_validator/format_message_spec.rb
75
+ - spec/epub_validator/process_epub_spec.rb
75
76
  - spec/epub_validator_spec.rb
76
77
  - spec/spec_helper.rb
77
- homepage: http://mikecook.co.uk
78
+ homepage: https://github.com/mrcook/
78
79
  licenses: []
79
80
  post_install_message:
80
81
  rdoc_options: []
@@ -97,5 +98,5 @@ rubyforge_project:
97
98
  rubygems_version: 1.8.10
98
99
  signing_key:
99
100
  specification_version: 3
100
- summary: Run epubcheck.jar on single/multiple EPUB files.
101
+ summary: Check that your EPUB book is a valid IDPF document.
101
102
  test_files: []
@@ -1,30 +0,0 @@
1
- module EpubValidator
2
- class CheckEpub
3
- attr_accessor :message
4
-
5
- def initialize(filename)
6
- @filename = filename
7
- @message = format_epubcheck_message(process_epub)
8
- end
9
-
10
- def process_epub
11
- epubcheck_jar = File.expand_path(File.dirname(__FILE__) + '/../epubcheck-1-2/epubcheck-1.2.jar')
12
- epubcheck = `java -jar #{epubcheck_jar} "#{@filename}" 2>&1`
13
- end
14
-
15
- def format_epubcheck_message(message)
16
- return ['Passed.'] if message.match('No errors or warnings detected')
17
-
18
- m_array = message.split(/\n/)
19
-
20
- # clean up all useless info
21
- m_array.delete_if do |s|
22
- s.empty? or
23
- s.match('^Epubcheck Version.*') or
24
- s.match('^Check finished.*')
25
- end
26
-
27
- m_array.unshift('FAILED!')
28
- end
29
- end
30
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module EpubValidator
4
- describe CheckEpub do
5
- context "when it tries to process a missing file" do
6
- it "should return missing file error message" do
7
- failed_message = 'FAILED!\n\nNo .epub file to check was specified in arguments!\n\nThe tool will EXIT!'
8
- ce = CheckEpub.new('test.epub')
9
- CheckEpub.any_instance.stub(:process_epub).and_return(failed_message)
10
- ce.process_epub.should eq(failed_message)
11
- end
12
- end
13
- context "when it processes a valid file" do
14
- it "should return 'Passed.' message as an array" do
15
- success_message = "Epubcheck Version 1.2\n\nNo errors or warnings detected\n"
16
- ce = CheckEpub.new('test.epub')
17
- ce.format_epubcheck_message(success_message).should eq(['Passed.'])
18
- end
19
- end
20
- context "when it processes an invalid file" do
21
- it "should return error message as an array" do
22
- failed_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_failed_message = ["FAILED!", "ERROR: book.epub: resource OEBPS/stylesheets/handbookish.css is missing"]
24
- ce = CheckEpub.new('test.epub')
25
- ce.format_epubcheck_message(failed_message).should eq(formatted_failed_message)
26
- end
27
- end
28
- end
29
- end