lyrics-ebook 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +340 -0
- data/README +46 -0
- data/bin/lyrics-ebook +47 -0
- data/lib/eeepub/LICENSE +20 -0
- data/lib/eeepub/README.md +77 -0
- data/lib/eeepub/Rakefile +49 -0
- data/lib/eeepub/VERSION +1 -0
- data/lib/eeepub/examples/files/bar.html +42 -0
- data/lib/eeepub/examples/files/foo.html +42 -0
- data/lib/eeepub/examples/simple_epub.rb +25 -0
- data/lib/eeepub/lib/eeepub.rb +17 -0
- data/lib/eeepub/lib/eeepub/container_item.rb +108 -0
- data/lib/eeepub/lib/eeepub/easy.rb +100 -0
- data/lib/eeepub/lib/eeepub/maker.rb +127 -0
- data/lib/eeepub/lib/eeepub/ncx.rb +68 -0
- data/lib/eeepub/lib/eeepub/ocf.rb +112 -0
- data/lib/eeepub/lib/eeepub/opf.rb +148 -0
- data/lib/eeepub/spec/eeepub/easy_spec.rb +66 -0
- data/lib/eeepub/spec/eeepub/maker_spec.rb +124 -0
- data/lib/eeepub/spec/eeepub/ncx_spec.rb +80 -0
- data/lib/eeepub/spec/eeepub/ocf_spec.rb +43 -0
- data/lib/eeepub/spec/eeepub/opf_spec.rb +262 -0
- data/lib/eeepub/spec/eeepub_spec.rb +4 -0
- data/lib/eeepub/spec/spec_helper.rb +12 -0
- data/lib/lyrics_ebook.rb +71 -0
- data/lib/lyrics_ebook/cache2html.rb +33 -0
- data/lib/lyrics_ebook/cache_manager.rb +77 -0
- data/lib/lyrics_ebook/lyric.rb +32 -0
- data/lib/lyrics_ebook/lyric_download.rb +50 -0
- data/lib/lyrics_ebook/lyrics2html.rb +106 -0
- data/lib/lyrics_ebook/mini_lyrics_parser.rb +26 -0
- data/lib/lyrics_ebook/mp3_parser.rb +37 -0
- data/lib/wiki_lyrics/amarok/COPYING +340 -0
- data/lib/wiki_lyrics/amarok/README +51 -0
- data/lib/wiki_lyrics/amarok/amarok.rb +355 -0
- data/lib/wiki_lyrics/amarok/pluginadapter.rb +113 -0
- data/lib/wiki_lyrics/amarok/plugins.rb +95 -0
- data/lib/wiki_lyrics/amarok/wikilyrics.rb +578 -0
- data/lib/wiki_lyrics/amarok/wikilyrics.spec +4 -0
- data/lib/wiki_lyrics/amarok/wikipluginadapter.rb +392 -0
- data/lib/wiki_lyrics/cli/optionsparser.rb +228 -0
- data/lib/wiki_lyrics/cli/pluginadapter.rb +56 -0
- data/lib/wiki_lyrics/cli/plugins.rb +79 -0
- data/lib/wiki_lyrics/cli/wikilyrics.rb +178 -0
- data/lib/wiki_lyrics/cli/wikipluginadapter.rb +140 -0
- data/lib/wiki_lyrics/docs/COPYING +340 -0
- data/lib/wiki_lyrics/docs/ChangeLog +293 -0
- data/lib/wiki_lyrics/docs/HOWTO.pdf +0 -0
- data/lib/wiki_lyrics/docs/HOWTO.tex +151 -0
- data/lib/wiki_lyrics/docs/HOWTO.txt +139 -0
- data/lib/wiki_lyrics/docs/README +45 -0
- data/lib/wiki_lyrics/docs/TODO +12 -0
- data/lib/wiki_lyrics/gui/gui-gtk.rb +945 -0
- data/lib/wiki_lyrics/gui/gui-qt3.rb +785 -0
- data/lib/wiki_lyrics/gui/gui-qt4.rb +845 -0
- data/lib/wiki_lyrics/gui/gui-tk.rb +1104 -0
- data/lib/wiki_lyrics/gui/gui.rb +268 -0
- data/lib/wiki_lyrics/gui/test.rb +74 -0
- data/lib/wiki_lyrics/i18n/README +1 -0
- data/lib/wiki_lyrics/i18n/en.rb +181 -0
- data/lib/wiki_lyrics/i18n/es.rb +181 -0
- data/lib/wiki_lyrics/i18n/i18n.rb +126 -0
- data/lib/wiki_lyrics/i18n/sk.rb +174 -0
- data/lib/wiki_lyrics/itrans/COPYRIGHT +31 -0
- data/lib/wiki_lyrics/itrans/itrans +0 -0
- data/lib/wiki_lyrics/itrans/itrans.txt +8 -0
- data/lib/wiki_lyrics/itrans/lyric.txt +23 -0
- data/lib/wiki_lyrics/itrans/udvng.ifm +206 -0
- data/lib/wiki_lyrics/lyrics.rb +567 -0
- data/lib/wiki_lyrics/lyrics_AZLyrics.rb +113 -0
- data/lib/wiki_lyrics/lyrics_DarkLyrics.rb +124 -0
- data/lib/wiki_lyrics/lyrics_Giitaayan.rb +124 -0
- data/lib/wiki_lyrics/lyrics_Jamendo.rb +166 -0
- data/lib/wiki_lyrics/lyrics_LeosLyrics.rb +142 -0
- data/lib/wiki_lyrics/lyrics_LoudSongs.rb +135 -0
- data/lib/wiki_lyrics/lyrics_LyricWiki.rb +329 -0
- data/lib/wiki_lyrics/lyrics_LyricsDownload.rb +118 -0
- data/lib/wiki_lyrics/lyrics_LyricsMania.rb +141 -0
- data/lib/wiki_lyrics/lyrics_Lyriki.rb +287 -0
- data/lib/wiki_lyrics/lyrics_SeekLyrics.rb +108 -0
- data/lib/wiki_lyrics/lyrics_Sing365.rb +103 -0
- data/lib/wiki_lyrics/lyrics_TerraLetras.rb +126 -0
- data/lib/wiki_lyrics/mediawikilyrics.rb +1464 -0
- data/lib/wiki_lyrics/tests/plugin_tests.rb +161 -0
- data/lib/wiki_lyrics/tests/tests.rb +74 -0
- data/lib/wiki_lyrics/utils/formdata.rb +56 -0
- data/lib/wiki_lyrics/utils/htmlentities.rb +291 -0
- data/lib/wiki_lyrics/utils/http.rb +198 -0
- data/lib/wiki_lyrics/utils/itrans.rb +160 -0
- data/lib/wiki_lyrics/utils/kde.rb +88 -0
- data/lib/wiki_lyrics/utils/logger.rb +123 -0
- data/lib/wiki_lyrics/utils/strings.rb +378 -0
- data/lib/wiki_lyrics/utils/xmlhash.rb +111 -0
- data/lib/wiki_lyrics/wikilyrics.kdevelop +152 -0
- data/lib/wiki_lyrics/wikilyrics.kdevses +18 -0
- data/lib/wiki_lyrics/win/gtk_fix.bat +3 -0
- data/lib/wiki_lyrics/win/tk_fix.bat +3 -0
- data/lib/wiki_lyrics/win/wikilyrics.bat +4 -0
- data/lib/wiki_lyrics/win/win_fix.rb +52 -0
- data/templates/art_.erb.xhtml +29 -0
- data/templates/artists.erb.xhtml +19 -0
- data/templates/cover.erb.xhtml +22 -0
- data/test/cache_manager_test.rb +73 -0
- data/test/data/artist name/title name.lyric +6 -0
- data/test/lyric_test.rb +41 -0
- metadata +194 -0
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module EeePub
|
5
|
+
# The class to make ePub easily
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# epub = EeePub.make do
|
9
|
+
# title 'sample'
|
10
|
+
# creator 'jugyo'
|
11
|
+
# publisher 'jugyo.org'
|
12
|
+
# date '2010-05-06'
|
13
|
+
# identifier 'http://example.com/book/foo', :scheme => 'URL'
|
14
|
+
# uid 'http://example.com/book/foo'
|
15
|
+
#
|
16
|
+
# files ['/path/to/foo.html', '/path/to/bar.html']
|
17
|
+
# nav [
|
18
|
+
# {:label => '1. foo', :content => 'foo.html', :nav => [
|
19
|
+
# {:label => '1.1 foo-1', :content => 'foo.html#foo-1'}
|
20
|
+
# ]},
|
21
|
+
# {:label => '1. bar', :content => 'bar.html'}
|
22
|
+
# ]
|
23
|
+
# end
|
24
|
+
# epub.save('sample.epub')
|
25
|
+
class Maker
|
26
|
+
[
|
27
|
+
:title,
|
28
|
+
:creator,
|
29
|
+
:publisher,
|
30
|
+
:date,
|
31
|
+
:language,
|
32
|
+
:subject,
|
33
|
+
:description,
|
34
|
+
:rights,
|
35
|
+
:relation
|
36
|
+
].each do |name|
|
37
|
+
class_eval <<-DELIM
|
38
|
+
def #{name}(value)
|
39
|
+
@#{name}s ||= []
|
40
|
+
@#{name}s << value
|
41
|
+
end
|
42
|
+
DELIM
|
43
|
+
end
|
44
|
+
|
45
|
+
[
|
46
|
+
:uid,
|
47
|
+
:files,
|
48
|
+
:nav,
|
49
|
+
:ncx_file,
|
50
|
+
:opf_file,
|
51
|
+
:guide
|
52
|
+
].each do |name|
|
53
|
+
define_method(name) do |arg|
|
54
|
+
instance_variable_set("@#{name}", arg)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def identifier(id, options)
|
59
|
+
@identifiers ||= []
|
60
|
+
@identifiers << {:value => id, :scheme => options[:scheme]}
|
61
|
+
end
|
62
|
+
|
63
|
+
# @param [Proc] block the block for initialize
|
64
|
+
def initialize(&block)
|
65
|
+
@files ||= []
|
66
|
+
@nav ||= []
|
67
|
+
@ncx_file ||= 'toc.ncx'
|
68
|
+
@opf_file ||= 'content.opf'
|
69
|
+
|
70
|
+
instance_eval(&block) if block_given?
|
71
|
+
end
|
72
|
+
|
73
|
+
# Save as ePub file
|
74
|
+
#
|
75
|
+
# @param [String] filename the ePub file name to save
|
76
|
+
def save(filename)
|
77
|
+
Dir.mktmpdir do |dir|
|
78
|
+
@files.each do |file|
|
79
|
+
case file
|
80
|
+
when String
|
81
|
+
FileUtils.cp(file, dir)
|
82
|
+
when Hash
|
83
|
+
file_path, dir_path = *file.first
|
84
|
+
dest_dir = File.join(dir, dir_path)
|
85
|
+
FileUtils.mkdir_p(dest_dir)
|
86
|
+
FileUtils.cp(file_path, dest_dir)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
NCX.new(
|
91
|
+
:uid => @uid,
|
92
|
+
:title => @titles[0],
|
93
|
+
:nav => @nav
|
94
|
+
).save(File.join(dir, @ncx_file))
|
95
|
+
|
96
|
+
OPF.new(
|
97
|
+
:title => @titles,
|
98
|
+
:identifier => @identifiers,
|
99
|
+
:creator => @creators,
|
100
|
+
:publisher => @publishers,
|
101
|
+
:date => @dates,
|
102
|
+
:language => @languages,
|
103
|
+
:subject => @subjects,
|
104
|
+
:description => @descriptions,
|
105
|
+
:rights => @rightss,
|
106
|
+
:relation => @relations,
|
107
|
+
:guide=> @guide,
|
108
|
+
:manifest => @files.map{|file|
|
109
|
+
case file
|
110
|
+
when String
|
111
|
+
File.basename(file)
|
112
|
+
when Hash
|
113
|
+
file_path, dir_path = *file.first
|
114
|
+
File.join(dir_path, File.basename(file_path))
|
115
|
+
end
|
116
|
+
},
|
117
|
+
:ncx => @ncx_file
|
118
|
+
).save(File.join(dir, @opf_file))
|
119
|
+
|
120
|
+
OCF.new(
|
121
|
+
:dir => dir,
|
122
|
+
:container => @opf_file
|
123
|
+
).save(filename)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module EeePub
|
2
|
+
class NCX < ContainerItem
|
3
|
+
attr_accessor :uid,
|
4
|
+
:depth,
|
5
|
+
:total_page_count,
|
6
|
+
:max_page_number,
|
7
|
+
:doc_title,
|
8
|
+
:nav_map
|
9
|
+
|
10
|
+
attr_alias :title, :doc_title
|
11
|
+
attr_alias :nav, :nav_map
|
12
|
+
|
13
|
+
default_value :depth, 1
|
14
|
+
default_value :total_page_count, 0
|
15
|
+
default_value :max_page_number, 0
|
16
|
+
default_value :doc_title, 'Untitled'
|
17
|
+
|
18
|
+
def build_xml(builder)
|
19
|
+
builder.declare! :DOCTYPE, :ncx, :PUBLIC, "-//NISO//DTD ncx 2005-1//EN", "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd"
|
20
|
+
builder.ncx :xmlns => "http://www.daisy.org/z3986/2005/ncx/", :version => "2005-1" do
|
21
|
+
build_head(builder)
|
22
|
+
builder.docTitle { builder.text doc_title }
|
23
|
+
build_nav_map(builder)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_head(builder)
|
28
|
+
builder.head do
|
29
|
+
{
|
30
|
+
:uid => uid,
|
31
|
+
:depth => depth,
|
32
|
+
:totalPageCount => total_page_count,
|
33
|
+
:maxPageNumber => max_page_number
|
34
|
+
}.each do |k, v|
|
35
|
+
builder.meta :name => "dtb:#{k}", :content => v
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def build_nav_map(builder)
|
41
|
+
builder.navMap do
|
42
|
+
builder_nav_point(builder, nav_map)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def builder_nav_point(builder, nav_point, play_order = 1)
|
47
|
+
case nav_point
|
48
|
+
when Array
|
49
|
+
nav_point.each do |point|
|
50
|
+
play_order = builder_nav_point(builder, point, play_order)
|
51
|
+
end
|
52
|
+
when Hash
|
53
|
+
id = nav_point[:id] || "navPoint-#{play_order}"
|
54
|
+
builder.navPoint :id => id, :playOrder => play_order do
|
55
|
+
builder.navLabel { builder.text nav_point[:label] }
|
56
|
+
builder.content :src => nav_point[:content]
|
57
|
+
play_order += 1
|
58
|
+
if nav_point[:nav]
|
59
|
+
play_order = builder_nav_point(builder, nav_point[:nav], play_order)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
else
|
63
|
+
raise "nav_point must be Array or Hash"
|
64
|
+
end
|
65
|
+
play_order
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'zippy'
|
2
|
+
|
3
|
+
module EeePub
|
4
|
+
# Class to create OCF
|
5
|
+
class OCF
|
6
|
+
# Class for 'container.xml' of OCF
|
7
|
+
class Container < ContainerItem
|
8
|
+
attr_accessor :rootfiles
|
9
|
+
|
10
|
+
# @param [String or Array or Hash]
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# # with String
|
14
|
+
# EeePub::OCF::Container.new('container.opf')
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# # with Array
|
18
|
+
# EeePub::OCF::Container.new(['container.opf', 'other.opf'])
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# # with Hash
|
22
|
+
# EeePub::OCF::Container.new(
|
23
|
+
# :rootfiles => [
|
24
|
+
# {:full_path => 'container.opf', :media_type => 'application/oebps-package+xml'}
|
25
|
+
# ]
|
26
|
+
# )
|
27
|
+
def initialize(arg)
|
28
|
+
case arg
|
29
|
+
when String
|
30
|
+
set_values(
|
31
|
+
:rootfiles => [
|
32
|
+
{:full_path => arg, :media_type => guess_media_type(arg)}
|
33
|
+
]
|
34
|
+
)
|
35
|
+
when Array
|
36
|
+
# TODO: spec
|
37
|
+
set_values(
|
38
|
+
:rootfiles => arg.keys.map { |k|
|
39
|
+
filename = arg[k]
|
40
|
+
{:full_path => filename, :media_type => guess_media_type(filename)}
|
41
|
+
}
|
42
|
+
)
|
43
|
+
when Hash
|
44
|
+
set_values(arg)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def build_xml(builder)
|
52
|
+
builder.container :xmlns => "urn:oasis:names:tc:opendocument:xmlns:container", :version => "1.0" do
|
53
|
+
builder.rootfiles do
|
54
|
+
rootfiles.each do |i|
|
55
|
+
builder.rootfile convert_to_xml_attributes(i)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
attr_accessor :dir, :container
|
63
|
+
|
64
|
+
# @param [Hash<Symbol, Object>] values the values of symbols and objects for OCF
|
65
|
+
#
|
66
|
+
# @example
|
67
|
+
# EeePub::OCF.new(
|
68
|
+
# :dir => '/path/to/dir',
|
69
|
+
# :container => 'container.opf'
|
70
|
+
# )
|
71
|
+
def initialize(values)
|
72
|
+
values.each do |k, v|
|
73
|
+
self.send(:"#{k}=", v)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Set container
|
78
|
+
#
|
79
|
+
# @param [EeePub::OCF::Container or args for EeePub::OCF::Container]
|
80
|
+
def container=(arg)
|
81
|
+
if arg.is_a?(EeePub::OCF::Container)
|
82
|
+
@container = arg
|
83
|
+
else
|
84
|
+
# TODO: spec
|
85
|
+
@container = EeePub::OCF::Container.new(arg)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Save as OCF
|
90
|
+
#
|
91
|
+
# @param [String] output_path the output file path of ePub
|
92
|
+
def save(output_path)
|
93
|
+
output_path = File.expand_path(output_path)
|
94
|
+
|
95
|
+
FileUtils.chdir(dir) do
|
96
|
+
|
97
|
+
meta_inf = 'META-INF'
|
98
|
+
FileUtils.mkdir_p(meta_inf)
|
99
|
+
|
100
|
+
container.save(File.join(meta_inf, 'container.xml'))
|
101
|
+
|
102
|
+
Zippy.create output_path do |zip|
|
103
|
+
zip['mimetype'] = 'application/epub+zip'
|
104
|
+
Dir.glob('**/*').each do |filename|
|
105
|
+
zip[filename] = IO.read(filename) unless File.directory?(filename)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
module EeePub
|
2
|
+
class OPF < ContainerItem
|
3
|
+
attr_accessor :unique_identifier,
|
4
|
+
:title,
|
5
|
+
:language,
|
6
|
+
:identifier,
|
7
|
+
:date,
|
8
|
+
:subject,
|
9
|
+
:description,
|
10
|
+
:relation,
|
11
|
+
:creator,
|
12
|
+
:publisher,
|
13
|
+
:rights,
|
14
|
+
:manifest,
|
15
|
+
:spine,
|
16
|
+
:guide,
|
17
|
+
:ncx,
|
18
|
+
:toc
|
19
|
+
|
20
|
+
default_value :toc, 'ncx'
|
21
|
+
default_value :unique_identifier, 'BookId'
|
22
|
+
default_value :title, 'Untitled'
|
23
|
+
default_value :language, 'en'
|
24
|
+
|
25
|
+
attr_alias :files, :manifest
|
26
|
+
|
27
|
+
def identifier
|
28
|
+
case @identifier
|
29
|
+
when Array
|
30
|
+
@identifier
|
31
|
+
when String
|
32
|
+
[{:value => @identifier, :id => unique_identifier}]
|
33
|
+
when Hash
|
34
|
+
@identifier[:id] = unique_identifier
|
35
|
+
[@identifier]
|
36
|
+
else
|
37
|
+
@identifier
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def spine
|
42
|
+
@spine ||
|
43
|
+
complete_manifest.
|
44
|
+
select { |i| i[:media_type] == 'application/xhtml+xml' }.
|
45
|
+
map { |i| i[:id]}
|
46
|
+
end
|
47
|
+
|
48
|
+
def build_xml(builder)
|
49
|
+
builder.package :xmlns => "http://www.idpf.org/2007/opf",
|
50
|
+
'unique-identifier' => unique_identifier,
|
51
|
+
'version' => "2.0" do
|
52
|
+
|
53
|
+
build_metadata(builder)
|
54
|
+
build_manifest(builder)
|
55
|
+
build_spine(builder)
|
56
|
+
build_guide(builder)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def build_metadata(builder)
|
61
|
+
builder.metadata 'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
|
62
|
+
'xmlns:dcterms' => "http://purl.org/dc/terms/",
|
63
|
+
'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
|
64
|
+
'xmlns:opf' => "http://www.idpf.org/2007/opf" do
|
65
|
+
|
66
|
+
identifier.each do |i|
|
67
|
+
attrs = {}
|
68
|
+
attrs['opf:scheme'] = i[:scheme] if i[:scheme]
|
69
|
+
attrs[:id] = i[:id] if i[:id]
|
70
|
+
builder.dc :identifier, i[:value], attrs
|
71
|
+
end
|
72
|
+
|
73
|
+
[:title, :language, :subject, :description, :relation, :creator, :publisher, :date, :rights].each do |i|
|
74
|
+
value = self.send(i)
|
75
|
+
next unless value
|
76
|
+
|
77
|
+
[value].flatten.each do |v|
|
78
|
+
case v
|
79
|
+
when Hash
|
80
|
+
builder.dc i, v[:value], convert_to_xml_attributes(v.reject {|k, v| k == :value})
|
81
|
+
else
|
82
|
+
builder.dc i, v
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def build_manifest(builder)
|
90
|
+
builder.manifest do
|
91
|
+
complete_manifest.each do |i|
|
92
|
+
builder.item :id => i[:id], :href => i[:href], 'media-type' => i[:media_type]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def build_spine(builder)
|
98
|
+
builder.spine :toc => toc do
|
99
|
+
spine.each do |i|
|
100
|
+
builder.itemref :idref => i
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def build_guide(builder)
|
106
|
+
return if guide.nil? || guide.empty?
|
107
|
+
|
108
|
+
builder.guide do
|
109
|
+
guide.each do |i|
|
110
|
+
builder.reference convert_to_xml_attributes(i)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def complete_manifest
|
116
|
+
item_id_cache = {}
|
117
|
+
|
118
|
+
result = manifest.map do |i|
|
119
|
+
case i
|
120
|
+
when String
|
121
|
+
id = create_unique_item_id(i, item_id_cache)
|
122
|
+
href = i
|
123
|
+
media_type = guess_media_type(i)
|
124
|
+
when Hash
|
125
|
+
id = i[:id] || create_unique_item_id(i[:href], item_id_cache)
|
126
|
+
href = i[:href]
|
127
|
+
media_type = i[:media_type] || guess_media_type(i[:href])
|
128
|
+
end
|
129
|
+
{:id => id, :href => href, :media_type => media_type}
|
130
|
+
end
|
131
|
+
|
132
|
+
result += [{:id => 'ncx', :href => ncx, :media_type => 'application/x-dtbncx+xml'}] if ncx
|
133
|
+
result
|
134
|
+
end
|
135
|
+
|
136
|
+
def create_unique_item_id(filename, id_cache)
|
137
|
+
basename = File.basename(filename)
|
138
|
+
unless id_cache[basename]
|
139
|
+
id_cache[basename] = 0
|
140
|
+
name = basename
|
141
|
+
else
|
142
|
+
name = "#{basename}-#{id_cache[basename]}"
|
143
|
+
end
|
144
|
+
id_cache[basename] += 1
|
145
|
+
name
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|