Class: Peregrin::Ochook
Defined Under Namespace
Classes: DirectoryNotFound, IndexHTMLRootHasNoManifest, MissingManifest
Constant Summary
collapse
- FORMAT =
"Ochook"
- MANIFEST_PATH =
"ochook.manifest"
Constants inherited
from Zhook
Zhook::BODY_XPATH, Zhook::COVER_PATH, Zhook::FILE_EXT, Zhook::HEAD_XPATH, Zhook::INDEX_PATH
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(book) ⇒ Ochook
Returns a new instance of Ochook.
49
50
51
52
|
# File 'lib/formats/ochook.rb', line 49
def initialize(book)
super
insert_manifest_attribute
end
|
Class Method Details
.read(path) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/formats/ochook.rb', line 29
def self.read(path)
path = path.gsub(/\/$/, '')
validate(path)
book = Peregrin::Book.new
book.add_component(INDEX_PATH, IO.read(File.join(path, INDEX_PATH)))
Dir.glob(File.join(path, '**', '*')).each { |fpath|
ex = [INDEX_PATH, MANIFEST_PATH]
mpath = fpath.gsub(/^#{path}\//,'')
unless File.directory?(fpath) || ex.include?(mpath)
book.add_resource(mpath)
end
}
book.read_resource_proc = lambda { |resource|
IO.read(File.join(path, resource.src))
}
(book)
new(book)
end
|
Instance Method Details
#to_book(options = {}) ⇒ Object
85
86
87
88
|
# File 'lib/formats/ochook.rb', line 85
def to_book(options = {})
remove_manifest_attribute
super(options)
end
|
#write(dir) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/formats/ochook.rb', line 55
def write(dir)
FileUtils.rm_rf(dir) if File.directory?(dir)
FileUtils.mkdir_p(dir)
index_path = File.join(dir, INDEX_PATH)
File.open(index_path, 'w') { |f| f << htmlize(index) }
@book.resources.each { |resource|
full_path = File.join(dir, resource.src)
FileUtils.mkdir_p(File.dirname(full_path))
File.open(full_path, 'w') { |f| f << @book.read_resource(resource) }
}
unless @book.cover == COVER_PATH
cover_path = File.join(dir, COVER_PATH)
File.open(cover_path, 'wb') { |f| f << to_png_data(@book.cover) }
unless @book.resources.detect { |r| r.src == COVER_PATH }
@book.add_resource(COVER_PATH)
end
end
manifest_path = File.join(dir, MANIFEST_PATH)
File.open(manifest_path, 'w') { |f| f << manifest.join("\n") }
end
|