epub-parser 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b83027d3e13f05cfbfae7040371f72608502d9b
4
- data.tar.gz: 4aced6978cc17c4301c7f478e1197b6701d909b1
3
+ metadata.gz: 0863e952eebf7e5a0c502a70ef0d4eb53dc6f53a
4
+ data.tar.gz: 3f30d0aa575bc3b2ac740ec50ef54cee1452546c
5
5
  SHA512:
6
- metadata.gz: fcba9ccf2de4b1ab26f3443836e10ead323fcf9139164abd28385cc08e0838339fd3a6287b358b968b83f44a3fa5277c785c13000494581bc874975a84f82e27
7
- data.tar.gz: f1109a47200e5e0c94d67fecda3dbd464e170883fff35812bea44fb44cd780b66229f94a3dd9bdde162d8a82473596a1b76b595bfc2c11de3196db9c3ba3b977
6
+ metadata.gz: 55884a448641a94a3f100e09d3aed2ab554b299903af5008c6aa708932310c7164891667e426fd5093a152fa74e16cc44e9c92360db0c129ecd0c3e6933f9505
7
+ data.tar.gz: a09a814b990ccced895fe9e462fe44dad2ad244cbeda02a82afe69d4e5988b3bd98b5698a76e6c69cf87b3d64ebf66c63f21b24cd8485137c49da6cb0ad50707
data/.yardopts CHANGED
@@ -1,3 +1,6 @@
1
1
  -
2
- wiki/Home.md
3
- wiki/Item.md
2
+ CHANGELOG.markdown
3
+ MIT-LICENSE
4
+ docs/Home.markdown
5
+ docs/Item.markdown
6
+ docs/FixedLayout.markdown
@@ -0,0 +1,33 @@
1
+ CHANGELOG
2
+ =========
3
+ 0.1.4
4
+ -----
5
+ * [Fixed-Layout Documents][fixed-layout] support
6
+ * Define `ContentDocument::XHTML#top_level?`
7
+ * Define `Spine::Itemref#page_spread` and `#page_spread=`
8
+ * Define some utility methods around `Manifest::Item` and `Spine::Itemref`
9
+ * `Manifest::Item#itemref`
10
+ * `Spine::Itemref#item=`
11
+
12
+ [fixed-layout]: http://www.idpf.org/epub/fxl/
13
+
14
+ 0.1.3
15
+ -----
16
+ * Add `EPUB::Parser::Utils` module
17
+ * Add a command-line tool `epub-open`
18
+ * Add support for XHTML Navigation Document
19
+ * Make `EPUB::Publication::Package::Metadata#to_hash` obsolete. Use `#to_h` instead
20
+ * Add utility methods `EPUB#description`, `EPUB#date` and `EPUB#unique_identifier`
21
+
22
+ 0.1.2
23
+ -----
24
+ * Fix a bug that `Item#read` couldn't read file when `href` is percent-encoded(Thanks, [gambhiro][]!)
25
+
26
+ [gambhiro]: https://github.com/gambhiro
27
+
28
+ 0.1.1
29
+ -----
30
+ * Parse package@prefix and attach it as `Package#prefix`
31
+ * `Manifest::Item#iri` was removed. It have existed for files in unzipped epub books but now EPUB Parser retrieves files from zip archive directly. `#href` now returns `Addressable::URI` object.
32
+ * `Metadata::Link#iri`: ditto.
33
+ * `Guide::Reference#iri`: ditto.
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in epub-parser.gemspec
4
2
  gemspec
data/README.markdown CHANGED
@@ -4,6 +4,7 @@ EPUB Parser
4
4
 
5
5
  INSTALLATION
6
6
  -------
7
+
7
8
  gem install epub-parser
8
9
 
9
10
  USAGE
@@ -18,9 +19,8 @@ USAGE
18
19
  # do somethong...
19
20
  end
20
21
 
