7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/ncode_syosetu/builder/epub3.rb', line 7
def self.write(novel, path)
Dir.mktmpdir do |tmpdir|
builder = GEPUB::Builder.new do
language "ja"
unique_identifier novel.url
title novel.title
creator novel.author
date Time.now.to_s
resources(workdir: tmpdir) do
toc_html = novel.toc.html.gsub(%r[<a href="/[^/]+/(\d+)/?">], '<a href="\1.html">').gsub(/<br>/, '<br />')
File.write("toc.html", toc_html)
nav "toc.html"
ordered do
next_heading = nil
novel.episodes.each do |episode|
if episode.is_a?(NcodeSyosetu::Model::Heading)
next_heading = episode.title
else
episode_html = episode.html.gsub(/<br>/, '<br />')
html_path = "#{episode.number}.html"
File.write(html_path, episode_html)
file html_path
if next_heading
heading next_heading
next_heading = nil
end
end
end
end
end
end
builder.generate_epub(path)
end
end
|