ebook_tools 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/ebook_tools.gemspec +1 -1
- data/lib/ebook_tools.rb +13 -4
- data/lib/extract_book_struct.rb +21 -1
- metadata +1 -1
data/CHANGELOG
CHANGED
data/ebook_tools.gemspec
CHANGED
data/lib/ebook_tools.rb
CHANGED
@@ -145,9 +145,17 @@ module EbookTools
|
|
145
145
|
|
146
146
|
keywords = Utils.extract_keywords_from_path(File.dirname(file).gsub(source_path,''))
|
147
147
|
puts "start convert #{file}"
|
148
|
-
|
149
|
-
method_name = "#{
|
150
|
-
if
|
148
|
+
extname = File.extname(file).gsub('.','')
|
149
|
+
method_name = "#{extname}2epub"
|
150
|
+
if extname == 'epub'
|
151
|
+
FileUtils.mkdir_p(dest_path) unless Dir.exists?(dest_path)
|
152
|
+
FileUtils.cp(file,dest_file)
|
153
|
+
success_file = File.join(backup_path,file.gsub(source_path,''))
|
154
|
+
FileUtils.mkdir_p(File.dirname(success_file)) unless Dir.exists?(File.dirname(success_file))
|
155
|
+
FileUtils.mv(file,success_file,:force=>true)
|
156
|
+
success_count += 1
|
157
|
+
success_log.puts "success: #{source} conversion successfully!"
|
158
|
+
elsif EbookTools.respond_to?(method_name)
|
151
159
|
begin
|
152
160
|
if PDF.scan_pdf?(file)
|
153
161
|
scan_file = File.join(scan_path,file.gsub(source_path,''))
|
@@ -169,7 +177,7 @@ module EbookTools
|
|
169
177
|
FileUtils.mv(file,unknown_file,:force=>true)
|
170
178
|
error_count += 1
|
171
179
|
error_log.puts "error: #{source} \n#{e.backtrace.join("\n")}"
|
172
|
-
end
|
180
|
+
end
|
173
181
|
end
|
174
182
|
end
|
175
183
|
|
@@ -197,6 +205,7 @@ module EbookTools
|
|
197
205
|
if ExtractBookStruct.respond_to?(method_name)
|
198
206
|
docbook_xml = ExtractBookStruct.send(method_name,source,options)
|
199
207
|
if docbook_xml
|
208
|
+
FileUtils.mkdir_p(File.dirname(destination)) unless Dir.exists?(File.dirname(destination))
|
200
209
|
File.open(destination,'wb'){|file|file.write docbook_xml}
|
201
210
|
return true
|
202
211
|
else
|
data/lib/extract_book_struct.rb
CHANGED
@@ -51,7 +51,7 @@ module ExtractBookStruct
|
|
51
51
|
unless Utils.detect_utf8(content)
|
52
52
|
content = Utils.to_utf8(content)
|
53
53
|
end
|
54
|
-
content = sanitize_for_epub_text(content)
|
54
|
+
content = sanitize_for_epub_text(content)
|
55
55
|
paras = extract_paras(content)
|
56
56
|
# 检查书类型(text,digital,hybrid)
|
57
57
|
format = options[:format] || detect_struct_type(paras)
|
@@ -362,6 +362,25 @@ EOS
|
|
362
362
|
"<toc><title>Table of contents</title>#{gen_docbook_tocdiv(toc)}</toc>"
|
363
363
|
end
|
364
364
|
|
365
|
+
def gen_toc(toc,&block)
|
366
|
+
doc_toc = []
|
367
|
+
toc.each do |item|
|
368
|
+
children = ""
|
369
|
+
if item[:children].any?
|
370
|
+
children = gen_toc(item[:children],block)
|
371
|
+
end
|
372
|
+
doc_toc << block.call(item,children)
|
373
|
+
end
|
374
|
+
doc_toc.join("")
|
375
|
+
end
|
376
|
+
|
377
|
+
def gen_docbook_tocdiv(toc)
|
378
|
+
gen_toc(toc) do |item, children|
|
379
|
+
"<tocdiv><title>#{item[:title]}</title>#{children}</tocdiv>"
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
=begin
|
365
384
|
def gen_docbook_tocdiv(toc)
|
366
385
|
doc_toc = []
|
367
386
|
toc.each do |item|
|
@@ -373,6 +392,7 @@ EOS
|
|
373
392
|
end
|
374
393
|
doc_toc.join("")
|
375
394
|
end
|
395
|
+
=end
|
376
396
|
|
377
397
|
def gen_docbook_content(struct)
|
378
398
|
content = []
|