21
- See the [wiki][] or [API Documentation][rubydoc] for more info.
22
+ See files in docs directory or [API Documentation][rubydoc] for more info.
22
23
 
23
- [wiki]: https://github.com/KitaitiMakoto/epub-parser/wiki
24
24
  [rubydoc]: http://rubydoc.info/gems/epub-parser/frames
25
25
 
26
26
  ### `epubinfo` command-line tool
@@ -75,10 +75,17 @@ REQUIREMENTS
75
75
  * libxml2 and libxslt for Nokogiri gem
76
76
  * C compiler to compile Zip/Ruby and Nokogiri
77
77
 
78
- CHANGELOG
79
- ---------
78
+ RECENT CHANGES
79
+ --------------
80
+ ### 0.1.4
81
+ * [Fixed-Layout Documents][fixed-layout] support
82
+ * Define `ContentDocument::XHTML#top_level?`
83
+ * Define `Spine::Itemref#page_spread` and `#page_spread=`
84
+ * Define some utility methods around `Manifest::Item` and `Spine::Itemref`
85
+
86
+ [fixed-layout]: http://www.idpf.org/epub/fxl/
87
+
80
88
  ### 0.1.3
81
- * Add `EPUB::Parser::Utils` module
82
89
  * Add a command-line tool `epub-open`
83
90
  * Add support for XHTML Navigation Document
84
91
  * Make `EPUB::Publication::Package::Metadata#to_hash` obsolete. Use `#to_h` instead
@@ -91,10 +98,12 @@ CHANGELOG
91
98
 
92
99
  ### 0.1.1
93
100
  * Parse package@prefix and attach it as `Package#prefix`
94
- * `Manifest::Item#iri` was removed. It have existed for files in unzipped epub books but now EPUB Parser retrieves files from zip archive directly. `#href` now returns `Addressable::URI` object.
101
+ * `Manifest::Item#iri` was removed. `#href` now returns `Addressable::URI` object.
95
102
  * `Metadata::Link#iri`: ditto.
96
103
  * `Guide::Reference#iri`: ditto.
97
104
 
105
+ See CHANGELOG.markdown for details.
106
+
98
107
  TODOS
99
108
  -----
100
109
  * Simple inspect for `epub-open` tool
data/Rakefile CHANGED
@@ -6,6 +6,7 @@ require 'rdoc/task'
6
6
  require 'cucumber'
7
7
  require 'cucumber/rake/task'
8
8
  require 'epub/parser/version'
9
+ require 'zipruby'
9
10
 
10
11
  task :default => :test
11
12
  task :test => 'test:default'
@@ -20,6 +21,10 @@ namespace :test do
20
21
  task :build => :clean do
21
22
  input_dir = 'test/fixtures/book'
22
23
  sh "epzip #{input_dir}"
24
+ small_file = File.read("#{input_dir}/OPS/case-sensitive.xhtml")
25
+ Zip::Archive.open "#{input_dir}.epub" do |archive|
26
+ archive.add_buffer 'OPS/CASE-SENSITIVE.xhtml', small_file.sub('small file name', 'LARGE FILE NAME')
27
+ end
23
28
  end
24
29
 
25
30
  Rake::TestTask.new do |task|
@@ -41,7 +46,7 @@ namespace :doc do
41
46
  rdoc.rdoc_files = FileList['lib/**/*.rb']
42
47
  rdoc.rdoc_files.include 'README.markdown'
43
48
  rdoc.rdoc_files.include 'MIT-LICENSE'
44
- rdoc.rdoc_files.include 'wiki/**/*.md'
49
+ rdoc.rdoc_files.include 'docs/**/*.md'
45
50
  end
46
51
  end
47
52
 
@@ -57,7 +62,7 @@ namespace :gem do
57
62
  end
58
63
 
59
64
  desc "Create tag v#{EPUB::Parser::VERSION} and build and push epub-parser-#{EPUB::Parser::VERSION}.gem to Rubygems"
