Skip to content

Commit e76730d

Browse files
committed
rename to script/publish, allow running from top directory
1 parent 2bd5dc0 commit e76730d

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

Diff for: script/epub.rb renamed to script/publish

+33-20
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,31 @@
1414
require 'fileutils'
1515

1616
today = Date.today
17-
system("jekyll build")
18-
FileUtils.mkdir_p("epub_tmp/images")
19-
FileUtils.cp(Dir["_site/images/*"], "epub_tmp/images")
20-
FileUtils.mkdir_p("epub_tmp/css")
21-
FileUtils.cp("_site/css/styles.css", "epub_tmp/css")
22-
f = File.open("epub_tmp/css/styles.css", "a+")
23-
f.puts(<<EOS)
24-
/* epub patch */
25-
body {width:100%;}
26-
p {width:100%;}
27-
EOS
28-
f.close
29-
Dir["_site/*.html"].each do |f|
17+
system("../jekyll build")
18+
19+
GUIDE_DIR = File.expand_path("../..", __FILE__)
20+
ORIGINAL_DIR = "#{GUIDE_DIR}/_site"
21+
TEMP_DIR = "epub_tmp"
22+
23+
FileUtils.mkdir_p("#{TEMP_DIR}/images")
24+
FileUtils.cp(Dir["#{ORIGINAL_DIR}/images/*"], "#{TEMP_DIR}/images")
25+
FileUtils.mkdir_p("#{TEMP_DIR}/css")
26+
FileUtils.cp("#{ORIGINAL_DIR}/css/styles.css", "#{TEMP_DIR}/css")
27+
28+
File.open("#{TEMP_DIR}/css/styles.css", "a+") do |f|
29+
f.puts <<-EOS.gsub(/^\s*/, "")
30+
/* epub patch */
31+
body {width:100%;}
32+
p {width:100%;}
33+
EOS
34+
end
35+
36+
Dir["#{ORIGINAL_DIR}/*.html"].each do |f|
3037
old = File.read(f)
3138
new = old.gsub(%r("/css/styles.css"), %q("css/styles.css"))
32-
File.write("epub_tmp/#{File.basename(f)}", new)
39+
File.write("#{TEMP_DIR}/#{File.basename(f)}", new)
3340
end
41+
3442
navigation = [
3543
{:label => "Preface", :content => "preface.html"},
3644
{:label => "Introduction - translation in progress", :content => "intro.html"},
@@ -40,7 +48,6 @@
4048
{:label => "Chapter 3: Names and name tables", :content => "name.html"},
4149
{:label => "Chapter 4: Classes and modules", :content => "class.html"},
4250
{:label => "Chapter 5: Garbage collection", :content => "gc.html"},
43-
{:label => "Chapter 5: Garbage collection - unfinished alternative translation", :content => "chapter05.html"},
4451
{:label => "Chapter 6: Variables and constants", :content => "variable.html"},
4552
{:label => "Chapter 7: Security", :content => "security.html"}
4653
]},
@@ -64,19 +71,23 @@
6471
]},
6572
{:label => "Final chapter: Ruby's future - translation unstarted", :content => "fin.html"}
6673
]
67-
file_list = Dir["epub_tmp/images/*"].map{|f| {f => "images"}}
68-
file_list.push("epub_tmp/css/styles.css" => "css")
74+
75+
file_list = Dir["#{TEMP_DIR}/images/*"].map{|f| {f => "images"}}
76+
file_list.push("#{TEMP_DIR}/css/styles.css" => "css")
77+
6978
def scan_navigation(nav, acc)
7079
nav.each do |n|
7180
if n[:content]
72-
acc.push("epub_tmp/#{n[:content]}")
81+
acc.push("#{TEMP_DIR}/#{n[:content]}")
7382
end
7483
if n[:nav]
7584
scan_navigation(n[:nav], acc)
7685
end
7786
end
7887
end
88+
7989
scan_navigation(navigation, file_list)
90+
8091
epub = EeePub.make do
8192
title 'Ruby Hacking Guide'
8293
creator 'Minero AOKI, Vincent ISAMBART, Clifford Escobar CAOILE'
@@ -89,5 +100,7 @@ def scan_navigation(nav, acc)
89100
files file_list
90101
nav navigation
91102
end
92-
epub.save("rgh-#{today}.epub")
93-
FileUtils.rm_rf("epub_tmp")
103+
104+
sha = `git rev-parse HEAD`
105+
epub.save("#{GUIDE_DIR}/ebooks/rgh-#{today}_#{sha}.epub")
106+
FileUtils.rm_rf("#{TEMP_DIR}")

0 commit comments

Comments
 (0)