docbook_xsl_wrapper 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/docbook_xsl_wrapper +1 -1
- data/lib/docbook_xsl_wrapper/epub.rb +43 -34
- data/lib/docbook_xsl_wrapper/version.rb +1 -1
- metadata +2 -2
data/bin/docbook_xsl_wrapper
CHANGED
@@ -16,7 +16,7 @@ tmp_dir = Dir.mktmpdir
|
|
16
16
|
options.destination = tmp_dir
|
17
17
|
|
18
18
|
begin
|
19
|
-
puts "Rendering DocBook file #{options.docbook} to #{options.output}" if options.verbose
|
19
|
+
puts "Rendering DocBook file #{options.docbook} to #{options.output}\n\n" if options.verbose
|
20
20
|
|
21
21
|
epub = DocbookXslWrapper::Epub.new(options)
|
22
22
|
epub.render_to_file
|
@@ -21,48 +21,49 @@ module DocbookXslWrapper
|
|
21
21
|
def render_to_epub
|
22
22
|
@collapsed_docbook_file = collapse_docbook()
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
# Double-quote stylesheet & file to help Windows cmd.exe
|
25
|
+
db2epub_cmd = %Q(cd "#{options.destination}" && xsltproc #{xsl_parser_options} "#{options.custom_xsl}" "#{@collapsed_docbook_file}")
|
26
|
+
STDERR.puts db2epub_cmd if options.debug
|
27
|
+
success = system(db2epub_cmd)
|
28
|
+
raise "Could not render as .epub to #{options.output} (#{db2epub_cmd})" unless success
|
29
|
+
end
|
30
|
+
|
31
|
+
def xsl_parser_options
|
32
|
+
chunk_quietly = "--stringparam chunk.quietly " + (options.verbose ? '0' : '1')
|
33
|
+
co_path = "--stringparam callout.graphics.path #{options.callout_path}/"
|
34
|
+
co_limit = "--stringparam callout.graphics.number.limit #{options.callout_limit}"
|
35
|
+
co_ext = "--stringparam callout.graphics.extension #{options.callout_ext}"
|
28
36
|
html_stylesheet = "--stringparam html.stylesheet #{File.basename(options.css)}" if options.css
|
29
|
-
base
|
37
|
+
base = "--stringparam base.dir #{oebps_path}/"
|
30
38
|
unless options.fonts.empty?
|
31
39
|
fonts = options.fonts.map {|f| File.basename(f)}.join(',')
|
32
|
-
font
|
40
|
+
font = "--stringparam epub.embedded.fonts \"#{fonts}\""
|
33
41
|
end
|
34
|
-
meta
|
35
|
-
oebps =
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
# Double-quote stylesheet & file to help Windows cmd.exe
|
47
|
-
db2epub_cmd = %Q(cd "#{options.destination}" && xsltproc #{parser_opts} "#{options.custom_xsl}" "#{@collapsed_docbook_file}")
|
48
|
-
STDERR.puts db2epub_cmd if $DEBUG
|
49
|
-
success = system(db2epub_cmd)
|
50
|
-
raise "Could not render as .epub to #{options.output} (#{db2epub_cmd})" unless success
|
42
|
+
meta = "--stringparam epub.metainf.dir #{meta_inf_path}/"
|
43
|
+
oebps = "--stringparam epub.oebps.dir #{oebps_directory}/"
|
44
|
+
[chunk_quietly,
|
45
|
+
co_path,
|
46
|
+
co_limit,
|
47
|
+
co_ext,
|
48
|
+
base,
|
49
|
+
font,
|
50
|
+
meta,
|
51
|
+
oebps,
|
52
|
+
html_stylesheet,
|
53
|
+
].join(" ")
|
51
54
|
end
|
52
55
|
|
53
56
|
def bundle_epub
|
54
57
|
quiet = options.verbose ? "" : "-q"
|
55
58
|
mimetype_filename = write_mimetype()
|
56
|
-
meta = File.basename(meta_inf_directory)
|
57
|
-
oebps = File.basename(oebps_directory)
|
58
59
|
images = copy_images()
|
59
60
|
csses = copy_csses()
|
60
61
|
fonts = copy_fonts()
|
61
62
|
callouts = copy_callouts()
|
62
63
|
# zip -X -r ../book.epub mimetype META-INF OEBPS
|
63
64
|
# Double-quote stylesheet & file to help Windows cmd.exe
|
64
|
-
zip_cmd = %Q(cd "#{options.destination}" && zip #{quiet} -X -r "#{File.expand_path(options.output)}" "#{mimetype_filename}" "#{
|
65
|
-
puts zip_cmd if
|
65
|
+
zip_cmd = %Q(cd "#{options.destination}" && zip #{quiet} -X -r "#{File.expand_path(options.output)}" "#{mimetype_filename}" "#{meta_inf_directory}" "#{oebps_directory}")
|
66
|
+
puts zip_cmd if options.debug
|
66
67
|
success = system(zip_cmd)
|
67
68
|
raise "Could not bundle into .epub file to #{options.output}" unless success
|
68
69
|
end
|
@@ -91,7 +92,7 @@ module DocbookXslWrapper
|
|
91
92
|
if has_callouts?
|
92
93
|
calloutglob = "#{options.callout_full_path}/*#{options.callout_ext}"
|
93
94
|
Dir.glob(calloutglob).each {|img|
|
94
|
-
img_new_filename = File.join(
|
95
|
+
img_new_filename = File.join(oebps_path, options.callout_path, File.basename(img))
|
95
96
|
|
96
97
|
# TODO: What to rescue for these two?
|
97
98
|
FileUtils.mkdir_p(File.dirname(img_new_filename))
|
@@ -105,7 +106,7 @@ module DocbookXslWrapper
|
|
105
106
|
def copy_fonts
|
106
107
|
new_fonts = []
|
107
108
|
options.fonts.each {|font_file|
|
108
|
-
font_new_filename = File.join(
|
109
|
+
font_new_filename = File.join(oebps_path, File.basename(font_file))
|
109
110
|
FileUtils.cp(font_file, font_new_filename)
|
110
111
|
new_fonts << font_file
|
111
112
|
}
|
@@ -114,7 +115,7 @@ module DocbookXslWrapper
|
|
114
115
|
|
115
116
|
def copy_csses
|
116
117
|
if options.css
|
117
|
-
css_new_filename = File.join(
|
118
|
+
css_new_filename = File.join(oebps_path, File.basename(options.css))
|
118
119
|
FileUtils.cp(options.css, css_new_filename)
|
119
120
|
end
|
120
121
|
end
|
@@ -126,12 +127,12 @@ module DocbookXslWrapper
|
|
126
127
|
# TODO: It'd be cooler if we had a filetype lookup rather than just
|
127
128
|
# extension
|
128
129
|
if img =~ /\.(svg|png|gif|jpe?g|xml)/i
|
129
|
-
img_new_filename = File.join(
|
130
|
+
img_new_filename = File.join(oebps_path, img)
|
130
131
|
img_full = File.join(File.expand_path(File.dirname(options.docbook)), img)
|
131
132
|
|
132
133
|
# TODO: What to rescue for these two?
|
133
134
|
FileUtils.mkdir_p(File.dirname(img_new_filename))
|
134
|
-
puts(img_full + ": " + img_new_filename) if
|
135
|
+
puts(img_full + ": " + img_new_filename) if options.debug
|
135
136
|
FileUtils.cp(img_full, img_new_filename)
|
136
137
|
new_images << img_full
|
137
138
|
end
|
@@ -171,11 +172,19 @@ module DocbookXslWrapper
|
|
171
172
|
end
|
172
173
|
|
173
174
|
def oebps_directory
|
174
|
-
|
175
|
+
'OEBPS'
|
176
|
+
end
|
177
|
+
|
178
|
+
def oebps_path
|
179
|
+
@oebps_path ||= File.join(options.destination, oebps_directory)
|
175
180
|
end
|
176
181
|
|
177
182
|
def meta_inf_directory
|
178
|
-
|
183
|
+
'META-INF'
|
184
|
+
end
|
185
|
+
|
186
|
+
def meta_inf_path
|
187
|
+
@meta_inf_path ||= File.join(options.destination, meta_inf_directory)
|
179
188
|
end
|
180
189
|
|
181
190
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docbook_xsl_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|