14
14
require 'fileutils'
15
15
16
16
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 |
30
37
old = File . read ( f )
31
38
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 )
33
40
end
41
+
34
42
navigation = [
35
43
{ :label => "Preface" , :content => "preface.html" } ,
36
44
{ :label => "Introduction - translation in progress" , :content => "intro.html" } ,
40
48
{ :label => "Chapter 3: Names and name tables" , :content => "name.html" } ,
41
49
{ :label => "Chapter 4: Classes and modules" , :content => "class.html" } ,
42
50
{ :label => "Chapter 5: Garbage collection" , :content => "gc.html" } ,
43
- { :label => "Chapter 5: Garbage collection - unfinished alternative translation" , :content => "chapter05.html" } ,
44
51
{ :label => "Chapter 6: Variables and constants" , :content => "variable.html" } ,
45
52
{ :label => "Chapter 7: Security" , :content => "security.html" }
46
53
] } ,
64
71
] } ,
65
72
{ :label => "Final chapter: Ruby's future - translation unstarted" , :content => "fin.html" }
66
73
]
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
+
69
78
def scan_navigation ( nav , acc )
70
79
nav . each do |n |
71
80
if n [ :content ]
72
- acc . push ( "epub_tmp /#{ n [ :content ] } " )
81
+ acc . push ( "#{ TEMP_DIR } /#{ n [ :content ] } " )
73
82
end
74
83
if n [ :nav ]
75
84
scan_navigation ( n [ :nav ] , acc )
76
85
end
77
86
end
78
87
end
88
+
79
89
scan_navigation ( navigation , file_list )
90
+
80
91
epub = EeePub . make do
81
92
title 'Ruby Hacking Guide'
82
93
creator 'Minero AOKI, Vincent ISAMBART, Clifford Escobar CAOILE'
@@ -89,5 +100,7 @@ def scan_navigation(nav, acc)
89
100
files file_list
90
101
nav navigation
91
102
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