eeepub_ext 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +87 -0
- data/Rakefile +22 -0
- data/eeepub.gemspec +27 -0
- data/examples/files/bar.html +42 -0
- data/examples/files/foo.html +42 -0
- data/examples/simple_epub.rb +25 -0
- data/lib/eeepub.rb +15 -0
- data/lib/eeepub/container_item.rb +108 -0
- data/lib/eeepub/easy.rb +100 -0
- data/lib/eeepub/maker.rb +156 -0
- data/lib/eeepub/ncx.rb +68 -0
- data/lib/eeepub/ocf.rb +129 -0
- data/lib/eeepub/opf.rb +150 -0
- data/spec/eeepub/container_item_spec.rb +20 -0
- data/spec/eeepub/easy_spec.rb +71 -0
- data/spec/eeepub/maker_spec.rb +132 -0
- data/spec/eeepub/ncx_spec.rb +80 -0
- data/spec/eeepub/ocf_spec.rb +50 -0
- data/spec/eeepub/opf_spec.rb +267 -0
- data/spec/eeepub_spec.rb +4 -0
- data/spec/spec_helper.rb +13 -0
- metadata +193 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e81b6072e23bfd9103aa3f55ebba557ee8550cf4
|
4
|
+
data.tar.gz: af36680b189627d88e5430907a7240f4f8705b3d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 726c78f2e94268d1643a4efb140b57daf00bc7ee48c54e9a10eea68e18fca12d2d117b2e8206a54825b487372ddb1c7ad5b6f07548807fd972782884bb1d6246
|
7
|
+
data.tar.gz: 59678e2008c29c8d320c05406630ad533b433bcf72ea08fd2e308b468a5a2f3e91a4b50b3e5f862a1d9d9ac6df42abcb9e6e04f84a38ea7bea9f62f52e5c75a6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 jugyo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
## EeePub (Temporary Extension)
|
2
|
+
|
3
|
+
### Notes & Remarks
|
4
|
+
|
5
|
+
Patch to the original gem that I need for my [source2epub](https://rubygems.org/gems/source2epub) gem to work.
|
6
|
+
This gem will be deprecated as soon as the [rubyzip bug](https://github.com/jugyo/eeepub/pull/34) is fixed/merged by
|
7
|
+
the original author. This is my temporary solution to make my gem work so that
|
8
|
+
I can use the gem without the need to manually install my own fork first via Github.
|
9
|
+
|
10
|
+
I still can't find the way to make use of the original gem name in the gemspec.
|
11
|
+
|
12
|
+
EeePub
|
13
|
+
======
|
14
|
+
|
15
|
+
EeePub is a Ruby ePub generator.
|
16
|
+
|
17
|
+
Usage
|
18
|
+
-------
|
19
|
+
|
20
|
+
epub = EeePub.make do
|
21
|
+
title 'sample'
|
22
|
+
creator 'jugyo'
|
23
|
+
publisher 'jugyo.org'
|
24
|
+
date '2010-05-06'
|
25
|
+
identifier 'http://example.com/book/foo', :scheme => 'URL'
|
26
|
+
uid 'http://example.com/book/foo'
|
27
|
+
|
28
|
+
files ['/path/to/foo.html', '/path/to/bar.html'] # or files [{'/path/to/foo.html' => 'dest/dir'}, {'/path/to/bar.html' => 'dest/dir'}]
|
29
|
+
nav [
|
30
|
+
{:label => '1. foo', :content => 'foo.html', :nav => [
|
31
|
+
{:label => '1.1 foo-1', :content => 'foo.html#foo-1'}
|
32
|
+
]},
|
33
|
+
{:label => '1. bar', :content => 'bar.html'}
|
34
|
+
]
|
35
|
+
end
|
36
|
+
epub.save('sample.epub')
|
37
|
+
|
38
|
+
### Low Level API
|
39
|
+
|
40
|
+
Create NCX:
|
41
|
+
|
42
|
+
EeePub::NCX.new(
|
43
|
+
:uid => 'xxxx',
|
44
|
+
:title => 'sample',
|
45
|
+
:nav => [
|
46
|
+
{:label => '1. foo', :content => 'foo.html'},
|
47
|
+
{:label => '2. bar', :content => 'bar.html'}
|
48
|
+
]
|
49
|
+
).save(File.join('sample', 'toc.ncx'))
|
50
|
+
|
51
|
+
Create OPF:
|
52
|
+
|
53
|
+
EeePub::OPF.new(
|
54
|
+
:title => 'sample',
|
55
|
+
:identifier => {:value => '0-0000000-0-0', :scheme => 'ISBN'},
|
56
|
+
:manifest => ['foo.html', 'bar.html'],
|
57
|
+
:ncx => 'toc.ncx'
|
58
|
+
).save(File.join('sample', 'content.opf'))
|
59
|
+
|
60
|
+
Create OCF and ePub file:
|
61
|
+
|
62
|
+
EeePub::OCF.new(
|
63
|
+
:dir => 'sample',
|
64
|
+
:container => 'content.opf'
|
65
|
+
).save('sample.epub')
|
66
|
+
|
67
|
+
Install
|
68
|
+
-------
|
69
|
+
|
70
|
+
gem install eeepub
|
71
|
+
|
72
|
+
Requirements
|
73
|
+
-------
|
74
|
+
|
75
|
+
* builder
|
76
|
+
* eBook Reader :)
|
77
|
+
|
78
|
+
Links
|
79
|
+
-------
|
80
|
+
|
81
|
+
* Documentation: [http://yardoc.org/docs/jugyo-eeepub](http://yardoc.org/docs/jugyo-eeepub)
|
82
|
+
* Source code: [http://github.com/jugyo/eeepub](http://github.com/jugyo/eeepub)
|
83
|
+
|
84
|
+
Copyright
|
85
|
+
-------
|
86
|
+
|
87
|
+
Copyright (c) 2010 jugyo. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new do |t|
|
7
|
+
t.rspec_opts = ['--color']
|
8
|
+
end
|
9
|
+
rescue LoadError => e
|
10
|
+
puts "RSpec not installed"
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => :spec
|
14
|
+
|
15
|
+
begin
|
16
|
+
require 'yard'
|
17
|
+
YARD::Rake::YardocTask.new
|
18
|
+
rescue LoadError
|
19
|
+
task :yardoc do
|
20
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
21
|
+
end
|
22
|
+
end
|
data/eeepub.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = "eeepub_ext"
|
4
|
+
s.version = "0.8.2"
|
5
|
+
s.platform = Gem::Platform::RUBY
|
6
|
+
s.authors = ["jugyo"]
|
7
|
+
s.email = ["jugyo.org@gmail.com"]
|
8
|
+
s.homepage = "http://github.com/jugyo/eeepub"
|
9
|
+
s.summary = %q{ePub generator with rubyzip bug fix (unofficial version)}
|
10
|
+
s.description = %q{EeePub is a Ruby ePub generator.
|
11
|
+
This is based on the original eeepub version 0.8.1.
|
12
|
+
I added the bug fix to rubyzip to make it work with my own gem (source2epub).
|
13
|
+
This gem will be deprecated as soon as the original author (jugyo) merge
|
14
|
+
the pull request from the community with this change and many others fixes.}
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.add_dependency "builder", "~> 3.2.2"
|
20
|
+
s.add_dependency "rubyzip", "~> 1.1.6"
|
21
|
+
s.add_development_dependency "rspec", "~> 3.1.0"
|
22
|
+
s.add_development_dependency "nokogiri", "~> 1.6.3.1"
|
23
|
+
s.add_development_dependency "rr", "~> 1.1.2"
|
24
|
+
s.add_development_dependency "simplecov", "~> 0.9.0"
|
25
|
+
s.add_development_dependency "pry", "~> 0.10.1"
|
26
|
+
s.add_development_dependency "pry-byebug", "~> 2.0.0" if RUBY_VERSION >= "2.0.0"
|
27
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
|
4
|
+
<head>
|
5
|
+
<title></title>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<h1>bar</h1>
|
9
|
+
|
10
|
+
<p>foo foo foo foo</p>
|
11
|
+
<p>bar bar bar bar</p>
|
12
|
+
<p>foo foo foo foo</p>
|
13
|
+
<p>bar bar bar bar</p>
|
14
|
+
<p>foo foo foo foo</p>
|
15
|
+
<p>bar bar bar bar</p>
|
16
|
+
<p>foo foo foo foo</p>
|
17
|
+
<p>bar bar bar bar</p>
|
18
|
+
<p>foo foo foo foo</p>
|
19
|
+
<p>bar bar bar bar</p>
|
20
|
+
<p>foo foo foo foo</p>
|
21
|
+
<p>bar bar bar bar</p>
|
22
|
+
<p>foo foo foo foo</p>
|
23
|
+
<p>bar bar bar bar</p>
|
24
|
+
|
25
|
+
<h2 id="bar-1">bar-1</h2>
|
26
|
+
|
27
|
+
<p>foo foo foo foo</p>
|
28
|
+
<p>bar bar bar bar</p>
|
29
|
+
<p>foo foo foo foo</p>
|
30
|
+
<p>bar bar bar bar</p>
|
31
|
+
<p>foo foo foo foo</p>
|
32
|
+
<p>bar bar bar bar</p>
|
33
|
+
<p>foo foo foo foo</p>
|
34
|
+
<p>bar bar bar bar</p>
|
35
|
+
<p>foo foo foo foo</p>
|
36
|
+
<p>bar bar bar bar</p>
|
37
|
+
<p>foo foo foo foo</p>
|
38
|
+
<p>bar bar bar bar</p>
|
39
|
+
<p>foo foo foo foo</p>
|
40
|
+
<p>bar bar bar bar</p>
|
41
|
+
</body>
|
42
|
+
</html>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
|
4
|
+
<head>
|
5
|
+
<title></title>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<h1>foo</h1>
|
9
|
+
|
10
|
+
<p>foo foo foo foo</p>
|
11
|
+
<p>bar bar bar bar</p>
|
12
|
+
<p>foo foo foo foo</p>
|
13
|
+
<p>bar bar bar bar</p>
|
14
|
+
<p>foo foo foo foo</p>
|
15
|
+
<p>bar bar bar bar</p>
|
16
|
+
<p>foo foo foo foo</p>
|
17
|
+
<p>bar bar bar bar</p>
|
18
|
+
<p>foo foo foo foo</p>
|
19
|
+
<p>bar bar bar bar</p>
|
20
|
+
<p>foo foo foo foo</p>
|
21
|
+
<p>bar bar bar bar</p>
|
22
|
+
<p>foo foo foo foo</p>
|
23
|
+
<p>bar bar bar bar</p>
|
24
|
+
|
25
|
+
<h2 id="foo-1">foo-1</h2>
|
26
|
+
|
27
|
+
<p>foo foo foo foo</p>
|
28
|
+
<p>bar bar bar bar</p>
|
29
|
+
<p>foo foo foo foo</p>
|
30
|
+
<p>bar bar bar bar</p>
|
31
|
+
<p>foo foo foo foo</p>
|
32
|
+
<p>bar bar bar bar</p>
|
33
|
+
<p>foo foo foo foo</p>
|
34
|
+
<p>bar bar bar bar</p>
|
35
|
+
<p>foo foo foo foo</p>
|
36
|
+
<p>bar bar bar bar</p>
|
37
|
+
<p>foo foo foo foo</p>
|
38
|
+
<p>bar bar bar bar</p>
|
39
|
+
<p>foo foo foo foo</p>
|
40
|
+
<p>bar bar bar bar</p>
|
41
|
+
</body>
|
42
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
require 'rubygems'
|
3
|
+
require 'eeepub'
|
4
|
+
|
5
|
+
dir = File.join(File.dirname(__FILE__), 'files')
|
6
|
+
|
7
|
+
epub = EeePub.make do
|
8
|
+
title 'sample'
|
9
|
+
creator 'jugyo'
|
10
|
+
publisher 'jugyo.org'
|
11
|
+
date '2010-05-06'
|
12
|
+
uid 'BookId'
|
13
|
+
identifier 'http://example.com/book/foo', :scheme => 'URL', :id => 'BookId'
|
14
|
+
|
15
|
+
files [File.join(dir, 'foo.html'), File.join(dir, 'bar.html')]
|
16
|
+
nav [
|
17
|
+
{:label => '1. foo', :content => 'foo.html', :nav => [
|
18
|
+
{:label => '1.1 foo-1', :content => 'foo.html#foo-1'}
|
19
|
+
]},
|
20
|
+
{:label => '1. bar', :content => 'bar.html'}
|
21
|
+
]
|
22
|
+
end
|
23
|
+
epub.save('sample.epub')
|
24
|
+
|
25
|
+
puts "complete! => 'sample.epub'"
|
data/lib/eeepub.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'eeepub/container_item'
|
2
|
+
require 'eeepub/opf'
|
3
|
+
require 'eeepub/ocf'
|
4
|
+
require 'eeepub/ncx'
|
5
|
+
require 'eeepub/maker'
|
6
|
+
require 'eeepub/easy'
|
7
|
+
|
8
|
+
module EeePub
|
9
|
+
# Make ePub
|
10
|
+
#
|
11
|
+
# @param [Proc] block the block for initialize EeePub::Maker
|
12
|
+
def self.make(&block)
|
13
|
+
EeePub::Maker.new(&block)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'builder'
|
2
|
+
|
3
|
+
module EeePub
|
4
|
+
# Abstract base class for container item of ePub. Provides some helper methods.
|
5
|
+
#
|
6
|
+
# @abstract
|
7
|
+
class ContainerItem
|
8
|
+
class << self
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# Set default value to attribute
|
13
|
+
#
|
14
|
+
# @param [Symbol] name the attribute name
|
15
|
+
# @param [Object] default the default value
|
16
|
+
def default_value(name, default)
|
17
|
+
instance_variable_name = "@#{name}"
|
18
|
+
define_method(name) do
|
19
|
+
self.instance_variable_get(instance_variable_name) ||
|
20
|
+
self.instance_variable_set(instance_variable_name, default)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Define alias of attribute accessor
|
25
|
+
#
|
26
|
+
# @param [Symbol] name the attribute name as alias
|
27
|
+
# @param [Symbol] name the attribute name as source
|
28
|
+
def attr_alias(name, src)
|
29
|
+
alias_method name, src
|
30
|
+
alias_method :"#{name}=", :"#{src}="
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param [Hash<Symbol, Object>] values the hash of symbols and objects for attributes
|
35
|
+
def initialize(values)
|
36
|
+
set_values(values)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Set values for attributes
|
40
|
+
#
|
41
|
+
# @param [Hash<Symbol, Object>] values the hash of symbols and objects for attributes
|
42
|
+
def set_values(values)
|
43
|
+
values.each do |k, v|
|
44
|
+
self.send(:"#{k}=", v)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Convert to xml of container item
|
49
|
+
#
|
50
|
+
# @return [String] the xml of container item
|
51
|
+
def to_xml
|
52
|
+
out = ""
|
53
|
+
builder = Builder::XmlMarkup.new(:target => out, :indent => 2)
|
54
|
+
builder.instruct!
|
55
|
+
build_xml(builder)
|
56
|
+
out
|
57
|
+
end
|
58
|
+
|
59
|
+
# Save as container item
|
60
|
+
#
|
61
|
+
# @param [String] filepath the file path for container item
|
62
|
+
def save(filepath)
|
63
|
+
File.open(filepath, 'w') do |file|
|
64
|
+
file << self.to_xml
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
# Guess media type from file name
|
71
|
+
#
|
72
|
+
# @param [String] filename the file name
|
73
|
+
# @return [String] the media-type
|
74
|
+
def guess_media_type(filename)
|
75
|
+
case filename
|
76
|
+
when /.*\.x?html?$/i
|
77
|
+
'application/xhtml+xml'
|
78
|
+
when /.*\.css$/i
|
79
|
+
'text/css'
|
80
|
+
when /.*\.(jpeg|jpg)$/
|
81
|
+
'image/jpeg'
|
82
|
+
when /.*\.png$/i
|
83
|
+
'image/png'
|
84
|
+
when /.*\.gif$/i
|
85
|
+
'image/gif'
|
86
|
+
when /.*\.svg$/i
|
87
|
+
'image/svg+xml'
|
88
|
+
when /.*\.ncx$/i
|
89
|
+
'application/x-dtbncx+xml'
|
90
|
+
when /.*\.opf$/i
|
91
|
+
'application/oebps-package+xml'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Convert options for xml attributes
|
96
|
+
#
|
97
|
+
# @param [Hash<Symbol, Object>] hash the hash of symbols and objects for xml attributes
|
98
|
+
# @return [Hash<String, Object>] the options for xml attributes
|
99
|
+
def convert_to_xml_attributes(hash)
|
100
|
+
result = {}
|
101
|
+
hash.each do |k, v|
|
102
|
+
key = k.to_s.gsub('_', '-').to_sym
|
103
|
+
result[key] = v
|
104
|
+
end
|
105
|
+
result
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/lib/eeepub/easy.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module EeePub
|
5
|
+
# The class to make ePub more easily
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# epub = EeePub::Easy.new do
|
9
|
+
# title 'sample'
|
10
|
+
# creator 'jugyo'
|
11
|
+
# identifier 'http://example.com/book/foo', :scheme => 'URL'
|
12
|
+
# uid 'http://example.com/book/foo'
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# epub.sections << ['1. foo', <<HTML]
|
16
|
+
# <?xml version="1.0" encoding="UTF-8"?>
|
17
|
+
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
18
|
+
# <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
|
19
|
+
# <head>
|
20
|
+
# <title>foo</title>
|
21
|
+
# </head>
|
22
|
+
# <body>
|
23
|
+
# <p>
|
24
|
+
# foo foo foo foo foo foo
|
25
|
+
# </p>
|
26
|
+
# </body>
|
27
|
+
# </html>
|
28
|
+
# HTML
|
29
|
+
#
|
30
|
+
# epub.assets << 'image.png'
|
31
|
+
#
|
32
|
+
# epub.save('sample.epub')
|
33
|
+
class Easy < EeePub::Maker
|
34
|
+
attr_reader :sections, :assets
|
35
|
+
|
36
|
+
# @param [Proc] block the block for initialize
|
37
|
+
def initialize(&block)
|
38
|
+
@sections = []
|
39
|
+
@assets = []
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
# Save as ePub file
|
44
|
+
#
|
45
|
+
# @param [String] filename the ePub file name to save
|
46
|
+
def save(filename)
|
47
|
+
Dir.mktmpdir do |dir|
|
48
|
+
prepare(dir)
|
49
|
+
|
50
|
+
NCX.new(
|
51
|
+
:uid => @uid,
|
52
|
+
:title => @titles[0],
|
53
|
+
:nav => @nav
|
54
|
+
).save(File.join(dir, @ncx_file))
|
55
|
+
|
56
|
+
OPF.new(
|
57
|
+
:title => @titles,
|
58
|
+
:identifier => @identifiers,
|
59
|
+
:creator => @creators,
|
60
|
+
:publisher => @publishers,
|
61
|
+
:date => @dates,
|
62
|
+
:language => @languages,
|
63
|
+
:subject => @subjects,
|
64
|
+
:description => @descriptions,
|
65
|
+
:rights => @rightss,
|
66
|
+
:relation => @relations,
|
67
|
+
:manifest => @files.map{|i| File.basename(i)},
|
68
|
+
:ncx => @ncx_file
|
69
|
+
).save(File.join(dir, @opf_file))
|
70
|
+
|
71
|
+
OCF.new(
|
72
|
+
:dir => dir,
|
73
|
+
:container => @opf_file
|
74
|
+
).save(filename)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def prepare(dir)
|
81
|
+
filenames = []
|
82
|
+
sections.each_with_index do |section, index|
|
83
|
+
filename = File.join(dir, "section_#{index}.html")
|
84
|
+
File.open(filename, 'w') { |file| file.write section[1] }
|
85
|
+
filenames << filename
|
86
|
+
end
|
87
|
+
|
88
|
+
assets.each do |file|
|
89
|
+
FileUtils.cp(file, dir)
|
90
|
+
end
|
91
|
+
|
92
|
+
files(filenames + assets)
|
93
|
+
nav(
|
94
|
+
[sections, filenames].transpose.map do |section, filename|
|
95
|
+
{:label => section[0], :content => File.basename(filename)}
|
96
|
+
end
|
97
|
+
)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|