60
- task :release do
65
+ task :release => :test do
61
66
  Bundler::GemHelper.new.release_gem
62
67
  end
63
68
  end
@@ -0,0 +1,98 @@
1
+ {file:docs/Home.markdown} > **{file:docs/FixedLayout.markdow}**
2
+
3
+ Fixed-Layout Documents
4
+ ======================
5
+
6
+ Since v0.1.4, EPUB Parser supports Fixed-Layout Documents by {EPUB::Publication::FixedLayout} module.
7
+ It is set "on" when `rendition` property exists in `prefix` attribute of `package` element in rootfile.
8
+
9
+ EPUB Fixed-Layout defines some additional properties to see how to render Content Documents. This EPUB Parser library supports it by providing convenience methods to know how to render.
10
+
11
+ Methods for {EPUB::Publication::Package}
12
+ ----------------------------------------
13
+
14
+ ### {EPUB::Publication::FixedLayout::PackageMixin#using_fixed_layout #using_fixed_layout}
15
+
16
+ It is `true` when `package@prefix` attribute has `rendition` property.
17
+
18
+ parser = EPUB::Parser::Publication.new(<<OPF, 'dummy/rootfile.opf')
19
+ <package version="3.0"
20
+ unique-identifier="pub-id"
21
+ xmlns="http://www.idpf.org/2007/opf"
22
+ prefix="rendition: http://www.idpf.org/vocab/rendition/#">
23
+ </package>
24
+ OPF
25
+ package = parser.parse_package
26
+ package.using_fixed_layout # => true
27
+
28
+ And you can set by your self:
29
+
30
+ package.using_fixed_layout = true
31
+ package.prefix # => {"rendition"=>"http://www.idpf.org/vocab/rendition/#"}
32
+
33
+ Common Methods
34
+ --------------
35
+
36
+ Methods below are provided for
37
+
38
+ * {EPUB::Publication::Package::Metadata},
39
+ * {EPUB::Publication::Package::Spine::Itemref},
40
+ * {EPUB::Publication::Package::Manifest::Item} and
41
+ * {EPUB::ContentDocument::XHTML}(and its subclasses).
42
+
43
+ ### #rendition_layout, #rendition_orientation and #rendition_spread
44
+
45
+ `rendition:xxx` property is specified `meta` element in `package/metadata` and `properties` attribute of `package/spine/itemref` elements in EPUB Publications. You can recommended to use `rendition_xxx` attribute to set them although you can do it by manipulating {EPUB::Publication::Package::Metadata} and {EPUB::Publication::Package::Spine::Itemref}s directly. It is the reason why it be recommended that you must manipulate some objects not only one object to set a document's `rendition:layout` to, for instance, `reflowable`; {EPUB::Publication::Package::Metadata::Meta Metadata::Meta} and {EPUB::Publication::Package::Spine::Itemref#properties Spine::Itemref#properties}. It is bothered and tends to be mistaken, so you're recommended to use not them but `rendition_layout`.
46
+
47
+ Usage is simple. Just read and write attribute values.
48
+
49
+ metadata.rendition_layout # => "reflowable"
50
+ metadata.rendition_layout = 'pre-paginated'
51
+ metadata.rendition_layout # => "pre-paginated"
52
+
53
+ itemref.rendition_layout # => "pre-paginated"
54
+ itemref.rendition_layout = "reflowable"
55
+ itemref.rendition_layout # => "reflowable"
56
+
57
+ These methods are defined for {EPUB::Publication::Package::Metadata}, {EPUB::Publication::Package::Spine::Itemref}, {EPUB::Publication::Package::Manifest::Item} and {EPUB::ContentDocument::XHTML}. Methods for {EPUB::Publication::Package::Metadata Metadata} and {EPUB::Publication::Package::Spine::Itemref Itemref} are primary and ones for {EPUB::Publication::Package::Manifest::Item Item} and {EPUB::ContentDocument::XHTML ContentDocument} are simply delegated to {EPUB::Publication::Package::Spine::Itemref Itemref}.
58
+
59
+ ### aliases
60
+
61
+ Each attribute `rendition_xxx` has alias attribute as just `xxx`.
62
+
63
+ metadata.orientation = 'portrait'
64
+ metadata.orientation # => "portrait"
65
+ metadata.rendition_orientation # => "portrait"
66
+
67
+ ### #reflowable? and #pre_paginated?
68
+
69
+ Predicate methods `#reflowable?` and `#pre_paginated?` which are shortcuts for comparison `rendition_layout` to arbitrary property value.
70
+
71
+ itemref.rendition_layout = 'pre-paginated'
72
+ itemref.reflowable? # => false
73
+ itemref.pre_paginated? # => true
74
+
75
+ ### #make_reflowable and make_pre_paginated
76
+
77
+ `#make_reflowable` and `#make_pre_paginated` can be used instead of calling `rendition_layout` and comparing with `String` `"reflowable"` or `"pre-paginated"`, they help you from mistyping such like `"pre_paginated"`(using underscore rather than hyphen).
78
+
79
+ They are aliased to `#reflowable!` and `#pre_paginated!`.
80
+
81
+ Methods for {EPUB::Publication::Package::Spine::Itemref}
82
+ --------------------------------------------------------
83
+
84
+ ### #page_spread
85
+
86
+ {EPUB::Publication::FixedLayout FixedLayout} module adds property `center` to {EPUB::Publication::Package::Spine::Itemref#page_spread}'s available properties, which are ever `left` and `right`.
87
+
88
+ itemref.page_spread # => nil
89
+ itemref.page_spread = 'center'
90
+ itemref.page_spread # => "center"
91
+ itemref.properties # => ["rendition:page-spread-center"]
92
+
93
+ References
94
+ ----------
95
+
96
+ * [Fixed-Layout Documents][fixed-layout] on IDPF site
97
+
98
+ [fixed-layout]: http://www.idpf.org/epub/fxl/
@@ -32,9 +32,7 @@ This book object can yield page by spine's order(spine defines the order to read
32
32
  # do something...
33
33
  end
34
34
 
35
- `page` above is a [`EPUB::Publication::Package::Manifest::Item`][1] object and you can call `#href` to see where is the page file:
36
-
37
- [1]:http://rubydoc.info/gems/epub-parser/EPUB/Publication/Package/Manifest/Item
35
+ `page` above is an {EPUB::Publication::Package::Manifest::Item} object and you can call {EPUB::Publication::Package::Manifest::Item#href #href} to see where is the page file:
38
36
 
39
37
  book.each_page_on_spine do |page|
40
38
  file = page.href # => path/to/page/in/zip/archive
@@ -43,15 +41,15 @@ This book object can yield page by spine's order(spine defines the order to read
43
41
  }
44
42
  end
45
43
 
46
- And `Item` provides syntax suger `#read` for above:
44
+ And {EPUB::Publication::Package::Manifest::Item Item} provides syntax suger {EPUB::Publication::Package::Manifest::Item#read #read} for above:
47
45
 
48
46
  html = page.read
49
47
  doc = Nokogiri.HTML html
50
48
  # do something with Nokogiri as always
51
49
 
52
- For several utilities of Item, see [[Item]] page.
50
+ For several utilities of Item, see {file:docs/Item.markdown} page.
53
51
 
54
- By the way, although `book` above is a `EPUB::Book` object, all features are provided by `EPUB` module. Therefore YourBook class can include the features of EPUB:
52
+ By the way, although `book` above is a {EPUB::Book} object, all features are provided by {EPUB} module. Therefore YourBook class can include the features of {EPUB}:
55
53
 
56
54
  require 'epub'
57
55
 
@@ -111,4 +109,4 @@ License
111
109
  =======
112
110
 
113
111
  This library is distributed under the term of the MIT Licence.
114
- See [MIT-LICENSE](/epub/parser/blobs/master/MIT-LICENSE) file for more info.
112
+ See {file:MIT-LICENSE} file for more info.
@@ -1,17 +1,17 @@
1
- [[Home]] > **[[Item]]**
1
+ {file:docs/Home.markdown} > **{file:docs/Item}**
2
2
 
3
3
  Overview
4
4
  ========
5
5
 
6
- When manipulating resources (XHTML, images, audio...) in EPUB, [`EPUB::Publication::Manifest::Item`](http://rubydoc.info/gems/epub-parser/EPUB/Publication/Package/Manifest/Item) object will be used.
7
- And objects which `EPUB#each_page_on_spine` yields are also instances of this class.
6
+ When manipulating resources (XHTML, images, audio...) in EPUB, {EPUB::Publication::Package::Manifest::Item} object will be used.
7
+ And objects which {EPUB#each_page_on_spine} yields are also instances of this class.
8
8
 
9
9
  Here's the tutorial of this class.
10
10
 
11
11
  Getting Items
12
12
  =============
13
13
 
14
- Getting the `Item` object you want is due to other classes, mainly `EPUB` module:
14
+ Getting the {EPUB::Publication::Package::Manifest::Item Item} object you want is due to other classes, mainly {EPUB} module:
15
15
 
16
16
  book = EPUB::Parser.parse 'book.epub'
17
17
  book.resouces # => all items including XHTMLs, CSSs, images, audios and so on
@@ -27,7 +27,7 @@ For the last two examples, knowledge for EPUB structure is required.
27
27
  Using Items
28
28
  ===========
29
29
 
30
- Once you've got an `Item`, it provides informations about the item(file).
30
+ Once you've got an {EPUB::Publication::Package::Manifest::Item Item}, it provides informations about the item(file).
31
31
 
32
32
  item.id # => the ID of the item
33
33
  item.media_type # => media type like application/xhtml+xml
@@ -37,7 +37,7 @@ Once you've got an `Item`, it provides informations about the item(file).
37
37
  item.fallback_chain # => ditto.
38
38
  item.using_fallback_chain # => ditto.
39
39
 
40
- And `Item` also provides some methods which helps you handle the item.
40
+ And {EPUB::Publication::Package::Manifest::Item Item} also provides some methods which helps you handle the item.
41
41
 
42
42
  For example, for XHTML:
43
43
 
@@ -52,13 +52,13 @@ For image:
52
52
  Fallback Chain
53
53
  ==============
54
54
 
55
- Some items have `fallback` attribute, which provides the item to be used when reading system(your app) cannot handle with given item for some reason(for example, media type not supported).
55
+ Some items have {EPUB::Publication::Package::Manifest::Item#fallback `fallback`} attribute, which provides the item to be used when reading system(your app) cannot handle with given item for some reason(for example, media type not supported).
56
56
 
57
- Of course, you can get it by calling `fallback` method:
57
+ Of course, you can get it by calling {EPUB::Publication::Package::Manifest::Item#fallback `fallback`} method:
58
58
 
59
59
  item.fallback # => fallback `Item` or nil
60
60
 
61
- Also you can use `use_fallback_chain` not to check if you can accept item or not for every item:
61
+ Also you can use {EPUB::Publication::Package::Manifest::Item#use_fallback_chain `use_fallback_chain`} not to check if you can accept item or not for every item:
62
62
 
63
63
  item.use_fallback_chain :supported => 'image/png' do |png|
64
64
  # do something with PNG image
@@ -66,7 +66,7 @@ Also you can use `use_fallback_chain` not to check if you can accept item or not
66
66
 
67
67
  If item's media type is, for instance, 'image/x-eps', the fallback is used.
68
68
  If the fallback item's media type is 'image/png', `png` variable means the item, if not, "fallback of fallback" will be checked.
69
- Finally you can use the item you want, or `EPUB::MediaType::UnsupportedError` exception will be raised(if no item you can accept found).
69
+ Finally you can use the item you want, or {EPUB::Constants::MediaType::UnsupportedError EPUB::MediaType::UnsupportedError} exception will be raised(if no item you can accept found).
70
70
  Therefore, you should `rescue` clause:
71
71
 
72
72
  # :unsupported option can also be used
data/epub-parser.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.files = `git ls-files`.split("\n")
18
18
  .push('test/fixtures/book/OPS/ルートファイル.opf')
19
19
  .push('test/fixtures/book/OPS/日本語.xhtml')
20
- .push(Dir['wiki/*.md'])
20
+ .push(Dir['docs/*.md'])
21
21
  s.files.reject! do |fn|
22
22
  ['"test/fixtures/book/OPS/\343\203\253\343\203\274\343\203\210\343\203\225\343\202\241\343\202\244\343\203\253.opf"', '"test/fixtures/book/OPS/\346\227\245\346\234\254\350\252\236.xhtml"'].include? fn
23
23
  end
@@ -26,7 +26,6 @@ Gem::Specification.new do |s|
26
26
  s.require_paths = ["lib"]
27
27
  s.has_rdoc = 'yard'
28
28
 
29
- s.add_development_dependency 'rubygems-test'
30
29
  s.add_development_dependency 'rake'
31
30
  s.add_development_dependency 'pry'
32
31
  s.add_development_dependency 'pry-doc'
@@ -43,6 +42,6 @@ Gem::Specification.new do |s|
43
42
 
44
43
  s.add_runtime_dependency 'enumerabler'
45
44
  s.add_runtime_dependency 'zipruby'
46
- s.add_runtime_dependency 'nokogiri', '1.5.8'
45
+ s.add_runtime_dependency 'nokogiri', '1.5.9'
47
46
  s.add_runtime_dependency 'addressable'
48
47
  end
data/lib/epub.rb CHANGED
@@ -31,6 +31,12 @@ module EPUB
31
31
  end
32
32
  end
33
33
 
34
+ %w[nav].each do |met|
35
+ define_method met do
36
+ manifest.__send__ met
37
+ end
38
+ end
39
+
34
40
  def each_page_on_spine(&blk)
35
41
  enum = package.spine.items
36
42
  if block_given?
@@ -44,6 +44,10 @@ module EPUB
44
44
  def each_landmark
45
45
  end
46
46
 
47
+ def navigation
48
+ navigations.first
49
+ end
50
+
47
51
  class Item
48
52
  attr_accessor :items, :text, :hidden,
49
53
  :content_document, :href, :item
@@ -7,6 +7,11 @@ module EPUB
7
7
  item.read
8
8
  end
9
9
  alias raw_document read
10
+
11
+ # referenced directly from spine?
12
+ def top_level?
13
+ !! item.itemref
14
+ end
10
15
  end
11
16
  end
12
17
  end
@@ -8,13 +8,6 @@ module EPUB
8
8
  class ContentDocument
9
9
  include Utils
10
10
 
11
- class << self
12
- # @param [EPUB::Publication::Package::Manifest::Item] item
13
- def parse(item)
14
- new(item).parse
15
- end
16
- end
17
-
18
11
  # @param [EPUB::Publication::Package::Manifest::Item] item
19
12
  def initialize(item)
20
13
  @item = item
@@ -55,19 +55,19 @@ module EPUB
55
55
  encryption
56
56
  end
57
57
 
58
- def parse_manifest
58
+ def parse_manifest(content)
59
59
  warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE
60
60
  end
61
61
 
62
- def parse_metadata
62
+ def parse_metadata(content)
63
63
  warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE
64
64
  end
65
65
 
66
- def parse_rights
66
+ def parse_rights(content)
67
67
  warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE
68
68
  end
69
69
 
70
- def parse_signatures
70
+ def parse_signatures(content)
71
71
  warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE
72
72
  end
73
73
  end