epub_validator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest ADDED
@@ -0,0 +1,7 @@
1
+ require "autotest/growl"
2
+
3
+ Autotest.add_hook :initialize do |at|
4
+ at.add_mapping(%r%^spec/(epub_validator)/.*rb$%) {|filename, _|
5
+ filename
6
+ }
7
+ end
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in epub_validator.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # epubValidator - Check your EPUB Books
2
+
3
+ This library will check that your EPUB v2 files are valid IDPF documents (using epubcheck-1.2.jar) and return a successful or error message. It can be called as a Ruby library, or invoked from the command line.
4
+
5
+ For more about the IDPF see http://idpf.org
6
+
7
+ For more about the epubcheck tool see http://code.google.com/p/epubcheck/
8
+
9
+
10
+ ## Setup
11
+
12
+ ```
13
+ gem install epub_validator
14
+ ```
15
+
16
+ ## Basic Usage
17
+
18
+ Sample usage and output for a missing EPUB file:
19
+
20
+ ``` ruby
21
+ require 'epub_validator'
22
+
23
+ ev = EpubValidator.check_file('/path/to/missing.epub')
24
+ ev.message.each do |m|
25
+ puts m
26
+ end
27
+ => # FAILED!
28
+ => # ERROR: /path/to/missing.epub: I/O error: path/to/missing.epub (No such file or directory)
29
+ ```
30
+
31
+ Now from the command line:
32
+
33
+ ``` terminal
34
+ $ epub_validator /path/to/missing.epub
35
+ Checking....
36
+ FAILED!
37
+ ERROR: /path/to/missing.epub: I/O error: /path/to/missing.epub (No such file or directory)
38
+ ```
39
+
40
+
41
+ ## Requirements
42
+
43
+ Java must be installed and set in your PATH.
44
+
45
+ ## Future Features
46
+
47
+ * Accept directory containing many .epub files for processing.
48
+ * Write results to log file.
49
+ * Format "error" output for more intuitive instructions.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ #require 'cucumber/rake/task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ #Cucumber::RakeTask.new(:features)
7
+
8
+ task :default => :spec
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'epub_validator'
7
+ #require 'epub_validator/command'
8
+
9
+ # Thanks heroku!
10
+ args = ARGV.dup
11
+ ARGV.clear
12
+ command = args.shift.strip rescue 'help'
13
+
14
+ # need to implement Command class
15
+ #EpubValidator::Command.run(command, args)
16
+
17
+ puts "Checking...."
18
+ ev = EpubValidator.check_file(command)
19
+ puts ev.message
20
+
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'epub_validator/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.platform = Gem::Platform::RUBY
7
+
8
+ s.name = "epub_validator"
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.}
12
+
13
+ s.authors = ["Mike Cook"]
14
+ s.email = ["m@mikecook.co.uk"]
15
+ s.homepage = "http://mikecook.co.uk"
16
+
17
+ s.required_ruby_version = ">= 1.9.2"
18
+ s.required_rubygems_version = ">= 1.3.6"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
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"
32
+ end
@@ -0,0 +1,10 @@
1
+ Dir["#{File.dirname(__FILE__)}/epub_validator/**/*"].each {|file| require(file)}
2
+
3
+ require 'epub_validator/check_epub'
4
+
5
+ module EpubValidator
6
+ def self.check_file(filename)
7
+ CheckEpub.new(filename)
8
+ end
9
+ end
10
+
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,3 @@
1
+ module EpubValidator
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2007 Adobe Systems Incorporated
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
@@ -0,0 +1,61 @@
1
+ This folder contains the distribution of epubcheck project.
2
+
3
+ EpubCheck is a tool to validate IDPF Epub files. It can detect many
4
+ types of errors in Epub. OCF container structure, OPF and OPS mark-up,
5
+ and internal reference consistency are checked. EpubCheck can be run
6
+ as a standalone command-line tool, installed as a web application or
7
+ used as a library.
8
+
9
+ Epubcheck project home: http://code.google.com/p/epubcheck/
10
+
11
+ BUILDING
12
+
13
+ To build epubcheck from the sources you need Java Development Kit (JDK) 1.5 or above
14
+ and Apache ant (http://ant.apache.org/) 1.6 or above installed
15
+
16
+ Run
17
+
18
+ ant -f build.xml
19
+
20
+ RUNNING
21
+
22
+ To run the tool you need Java Runtime (1.5 or above). Any OS should do. Run
23
+ it from the command line:
24
+
25
+ java -jar epubcheck-x.x.x.jar file.epub
26
+
27
+ All detected errors are simply printed to stderr.
28
+
29
+ USING AS A LIBRARY
30
+
31
+ You can also use EpubCheck as a library in your Java application. EpubCheck
32
+ public interfaces can be found in com.adobe.epubcheck.api package. EpubCheck
33
+ class can be used to instantiate a validation engine. Use one of its
34
+ constructors and then call validate() method. Report is an interface that
35
+ you can implement to get a list of the errors and warnings reported by the
36
+ validation engine (instead of the error list being printed out).
37
+
38
+ LICENSING
39
+
40
+ See COPYING.txt
41
+
42
+ AUTHORS
43
+
44
+ Peter Sorotokin
45
+ Garth Conboy
46
+ Markus Gylling
47
+ Piotr Kula
48
+
49
+ Most of the EpubCheck functionality comes from the schema validation tool Jing
50
+ and schemas that were developed by IDPF and DAISY. EpubCheck development was
51
+ largely done at Adobe Systems.
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
Binary file
@@ -0,0 +1,12 @@
1
+ Jing Copying Conditions
2
+
3
+ Copyright (c) 2001-2003 Thai Open Source Software Center Ltd
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10
+ * Neither the name of the Thai Open Source Software Center Ltd nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Binary file
Binary file
@@ -0,0 +1,29 @@
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
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe EpubValidator do
4
+ context "when given a single EPUB filename" do
5
+ it "should validate the file"
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require 'epub_validator'
2
+
3
+ RSpec.configure do |config|
4
+ config.mock_with :rspec
5
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: epub_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mike Cook
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-29 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &11655920 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *11655920
25
+ - !ruby/object:Gem::Dependency
26
+ name: ZenTest
27
+ requirement: &11654780 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *11654780
36
+ - !ruby/object:Gem::Dependency
37
+ name: autotest-growl
38
+ requirement: &11653840 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
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.
50
+ email:
51
+ - m@mikecook.co.uk
52
+ executables:
53
+ - epub_validator
54
+ extensions: []
55
+ extra_rdoc_files: []
56
+ files:
57
+ - .autotest
58
+ - .gitignore
59
+ - .rspec
60
+ - Gemfile
61
+ - README.md
62
+ - Rakefile
63
+ - bin/epub_validator
64
+ - epub_validator.gemspec
65
+ - lib/epub_validator.rb
66
+ - lib/epub_validator/check_epub.rb
67
+ - lib/epub_validator/version.rb
68
+ - lib/epubcheck-1-2/COPYING.txt
69
+ - lib/epubcheck-1-2/README.txt
70
+ - lib/epubcheck-1-2/epubcheck-1.2.jar
71
+ - lib/epubcheck-1-2/jing_license.txt
72
+ - lib/epubcheck-1-2/lib/jing.jar
73
+ - lib/epubcheck-1-2/lib/saxon.jar
74
+ - spec/epub_validator/check_epub_spec.rb
75
+ - spec/epub_validator_spec.rb
76
+ - spec/spec_helper.rb
77
+ homepage: http://mikecook.co.uk
78
+ licenses: []
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: 1.9.2
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: 1.3.6
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 1.8.10
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Run epubcheck.jar on single/multiple EPUB files.
101
+ test_files: []